OpenGL extension initialization

Started by
13 comments, last by Rhiakath 14 years, 12 months ago
Ok, maybe you guys can help me out if I show you a little snippet.

Tihs is a part of the main() function.

int main ( int argc, char *argv[] )
{
OpenGL::CGLContext Context;

Context.Initialize();
Context.CreateWindow();
.
.
.
OpenGL::CGLShaderProgram Program;
OpenGL::CGLShader VS, PS;
glCreateShader(GL_VERTEX_SHADER);
Context.InitializeExtensions();
glCreateShader(GL_VERTEX_SHADER);
VS.LoadFromFile ( OpenGL::CGLShader::VERTEX_SHADER, "default.vertex_shader" );

So, inside Initialize, all it does is create a context, then create a window to that context. Get extensions, destroy window (not the context).

The problem is, glCreateShader resolves just fine, when i get the pointer. the debugger shows me an address, and successfully resolves it into the func name, so I check it's correct.
after it leaves Initialize(), it comes to glCreateShader.
It segfaults here.
If I comment out that line, it just segfaults on the next glCreateShader, even after getting the func pointers again inside InitializeExtensions.
The only way it does not segfault, is if I call glCreateShader inside InitializeExtensions.

Nevertheless, the pointer remains with the same value all across the whole session.

What's happening here?
Advertisement
OpenGL::CGLShaderProgram Program;
OpenGL::CGLShader VS, PS;
glCreateShader(GL_VERTEX_SHADER);
Context.InitializeExtensions();

If I am reading this right you have glCreateShader() called before you initialize the extensions?
Quote:Original post by Rhiakath
And, of course, I'd only do this with functions that had similar signatures, right?

I assume you mean identical signature, not similar. Similar signature implies there is a difference in the signature, and then they definitely are different. But still, identical signature does in no way imply same functionality.

Quote:Original post by Rhiakath
Now, is it really needed for me to have a thousand if's, just checking if the core function is available, and if not use the extension?
Is there no other way?

No, it is not needed to make thousands of ifs to get around this. A few perhaps if you wrap it. For example, wrap shader functions around some unified interface, and then let the implementation of the interface deal with different extension and core support.
GLuint loadprogram(GLuint vshader, GLuint fshader){	GLuint program = glCreateProgram();	glAttachShader(program, vshader);	glAttachShader(program, fshader);	glLinkProgram(program);	return program;}

A quick example using the core variants to create a program with a vertex and a fragment shader. A single if is needed to make this use the ARB-variants when needed and I can still load all my shaders from thousands of places, which would need thousands of ifs without the wrapper.
Reading only that part, it would seem so. But as I said, it is calling Initialize Extensions inside Initialize, right at the beginning.
I'm just trying to figure out where it breaks, so I'm calling it twice, and enveloping it with glCreateShader.
Some more replies there before my post. Looks like there are some wrapper classes for shaders there, which is what I'm talking about. Don't use OpenGL-code directly everywhere; wrap it and use the interface instead.
That is what I'm doing. unfortunately, the opengl calls inside the shader class all segfault. I just added the opengl calls here to be able to see where it screws up. What bothers me, is that between the initialize call, and the shader loading call, there is nothing. and the pointer remains the same. why does it segfault?

This topic is closed to new replies.

Advertisement