无法在OpenGL中获得GLSL着色器

时间:2013-01-05 02:28:38

标签: c++ opengl glsl shader

我一直在这台机器上开发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。

P.S。如果我删除了glewExperimental,则代码会在glGenVertexArrays上崩溃。

1 个答案:

答案 0 :(得分:2)

不幸的是,GLEW与当前的OpenGL开发并不相同,特别是如果涉及核心上下文或显式版本配置文件。直到最近我才有同样的问题,也与GLFW一起。省略设置OpenGL版本窗口提示确实解决了我的问题。即禁用或删除这两个电话:

glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);