Multimedia Page 3 - Using OpenGL with SDL for Game Programming |
In SDL all the sub-systems are initialized via SDL_Init(). OpenGL, being a part of the graphics subsystem, is not directly initialized in this manner. For initializing OpenGL, these three steps should be followed:
Of these, the second one is optional as it is used only when double buffering is a requirement. Let's have a detailed look at all of them. Setting the OpenGL Attributes Before initializing the video, it is better to set up the OpenGL attributes. These attributes are passed to OpenGL via SDL calling the SDL_GL_SetAttribute() function. The parameters are the OpenGL attribute and their values. The most common attributes passed to this function are:
You are probably wondering right now whether these attributes could be set after initializing the video mode. The answer is no. The reason is that these settings have to be initialized before invoking and configuring the video mode. Next we have to set up the video mode. Setting up double buffering This aspect must also to be covered before setting up the video mode as this attribute goes as a flag parameter to the SDL_GL_SetAttribute. The attribute is SDL_GL_DOUBLEBUFFER and the value is either 1 or 0. The point to be kept in mind is that when working in conjunction with OpenGL, the flag specifying the double buffer must be passed as an attribute to the SDL_GL_SetAttribute function and not to the SDL_Set_VideoMode(). In code this would be:
would set the double buffering to one state. Setting the Video Mode Once the OpenGL attributes are set, setting the video mode is similar to the setting of video mode as described in previous tutorials. For more details have a look at the second article in this series. The only difference comes in flags being sent to the SDL_Set_VideoMode(). Apart from other required flags the SDL_OPENGL would also be set i.e.
Setting the SDL_OPENGL flag is a must. That covers all the required steps, Now let's see OpenGL at play.
blog comments powered by Disqus |