Confused about extensions on linux

hey,

i’m kind of confused as far as using extensions with linux. Does it work the windows way, with a function like wglGetProcAdd, or the Mac way where you only need to make sure that the extension is supported and don’t need a function pointer. In the forums I have seen people using glXGetProcAdd, but I have also seen some SDl code that only checks to see if the string is present?

second, would a simpler solution be to use GLEW? From what i’ve read it seems like GLEW takes care of anything special that needs to be done to use an extension.

thank you.

On Linux and other X-Windows systems, you use glXGetProcAddress . There are a couple differences between this function and the wgl version that you need to keep in mind.

[ol][li] Function pointers returned by glXGetProcAddress are context independent. That means that you can call glXGetProcAddress to initialize function pointers before you even create a context.[/li] [li] As a consequence of 1, glXGetProcAddress never returns NULL. Because of the way function dispatch work on Linux (and probably other Unixes as well), a pointer to a function will be returned even if the function is not supported by the GL implementation. Calling that function my result in a crash. Try calling glXGetProcAddress with “glFooBar” sometime. :slight_smile: [/li] [li] In general it is not a good idea to name your function pointer the same thing as the real function (see the code snippet below). I know this is common practice on Windows, but it’s no different than having a global variable “void *(*malloc)(size_t)”. You wouldn’t expect that to work, would you?[/ol][/li]

PFNGLMULTITEXCOORD2DARBPROC glMultiTexCoord2DARB;

...

glMultiTexCoord2DARB = (PFNGLMULTITEXCOORD2DARBPROC)
    glXGetProcAddressARB((GLubyte *)"glMultiTexCoord2DARB");

That said, using extension wrapper libraries is a pretty good idea. You won’t have to worry about platform dependencies, and they usually have utility routines to check for the existance of extensions.

AFAIK if you don’t need the functionpointer but I’m not sure its allways the case. I have never used them. Maybe they have changed something. The best way is to use GLEW.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.