[Qt-interest] Using opengl extensions and getting the functions

Oliver Demetz forenbeitraege at oliverdemetz.de
Thu May 21 12:26:06 CEST 2009


Hi!

I want to use some of the opengl extensions in my qt app.

As an example, let us take the function

     void glActiveTextureARB ( GLenum texture );

In the opengl subdir of the sources of qt, I found an intersting file 
qglextensions_p.h and an accoriding header file.
But the usage of this file is somewhat unclear to me.

What I understand is that qt provides a portable function to obtain the 
function pointers via QGLContext::getProcAddress.

Also I think to have understood that it is not a good idea to give the 
obtained function its "original" name, so what they do is managing one 
central collection of all function pointers that are obtained via 
#defines that have the original name.

For our example the proceeding is as follows:

A) Define a type called " _glActiveTextureARB " via

       typedef void (APIENTRY *_glActiveTextureARB) (GLenum);

B) Have a funtion pointer variable somewhere with name

       _glMultiTexCoord2fARB   qt_glMultiTexCoord2fARB = NULL;
               ^^^^                    ^^^^
               type                variable name

C) "Fill" the variable with the address of the wntry point of the actual 
gl function. This can be done via

       qt_glMultiTexCoord2fARB = (_glMultiTexCoord2fARB)
             GLContext::currentContext()->getProcAddress(
                   QLatin1String("glMultiTexCoord2fARB"));

Ok, I've a clue what is going on. Now my next step is to deploy this 
into my code *elegantly*. So far, I've packed step A into a header file 
"MyExtensions.h" and steps B and C are performed in place where I need 
the call the function, eg. in paintGL. By decalring the variable in step 
B as static, the resolving in step C is only done once.

BUT THIS IS EVERYTHING ELSE THAN ELEGANT. HOW CAN I EXPORT ALL THESE 
STEPS INTO A HEADER FILE?

Thanks in advance,
Oliver



More information about the Qt-interest-old mailing list