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?

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top