10

I'm learning OpenGL on Fedora 13 and noticed that a call to glGetString is causing a seg fault. I've scraped Google, but come up with no solutions.

The code is simple:

#include <GL/gl.h>

int main() {
    glGetString(GL_VERSION);
    return 0;
}

Compile Command:

g++ -lGL main.cpp -o test.bin

Run result:

$ ./test.bin 
Segmentation fault (core dumped)

OpenGL Info:

$ glxinfo | grep OpenGL
OpenGL vendor string: Tungsten Graphics, Inc
OpenGL renderer string: Mesa DRI Intel(R) IGDNG_M GEM 20100328 2010Q1 
OpenGL version string: 2.1 Mesa 7.8.1
OpenGL shading language version string: 1.20
OpenGL extensions:

Any ideas or references are greatly appreciated.

Solution:

#include <iostream>
#include <GL/freeglut.h>

int main(int argc, char **argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA);
    glutCreateWindow("test");
    glutFullScreen();
    std::cout << glGetString(GL_VERSION) << std::endl;
    return 0;
}
Cryo
  • 817
  • 1
  • 7
  • 16

1 Answers1

16

I doubt you can call even something as simple as glGetString without an OpenGL context.

Nicolas Lefebvre
  • 4,247
  • 1
  • 25
  • 29
  • I think you're right. The docs of glGetString say it returns information about the "current GL connection" but I don't think the original poster has initialized this connection. http://www.opengl.org/sdk/docs/man/xhtml/glGetString.xml – David Grayson Jun 09 '11 at 06:32
  • 2
    Direct hit! Thanks for the help. – Cryo Jun 09 '11 at 06:41
  • wow... been racking my head for half an hour wondering if I had forgotten everything about pointers turns out I was calling it at the wrong time lol! Thanks, as simple as this answer is it is very insightful – Mahmud Ahmad Apr 08 '21 at 02:07