Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Setting up the OpenGL support
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jul 16, 2006
1 parent a185206 commit 4f62229
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 110 deletions.
1 change: 1 addition & 0 deletions include/SDL_compat.h
Expand Up @@ -172,6 +172,7 @@ extern DECLSPEC int SDLCALL SDL_DisplayYUVOverlay(SDL_Overlay * overlay,
SDL_Rect * dstrect);
extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay * overlay);
extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value);
extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void);

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
Expand Down
12 changes: 9 additions & 3 deletions include/SDL_video.h
Expand Up @@ -1499,6 +1499,10 @@ extern DECLSPEC int SDLCALL SDL_GL_MakeCurrent(SDL_WindowID windowID,
*
* \brief Set the swap interval for the current OpenGL context.
*
* \param interval 0 for immediate updates, 1 for updates synchronized with the vertical retrace
*
* \return 0 on success, or -1 if setting the swap interval is not supported.
*
* \sa SDL_GL_GetSwapInterval()
*/
extern DECLSPEC int SDLCALL SDL_GL_SetSwapInterval(int interval);
Expand All @@ -1508,16 +1512,18 @@ extern DECLSPEC int SDLCALL SDL_GL_SetSwapInterval(int interval);
*
* \brief Get the swap interval for the current OpenGL context.
*
* \return 0 if there is no vertical retrace synchronization, 1 if the buffer swap is synchronized with the vertical retrace, and -1 if getting the swap interval is not supported.
*
* \sa SDL_GL_SetSwapInterval()
*/
extern DECLSPEC int SDLCALL SDL_GL_GetSwapInterval(void);

/**
* \fn void SDL_GL_SwapBuffers(void)
* \fn void SDL_GL_SwapWindow(SDL_WindowID windowID)
*
* Swap the OpenGL buffers, if double-buffering is supported.
* \brief Swap the OpenGL buffers for the window, if double-buffering is supported.
*/
extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void);
extern DECLSPEC void SDLCALL SDL_GL_SwapWindow(SDL_WindowID windowID);

/**
* \fn void SDL_GL_DeleteContext(SDL_GLContext context)
Expand Down
25 changes: 25 additions & 0 deletions src/SDL_compat.c
Expand Up @@ -36,6 +36,7 @@ static SDL_TextureID SDL_VideoTexture;
static SDL_Surface *SDL_VideoSurface;
static SDL_Surface *SDL_ShadowSurface;
static SDL_Surface *SDL_PublicSurface;
static SDL_GLContext *SDL_VideoContext;
static char *wm_title;

char *
Expand Down Expand Up @@ -335,6 +336,11 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
SDL_FreeSurface(SDL_VideoSurface);
SDL_VideoSurface = NULL;
}
if (SDL_VideoContext) {
SDL_GL_MakeCurrent(0, SDL_VideoContext);
SDL_GL_DeleteContext(SDL_VideoContext);
SDL_VideoContext = NULL;
}
if (SDL_VideoWindow) {
SDL_GetWindowPosition(SDL_VideoWindow, &window_x, &window_y);
}
Expand Down Expand Up @@ -432,6 +438,13 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)

/* If we're in OpenGL mode, just create a stub surface and we're done! */
if (flags & SDL_OPENGL) {
SDL_VideoContext = SDL_GL_CreateContext(SDL_VideoWindow);
if (!SDL_VideoContext) {
return NULL;
}
if (SDL_GL_MakeCurrent(SDL_VideoWindow, SDL_VideoContext) < 0) {
return NULL;
}
SDL_VideoSurface =
SDL_CreateRGBSurfaceFrom(NULL, width, height, bpp, 0, 0, 0, 0, 0);
if (!SDL_VideoSurface) {
Expand Down Expand Up @@ -1418,4 +1431,16 @@ SDL_FreeYUVOverlay(SDL_Overlay * overlay)
}
}

int
SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
{
return SDL_GL_GetWindowAttribute(SDL_VideoWindow, attr, value);
}

void
SDL_GL_SwapBuffers(void)
{
SDL_GL_SwapWindow(SDL_VideoWindow);
}

/* vi: set ts=4 sw=4 expandtab: */
37 changes: 10 additions & 27 deletions src/video/SDL_sysvideo.h
Expand Up @@ -227,36 +227,21 @@ struct SDL_VideoDevice
void (*VideoQuit) (_THIS);

/* * * */
/* OpenGL support */

/* Sets the dll to use for OpenGL and loads it */
/* OpenGL support
*/
int (*GL_LoadLibrary) (_THIS, const char *path);

/* Retrieves the address of a function in the gl library */
void *(*GL_GetProcAddress) (_THIS, const char *proc);

/* Get attribute information from the windowing system. */
int (*GL_GetAttribute) (_THIS, SDL_GLattr attrib, int *value);

/* Make the context associated with this driver current */
int (*GL_MakeCurrent) (_THIS);

/* Swap the current buffers in double buffer mode. */
void (*GL_SwapBuffers) (_THIS);

/* Determine whether the mouse should be in relative mode or not.
This function is called when the input grab state or cursor
visibility state changes.
If the cursor is not visible, and the input is grabbed, the
driver can place the mouse in relative mode, which may result
in higher accuracy sampling of the pointer motion.
*/
void (*CheckMouseMode) (_THIS);
SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
int (*GL_SetSwapInterval) (_THIS, int interval);
int (*GL_GetSwapInterval) (_THIS);
void (*GL_SwapWindow) (_THIS, SDL_Window * window);
void (*GL_DeleteContext) (_THIS, SDL_GLContext context);

/* * * */
/* Event manager functions */

/* Handle any queued OS events */
/* Event manager functions
*/
void (*PumpEvents) (_THIS);

/* * * */
Expand All @@ -266,8 +251,6 @@ struct SDL_VideoDevice
int current_display;
Uint32 next_object_id;

/* Driver information flags */

/* * * */
/* Data used by the GL drivers */
struct
Expand Down

0 comments on commit 4f62229

Please sign in to comment.