为什么 glGetString(GL_VERSION) 会导致段错误? [英] Why Could glGetString(GL_VERSION) Be Causing a Seg Fault?

查看:38
本文介绍了为什么 glGetString(GL_VERSION) 会导致段错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Fedora 13 上学习 OpenGL,并注意到对 glGetString 的调用导致了段错误.我已经搜索了 Google,但没有找到解决方案.

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.

代码很简单:

#include <GL/gl.h>

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

编译命令:

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

运行结果:

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

OpenGL 信息:

$ 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.

解决方案:

#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;
}

推荐答案

我怀疑如果没有 anOpenGL 上下文.

这篇关于为什么 glGetString(GL_VERSION) 会导致段错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆