Video Events OpenGL Audio CD-ROM Threads Time

SDL as an OpenGL Context Manager


Introduction Function List Function Reference Examples

As of version 1.1, SDL contains extensions which let you use the power of the 3D graphics API OpenGL with SDL's event handling, timer, audio, and thread functions. By simply adding an extra flag to your call to SDL_SetVideoMode, SDL will automatically initialize the appropriate OpenGL "context manager". In effect, you can now use SDL as an alternative to Mark Kilgard's GLUT library.

It must be noted that as of version 1.1.0 of this library, the normal SDL blitting functions and surface manipulation functions do NOT work when SDL is in an OpenGL rendering mode. However, any library which uses OpenGL (for instance Nate Miller's glTexFontf) will work with OpenGL under SDL. In addition, the SDL add-on libraries, such as SDL_Image and SDLmixer, can all be made to work under OpenGL.

To initialize OpenGL under SDL, you must call SDL_Init(SDL_INIT_VIDEO), then set your desired GL attributes (color component size, alpha depth, depth buffer size, double buffering, etc.) with SDL_GL_SetAttribute. Then call SDL_SetVideoMode with the SDL_OPENGL flag. You can then call all the normal GL/GLU functions. To swap buffers, call SDL_GL_SwapBuffers. SDL_Quit() can still be used to clean up when you're done.

Here are some examples to get you started.

A series of tutorials on using OpenGL with SDL is available online at: http://www.devolution.com/~slouken/SDL/opengl/intro.html