Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

c - Why Could glGetString(GL_VERSION) Be Causing a Seg Fault?

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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...