PDA

View Full Version : glXGetProcAddress



nukem
02-18-2004, 12:40 PM
I am having a problem getting glXGetProcAddress working in my program. Here is my code




void* ClientActiveTextureARB = (void*)glXGetProcAddressARB((const GLubyte *)"glClientActiveTextureARB");

ClientActiveTextureARB(GL_TEXTURE0_ARB);


g++ gives me these errors.




NuclearBSP.cpp:135: error: `GL_TEXTURE0_ARB' undeclared (first use this
function)
NuclearBSP.cpp:135: error: (Each undeclared identifier is reported only once
for each function it appears in.)
NuclearBSP.cpp:135: error: `ClientActiveTextureARB' cannot be used as a
function
NuclearBSP.cpp:139: error: `GL_TEXTURE1_ARB' undeclared (first use this
function)
NuclearBSP.cpp:139: error: `ClientActiveTextureARB' cannot be used as a
function


Could someone please help me to get glXGetProcAddress to work?

Thanks

nuke

dorbie
02-18-2004, 02:18 PM
1) You need to include glext.h

2) You need to declare the pointer as a pointer to a function not a pointer to a void, (you can't jump to arbitrary addresses in void pointers, that would be crazy).

3) The best way to do 2) is to use the typed function pointer prototypes specific to each extension function in glext.h which buy you back the argument checking you would otherwise lose due to a lack of function prototypes for a function pointer.

[This message has been edited by dorbie (edited 02-18-2004).]

nukem
02-18-2004, 11:08 PM
I hate sounding stupid but, what do you mean? When you say "You need to declare the pointer as a pointer to a function not a pointer to a void, (you can't jump to arbitrary addresses in void pointers, that would be crazy)." what do you mean I dont understand that? Do you mean use typedef or GLAPI void APIENTRY as its declared in glext.h?

idr
02-19-2004, 09:50 AM
In C (or C++) it is illegal to "call" anything that isn't either a function or a pointer to a function. You wouldn't do something like:




int foo;

void bar( void )
{
foo();
}


And expect it to compile, would you? There are typedefs in glext.h specifically for each extension function. For example, for glMultiTexCoord2fv you would use PFNGLMULTITEXCOORD2FVPROC. So, the corrected version of your code would be:




PFNGLCLIENTACTIVETEXTUREARBPROC ClientActiveTexture = (PFNGLCLIENTACTIVETEXTUREARBPROC) glXGetProcAddressARB((const GLubyte *)"glClientActiveTextureARB");
(*CliengActiveTexture)(GL_TEXTURE0_ARB);


There are two things to note here. First, it is also invalid in the C99 standard to assign a (void *) to a pointer to function, hence the cast on the return value from glXGetProcAddressARB. Second, as you did in your original example, do not name your function pointers the same thing as the function (i.e., do not name the pointer in this example glClientActiveTextureARB). This is non-portable and will cause problems, at the very least, with the open-source drivers for Linux.

marcus256
02-20-2004, 02:12 AM
Read the GLFW Users Guide (http://glfw.sourceforge.net/UsersGuide.pdf) , Chapter 7 about OpenGL extensions. It deals with function pointers etc.

Personally, I prefer to include GL/glext.h from GL/gl.h include it. I always use my "custom" gl.h, glu.h & glext.h files, regardless of compiler and system.


[This message has been edited by marcus256 (edited 02-20-2004).]

nukem
02-23-2004, 08:34 PM
idr: I tried your way and while it compiled fine when linking I get a bunch of errors like this
/usr/lib/libGLcore.so.1: undefined reference to `NvRmAllocContextDma'
/usr/lib/libGL.so: undefined reference to `_nv000180gl@LIBGLCORE'
/usr/lib/libGL.so: undefined reference to `_nv000280gl@LIBGLCORE'
/usr/lib/libGL.so: undefined reference to `_nv000194gl@LIBGLCORE'
/usr/lib/libGL.so: undefined reference to `_nv000206gl@LIBGLCORE'
/usr/lib/libGL.so: undefined reference to `_nv000338gl@LIBGLCORE'
/usr/lib/libGL.so: undefined reference to `_nv000187gl@LIBGLCORE'
/usr/lib/libGL.so: undefined reference to `_nv000324gl@LIBGLCORE'

What are those all about?

marcus256: Thanks for the link it helps explain alot.

idr
02-24-2004, 10:45 AM
It's some irritating thing about the way Nvidia's drivers work. I don't know what the sollution is. Perhaps there's some information on Nvidia's developer site?

m2
02-24-2004, 11:45 PM
Originally posted by dorbie:
1) You need to include glext.h


No, you don't. Please point to the relevant doc (chapter and verse), that says this file exists at all. I beleive you are trying to say something else, namely, you need to have a private copy of the file commonly called "glext.h" (found for example at the OpenGL Extension Registry website), call it _something else_, and include that from your program.

idr
02-25-2004, 03:47 PM
I you are going to use extension functions, you need glext.h or something that has the relevant prototypes, typedefs, and enumerants defined. It makes no mention of that in the OpenGL specification because the specification only covers the core and not extensions.

m2
02-26-2004, 10:09 AM
Originally posted by idr:
I you are going to use extension functions, you need glext.h or something that has the relevant prototypes, typedefs, and enumerants defined. It makes no mention of that in the OpenGL specification because the specification only covers the core and not extensions.

The whole extension mechanism is well documented. The spec files provide prototypes for new functions and new tokens. This file, glext.h, does not exist _anywhere_. There are OpenGL installations which _do not_ provide this file, or provide this file under another name. Some don't provide _any_ extension information at all. In short: do not rely on the OpenGL to provide extension information in a specific file or at all, because it does not have to.

nukem
02-26-2004, 06:51 PM
I do need glext.h(or things declared in it) if I do not include it I get errors. If its not standard what should I do about things I need in it?

idr: I compiled and linked it sucesfully on my laptop(ATI Radeon Mobility 7500 using DRI drivers). The only problem is it seg faults out, this may be due to a coding error though. I guess ill do a search on problems with the nvidia drivers.

m2
02-26-2004, 10:23 PM
Originally posted by nukem:

I do need glext.h(or things declared in it) if I do not include it I get errors. If its not standard what should I do about things I need in it?

a) Cherry pick whatever you need from the glext.h file found at the extension registry and put it in your own private file.

b) Make a private copy of that file and ship it with your project.

c) Use one of the extension loading libraries already available. These take care of the problems you might have.

idr
02-28-2004, 06:50 PM
Nukem: As for the problem on the Radeon DRI driver, are you sure the extension you're trying to use exists? Just because glXGetProcAddress returns a pointer doesn't mean that function is actually supported. I don't know if that's causing your segfault, but it's something to check, anyway.

I also agree with m2. There are a number of extension loading libraries that take care of a lot of this grunt work.

nukem
03-02-2004, 05:55 PM
Originally I was trying to keep the deps as low(currently only *nix libs OpenGL and jpeglib) as possible but now I am considering using a lib out there. Anyway thanks for your help guys!!!