SteinSOFT.net
  Using OpenGL Extensions

OpenGL as a standard has been specified many years ago now and since then, the main usage and commands haven't changed. First of all this is due to the clean and intelligent structure of the API. Nevertheless graphics hardware has improved very much in the last time, especially in the last few years. But unlike other graphic API's like DirectX, OpenGL hasn't completely changed in terms of functions when a new feature has to be supported. It rather relies on its extension mechanism which will be shortly explained here.

The first step of using extensions is to check whether they are supported by hardware. Therefore you have to check glGetString(GL_EXTENSIONS) which returns a string that contains all names of extensions that are supported by the OpenGL driver. These extensions are separated by spaces; an example of an extension is ARB_multitexture. A list of all OpenGL extensions can be found here - a little explanation included: http://oss.sgi.com/projects/ogl-sample/registry.

Here's the extensions check code:

#include <GL/glext.h>

//we rather use an own function instead of strstr(..) because
//this might be dangerous if two extensions begin with the same text
bool checkExtension(const char* extensions, const char* checkFor)
{
   char *extension;
   char *endOfStr;	
   int idx = 0;
   endOfStr = checkFor + strlen(checkFor);

   while (checkFor < endOfStr)
   {
      idx = strcspn(checkFor, " ");

      if ( (strlen(extensions) == idx) &&
           (strncmp(extensions, checkFor, idx) == 0))
         return true;

      checkFor += (idx + 1);
   }

   return false;
}

//..
//example
bool hasMultitexture =
  checkExtension(glGetString(GL_EXTENSIONS), "ARB_multitexture");

When you're sure that the wanted extension is supported by hardware, you can use it. Depending on your extension, it might be made of functions or simply of OpenGL constants that are used with existing functions. To know what functions and constants are defined with an extension, you have to check the documentation. To make things easier there is a header file glext.h which can also be downloaded from the code section and which defines the most important extension functions and constants.

Say we want to use the extension ARB_multitexture. This one brings both functions and constants with it. Before using the extension functions you have to get the functions addresses from the library. This is done with wglGetProcAddress(char* functionName) in Windows:

#include <GL/glext.h>

//get multitexture functions
glMultiTexCoord2fARB = (PFNGLMULTITEXCOORD2FARBPROC) 
  wglGetProcAddress("glMultiTexCoord2fARB");
glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) 
  wglGetProcAddress("glActiveTextureARB");
glClientActiveTextureARB = (PFNGLCLIENTACTIVETEXTUREARBPROC) 
  wglGetProcAddress("glClientActiveTextureARB");

After getting the function address, this function can be used as any normal OpenGL function - you only have to know how to use it. You should now have understood the basics of using extensions. Of course there are many other tutorials that really show you how to use some of the different extensions but this snippet is only intended as a reference. In case of questions, message board. Happy Coding!

Copyright © by SteinSOFT