GLFW_OPENGL_CORE_PROFILE导致分段故障

GLFW_OPENGL_CORE_PROFILE causes segmentation fault

本文关键字:分段 故障 PROFILE OPENGL CORE GLFW      更新时间:2023-10-16

我遵循OpenGL教程http://www.learnopengl.com/#!开始/Hello-Window

我按照教程中的教导编写了以下代码,但是设置配置文件会导致立即分割错误。程序给出了没有该行的预期输出。

#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main() {
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //SEGFAULT
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
    GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
    glfwMakeContextCurrent(window);
    glewExperimental = GL_TRUE;
    glewInit();
    glViewport(0, 0, 800, 600);
    while(!glfwWindowShouldClose(window))
    {
        glfwPollEvents();
        glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        glfwSwapBuffers(window);
    }
    glfwDestroyWindow(window);
    glfwTerminate();
    return 0;
}

如果有帮助,glxinfo | grep OpenGL的输出如下:

OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Sandybridge Mobile 
OpenGL core profile version string: 3.1 (Core Profile) Mesa 10.1.3
OpenGL core profile shading language version string: 1.40
OpenGL core profile context flags: (none)
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 10.1.3
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:

原来OpenGL 3.2中添加了核心和兼容性配置文件模式。因为我的系统是3.0版本,设置这个参数会导致崩溃。

所以对于低于3.2的版本,你不需要设置兼容模式或核心配置文件