Jump to content
  • Advertisement
Sign in to follow this  
supagu

OpenGL OGL extensions under linux seg. fault

This topic is 4059 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

trying to get opengl extensions working under linux. I have the following layout with my cpp/h files: OGLExtension.h: typedef void (APIENTRY * PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers); extern PFNGLGENBUFFERSARBPROC glGenBuffersARB; OGLExtension.cpp: PFNGLGENBUFFERSARBPROC glGenBuffersARB = 0; OGLDevice.h: #include "OGLExtension.h" OGLDevice.cpp: void* pAddr = (void*)glXGetProcAddress((const GLubyte*)"glBindBufferARB"); void **p = reinterpret_cast<void**>(&glBindBufferARB); *p = pAddr; the above code gets compiled in to a static library which is then linked to my main exe. problem is glGenBuffersARB is not set to 0 before the code is run to init the function pointer. This then causes a segmentation fault when the line is run: *p = pAddr; i've tried moving all this code snippet in to my main.cpp file and glGenBuffersARB is set to 0 so init'ing of the function pointer works correctly with out segmentation fault. any idea why when in a seperate static lib this is not being set to 0? btw using code::blocks and gcc/g++ compiler

Share this post


Link to post
Share on other sites
Advertisement
supagu,
Try this way;

typedef void (APIENTRY * PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);

// notice "p" at the begining to avoid having same name as function
PFNGLGENBUFFERSARBPROC pglGenBuffersARB = 0;
#define glGenBuffersARB pglGenBuffersARB;

int main()
{
// must initialize OpenGL context before using any GL calls
...

// get the function pointer
glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)glXGetProcAddress((const GLubyte*)"glGenBufferARB");
if(glGenBuffersARB == 0)
{
std::cout << "Failed to get the function pointer." << std::endl;
return 0;
}

// safe to call glGenBuffers
GLuint id;
glGenBuffersARB(1, &id);

...
}




I also notice an incorrect function name in your code; glBindBufferARB instead of glGenBuffersARB.

[Edited by - songho on June 8, 2007 12:05:50 PM]

Share this post


Link to post
Share on other sites
that does the trick!
so is this some compiler work around as my origonal code works fine under windows?

Share this post


Link to post
Share on other sites
it's not a compiler workaround: the issue is that you need a valid openGL context before you try to fetch openGL functions (atleast if you use glXGetProcAddress) as to why it works under windows, chances are is that Windows is not as anal about requiring a valid openGL context before you go fetching openGL functions with wglGetProcAddress (or whatever it is called).. the reason why Windows is probably not as anal is that in Windows almost everything about playing with the display is local, while in X, your app may be running on a completely different machine than where it is displayed (that is why in X, one talks about an X server)...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!