glGenTextures segmentation fault?
Asked Answered
A

2

6

So here is the problem: When I call glGenTextures I get a segmentation fault.

I'm on linux, and here is the code I'm currently using to investigate this:

#include <iostream>
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>

int main(int argc, char *argv[])
{
    GLuint texture;
    glGenTextures( 1, &texture );
    return texture;
}

Seems simple enough, right? Well, I traced the segfault with GDB (the GNU debugging tool) and it occurs when I call glGenTextures(), in the file /usr/lib/mesa/libGL.so.1.

That's my video driver's openGL code...

Any ideas?

Asiatic answered 2/11, 2012 at 12:1 Comment(0)
M
12

The code as shown hasn't done anything to set up a valid OpenGL context, so it can't use OpenGL.

How to do this varies by platform. If you don't want to dig down in your target platform's way of doing this, you can use something like GLFW to do it fairly portably, but of course that adds a dependency.

Monopolist answered 2/11, 2012 at 12:5 Comment(1)
On a side note: glGenTextures should not crash if there's no valid OpenGL context made current. It should just default to a No-Op and leave the contents of the texture names array unchanges. That it crashes in this condition is actually a Mesa bug.Endstopped
H
1

As user "unwind" say, you need to init your OpenGL context. You can do it without 3Dparty libs, though - check up this NeHe example: http://nehe.gamedev.net/tutorial/texture_mapping/12038/

Hope this helps.

Holography answered 2/11, 2012 at 12:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.