OpenGL Extensions Tutorial
OpenGL Extensions are usually made available to access new features of 3D graphics hardware. Hardware vendors define new functions and/or tokens that enhance the existing features of OpenGL.
Extensions created by a single vendor are called "vendor-specific" and extensions created by several vendors are called "multivendor" extensions.
If a vendor-specific or multivendor extension proves to be a good enhancement, the OpenGL Architecture Review Board (ARB) may promote it to an "ARB approved" extension.
If the extension is very useful, the ARB may decide to integrate the extension as a "core feature" to OpenGL. This happened for example with the OpenGL Shading Language which is now a core feature of OpenGL 2.0 and higher.
This concept makes OpenGL very powerful, because source code remains backwards compatible. OpenGL programs written 10 years ago still work today.
Once you have a valid OpenGL context, you can get a list of all extensions with glGetString(GL_EXTENSIONS). It returns a space delimited char-array of all available extensions.
All extensions have the form: GL_VENDOR_extension_name, where "VENDOR" may be - but not limited to - one of the following:
There are also other prefixes than "GL": Those are platform specific extensions. The most famous are "WGL" for Windows specific extensions and "GLX" for X-Windows specific extensions.
Using extensions in your C++ code is - unfortunately - platform specific. The address of the function (function pointer) must be retrieved from the OpenGL implementation (e.g. hardware driver). Under Windows this can be done using "wglGetProcAddress".
To save a lot of time handling all function pointers and tokens of all extensions for several platforms, there are some good OpenSource solutions available which simplify this process. One of them is "GLEW", available at http://glew.sourceforge.net. Another implementation is "GLee", available at http://elf-stone.com/glee.php. Both are good ways to handle extensions and are released under a modified BSD license. (Make sure to read the licenses for details.)
Introduction to GLEW
I am going to use GLEW, without a real reason - GLee is just as good. The latest version of GLEW is 1.3.5 and supports OpenGL 2.1 core functionality and some other new extensions.
GLEW can be compiled statically or dynamically. If you create a static lib, make sure to create a preprocessor variable "GLEW_STATIC" under Windows. Another way is to copy "glew.c" and "glew.h" directly to your code (you also have to define "GLEW_STATIC" under Windows). This is my preferred way because it makes cross compiler/platform management easier.
You can download my sample OpenGL project using GLEW + FreeGLUT here:
Download: OpenGL_Extensions_Tutorial.zip (GLEW and FreeGLUT is already included)
It is a Visual Studio 7.1 project. It can be converted to 8.0 (Express Edition and higher).
GLEW requires an initialization. When you do this initialization a valid OpenGL rendering context must be available. (In most cases this means an OpenGL window must be present and active).
Checking OpenGL Version
GLEW allows checking if all core extensions of a certain OpenGL Version (1.1, 1.2, 1.3, 1.5, 2.0, 2.1) are available. If you have for example OpenGL 1.3 installed, then the core extensions of OpenGL 1.2 and 1.1 will be present too.
There are two ways to check an extension: over a GLEW macro or – as a slower alternative – over a string.
Platform specific extensions
Platform specific extensions can also be queried using a GLEW macro. or using the functions "wglewIsSupported" or "glxglewIsSupported"). To use platform specific extensions include "wglew.h" or "glxglew.h" after the regular "glew.h".
1. Write a program which detects the OpenGL core version installed on your
machine and print the result to console. (use GLEW or GLee for this!)