Using GL Extensions

If you want to use a "new" feature in OpenGL, you'll probably find that while the version of OpenGL on your machine (the driver and low level software) is up to date, the support for it in the development environment is not. That is, your version of visual studio probably has an older version of things like "gl.h" and openg32.lib.

Even if it is up to date, there are some GL features that might be unique to your graphics card, ...

Fortunately, the inventors of OpenGL planned for this through a mechanism called an "extension". The idea is that for an advanced feature of OpenGL, you can ask the driver if it is supported, and talk to it "directly."

To make this easy, you can use a "GL Extension Manager" library. This is a program that makes calling "new" features in GL almost as easy as if it were in your version of "gl.h"

There are two different GL extension managers that I know about:

GLEE seems easier (its just one big C file to compile, or they give you the lib file). GLEW seems to be more "industrial strength." In last year's 559, most students used GLEE (and they found it themselves).

 

Using GLEE

To use GLEE you should

  1. Download a copy
  2. Put the .h file and .lib file in your project directory. (its actually better to put it somewhere else, but this is the easiest thing)
  3. Use #inlcude <glee.h> BEFORE you do #include <gl.h> (glee is smart enough to give you an error if you don't)
  4. Add glee.lib to your libraries that you link to
  5. Use opengl command that you didn't have before
 

An example...

I changed the texture tutorial to do multitexturing. I'll make a spotlight circle on each of the faces.

In the OpenGL book (mine is version 1.4) I see a command "glActiveTexture" that switches between textures. So my first step is to change the existing line

fetchTexture("cs559.jpg", GL_REPEAT, GL_REPEAT);

to be the two lines (that select a texture unit):

glActiveTexture(GL_TEXTURE0); fetchTexture("cs559.jpg", GL_REPEAT, GL_REPEAT);

But when I try to use it, I get an error that glActiveTexture and GL_TEXTURE0 are undefined. So I need to use GLEE to get it.

I "install" glee (copy the .h file and .lib file into my project directory and add glee.lib to my list of libraries I am using. I also need to add the #include "glee.h" before the #include "gl.h" in MyWindow.H.

Now the program compiles and runs again. Nothing new has happened, I'm just specifying which texture unit to use to do the work that already was done.

Now, I'll add the following after the above 2 lines:

glActiveTexture(GL_TEXTURE1);
fetchTexture("circle.jpg", GL_REPEAT, GL_REPEAT);

Which means we'll use two textures. However, in order to use the two textures, I need to give texture coordinates for both. I'll do this in a tricky way of making a macro that redines the "normal" texture coordinate specification to set both textures.

#define glTexCoord2f(u,v) {glMultiTexCoord2f(GL_TEXTURE0,u,v);\
	                   glMultiTexCoord2f(GL_TEXTURE1,u,v);}

The use of the macro to "alias" a library function is ugly, but easy for this (I wanted to avoid typing).

At this point things work - I get multi-texturing (the two textures are multiplied on top of each other, so there's a circle on each face). If I really wanted things to work right I would have to start setting more of the texture parameters to get the two textures to combine better.

But the point here was not to teach you how to do multi-texturing, it was to show how to use GLEE to have access to GL functions that are in the book, but not in our header.