gpt4 book ai didi

c++ - 为什么 glGetString(GL_VERSION) 返回 null/zero 而不是 OpenGL 版本?

转载 作者:IT老高 更新时间:2023-10-28 21:50:45 29 4
gpt4 key购买 nike

我使用的是 Linux Mint 13 XFCE。我的问题是,当我在终端中运行命令时:

glxinfo | grep "OpenGL version"

我得到以下输出:

OpenGL version string: 3.3.0 NVIDIA 295.40

但是当我在我的应用程序中运行 glGetString(GL_VERSION) 时,结果为空。为什么这段代码没有得到 gl_version

#include <stdio.h>
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/glext.h>

int main(int argc, char **argv) {

glutInit(&argc, argv);
glewInit();

printf("OpenGL version supported by this platform (%s): \n",
glGetString(GL_VERSION));
}

最佳答案

glutInit() 不会创建 GL context 使一个电流。您需要一个当前的 GL 上下文才能使 glewInit()glGetString() 工作。

试试这个:

#include <GL/glew.h>
#include <GL/glut.h>
#include <cstdio>

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutCreateWindow("GLUT");

glewInit();
printf("OpenGL version supported by this platform (%s): \n", glGetString(GL_VERSION));
}

关于c++ - 为什么 glGetString(GL_VERSION) 返回 null/zero 而不是 OpenGL 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12184506/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com