我在Linux 13 XFCE上。我的问题是,当我在终端运行时,命令:
glxinfo | grep "OpenGL version"
我得到以下输出:
OpenGL version string: 3.3.0 NVIDIA 295.40
但是,当我在应用程序中运行glGetString(GL_VERSION)
时,结果为null。为什么这段代码没有得到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));
}
发布于 2012-08-29 18:48:50
glutInit()
不创建GL上下文或创建一个电流。您需要一个当前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));
}
发布于 2019-03-10 10:16:50
还可以使用glfw
创建GL上下文,然后查询版本:
包括以下文件:
#include "GL/glew.h"
#include "GLFW/glfw3.h"
然后你就可以:
// Initialise GLFW
glewExperimental = true; // Needed for core profile
if (!glfwInit())
{
return "";
}
// We are rendering off-screen, but a window is still needed for the context
// creation. There are hints that this is no longer needed in GL 3.3, but that
// windows still wants it. So just in case.
glfwWindowHint(GLFW_VISIBLE, GL_FALSE); //dont show the window
// Open a window and create its OpenGL context
GLFWwindow* window;
window = glfwCreateWindow(100, 100, "Dummy window", NULL, NULL);
if (window == NULL) {
return "";
}
glfwMakeContextCurrent(window); // Initialize GLEW
if (glewInit() != GLEW_OK)
{
return "";
}
std::string versionString = std::string((const char*)glGetString(GL_VERSION));
https://stackoverflow.com/questions/12184506
复制相似问题