我已经在这台机器上开发 opengl 有一段时间了,突然间,GLEW 报告说我没有运行 opengl glsl 所需的扩展,即使它在其他项目中也可以工作。有趣的是,我什至得到
OpenGL Vendor: NVIDIA Corporation
OpenGL Renderer: GeForce 610M/PCIe/SSE2
OpenGL Version: 3.3.0
OpenGL 2.0 is available!
[FAILED] OpenGL Shading Language is not available...
我使用 glsllib 0.9.4 来加载扩展,而后者又使用 GLEW。我的代码如下:
bool Jogo::init() {
if(glfwInit() != GL_TRUE) return false;
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE);
if(glfwOpenWindow(1024, 768, 0, 0, 0, 0, 32, 0, GLFW_WINDOW) != GL_TRUE) return false;
glewExperimental = true;
if(initGLExtensions() != true) return false;
glm::mat4 matrizModel = glm::mat4(1.0f);
glm::mat4 matrizView = glm::lookAt(glm::vec3(0, 0, 3), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
glm::mat4 matrizProjecao = glm::perspective(45.0f, 9.0f/16.0f, -1.0f, 1.0f);
m_matrizMVP = matrizProjecao * matrizView * matrizModel;
m_shader = m_gerenciadorShader.loadfromFile("vshader.glsl", "fshader.glsl");
char *x = m_shader->getLinkerLog();
m_shader->setUniformMatrix4fv("mvp", 1, GL_FALSE, &(m_matrizMVP[0][0]));
m_world = new World();
glClearColor(0.0f, 0.2f, 0.5f, 0.0f);
glClearDepth(0.0f);
return true;
}
glsllib 加载扩展的代码是:
bool GLSLAPI initGLExtensions(void) {
if (extensions_init) return true;
extensions_init = true;
GLenum err = glewInit();
if (GLEW_OK != err) {
cout << "Error:" << glewGetErrorString(err) << endl;
extensions_init = false;
return false;
}
cout << "OpenGL Vendor: " << (char*) glGetString(GL_VENDOR) << "\n";
cout << "OpenGL Renderer: " << (char*) glGetString(GL_RENDERER) << "\n";
cout << "OpenGL Version: " << (char*) glGetString(GL_VERSION) << "\n\n";
checkGLSL();
return true;
}
CheckGLSL 在哪里查找glewGetExtension("GL_ARB_fragment_shader")
并glewGetExtension("GL_ARB_vertex_shader")
查看是否支持 GLSL。
PS 如果我删除 glewExperimental,代码会在glGenVertexArrays
.