To create the OpenGL draw context, call the function SDL_SetVideoMode(). This function takes four arguments: width, height, color depth, and flags. If you specify a color depth of 0, SDL uses the current color depth.
For an OpenGL context you must use the flag SDL_OPENGL. If you want a fullscreen draw context, you must also include the flag SDL_FULLSCREEN. The following code creates a 1024 by 768 pixel fullscreen OpenGL draw context that uses the current color depth:
SDL_Surface* drawContext; Uint32 flags; flags = SDL_OPENGL | SDL_FULLSCREEN; drawContext = SDL_SetVideoMode(1024, 768, 0, flags);
If you read the SDL documentation on SDL_SetVideoMode(), you will see that one of the flags you can use is SDL_DOUBLEBUF. This flag is for SDL programs that do not use OpenGL. If you’re using OpenGL for your graphics, do not use the SDL_DOUBLEBUF flag. Enable OpenGL double buffering by calling SDL_GL_SetAttribute().
Now that you’ve created the draw context, you can make any OpenGL function call. When you’re finished drawing a frame, call the function SDL_GL_SwapBuffers() to display the newly drawn frame on the screen.
SDL_GL_SwapBuffers();
Next (Timers)
Previous (Initializing SDL)