SDL:Tutorial:OpenGL Extensions with SDL
From GDWiki
Contents |
[edit] OpenGL Extensions with SDL
[edit] Intro
As you know, SDL is integrated with OpenGL; if you want to manage the window, SDL is the way, but if you want to manage the 3D world drawn in the window, OpenGL is the way. SDL also provides everything necessary for initialization of an OpenGL context.
With the diffusion and the high rate of growth of graphics hardware, two things have become important when speaking of OpenGL: Shaders and Extensions.
SDL provides a simple and effective way to use OpenGL extensions.
[edit] Checking extensions, the classic way
The classic way (that is, the one that doesn't employ external libraries like GLEW or GLee) to check if an extension is present is to include the glext.h header and use it. To use the extensions in compile-time, you should do something like:
#include <GL/glext.h> #ifdef GL_EXT_extensionname // The extension is present #else // Extension not present #endif
But usually you may prefer a dynamic loading of the extensions. To do this you need to ask the OpenGL implementation which extensions it supports, and then check if the one you need is there:
// Proto: const GLubyte * glGetString( GLenum name ) char *extensions = (char *)glGetString(GL_EXTENSIONS) // Check your extension if (strstr(extensions, "EXT_extensionname")) // The extension present else // Extension not present
[edit] Loading with SDL
When you are sure that an extension is in the OpenGL implementation, you need to load it. With SDL, the key is using the SDL_GL_GetProcAddress() function.
First: declare a pointer to the function
ret_type (APIENTRY * glExtensionName)(parameters) = NULL;
Note that SDL requires the APIENTRY declaration before the pointer.
Then you need to load the address and after checking that everything is 0K, use that function:
glExtensionName = (glExtensionName) SDL_GL_GetProcAddress("glExtensionFunction"); if (glExtensionName) // Use that extension else // Other way

