OpenGL nvoglv32.dll 调整大小后出错 window

OpenGL nvoglv32.dll error after resizing window

我有以下功能:

void introMenu(unsigned int texture,Shader shader, unsigned int VAO){
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, texture);
  shader.use();
  glBindVertexArray(VAO);
  glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
}

我在下面的函数之后调用它:

int buildWindow(GLint WINDOW_WIDTH,GLint WINDOW_HEIGHT,char *windowTitle,GLint focused, bool fullscreen){
    if(window!=NULL){
        glfwDestroyWindow(window);
    }
    glfwWindowHint(GLFW_RESIZABLE,GLFW_TRUE);
    glfwWindowHint(GLFW_VISIBLE,GLFW_TRUE);
    glfwWindowHint(GLFW_DECORATED,GLFW_TRUE);
    glfwWindowHint(GLFW_FOCUSED,GLFW_TRUE);
    glfwWindowHint(GLFW_FLOATING,focused);
    glfwWindowHint(GLFW_MAXIMIZED,GLFW_FALSE);
    glfwWindowHint(GLFW_CENTER_CURSOR,GLFW_FALSE);
    glfwWindowHint(GLFW_SCALE_TO_MONITOR,GLFW_TRUE);
    glfwWindowHint(GLFW_SAMPLES,4);
    glfwWindowHint(GLFW_DOUBLEBUFFER,GLFW_TRUE);
    glfwWindowHint(GLFW_REFRESH_RATE,GLFW_DONT_CARE);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,3);
    glfwWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE);
    if(!fullscreen){
        window=glfwCreateWindow(WINDOW_WIDTH,WINDOW_HEIGHT,windowTitle,NULL,NULL);
    }
    else{
        window=glfwCreateWindow(WINDOW_WIDTH,WINDOW_HEIGHT,windowTitle,glfwGetPrimaryMonitor(),NULL);
    }
    
    if(window==NULL){
        fprintf(stderr,"Failed to open GLFW window, possibly because of your Intel GPU\n");
        getchar();
        glfwTerminate();
        return -1;
    }

    //get monitor size
    const GLFWvidmode *mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    int monitorX, monitorY;
    glfwGetMonitorPos(glfwGetPrimaryMonitor(), &monitorX, &monitorY);
    //get window size
    int windowWidth, windowHeight;
    glfwGetWindowSize(window, &windowWidth, &windowHeight);

    //center window
    glfwSetWindowPos(window, monitorX + (mode->width - windowWidth) / 2, monitorY + (mode->height - windowHeight) / 2);
    
    //window icon
    GLFWimage icon[1];
    icon[0].pixels = stbi_load("images/icon/icon.png", &icon[0].width, &icon[0].height, 0, 4);
    glfwSetWindowIcon(window, 1, icon); 
    stbi_image_free(icon[0].pixels);


    //make window contest
    glfwMakeContextCurrent(window);

    return 0;
}

,这是我用来调整大小的window and/or设置它的参数。我首先销毁当前的,然后创建一个新的。当我在此函数之后调用第一个函数时,出现以下错误:OpenGL nvoglv32.dll error

如果我不调用 buildWindow function,它工作正常。

为什么会发生这种情况,我该如何解决这个问题?

在 GLFW 中,GL 上下文与 window 相关联,当您销毁 window 时,您会销毁 GL 上下文 - 以及所有包含它的 GL 对象:纹理、缓冲区、着色器、VAO 等等。并且您的代码仍然持有的所有 GL 对象名称都变得无效。如果您重新创建 window,则必须使用它重新创建所有 GL 对象。

在 GLFW 中没有简单的解决方法。您可以 fiddle 使用共享上下文 - 但即使是共享上下文也只共享“重”状态对象,如纹理和缓冲区,而不共享“轻量级”状态容器,如 VAO。

请注意,底层 GL 绑定 API(wgl、glX、egl、...)没有此类限制 - windows 和 GL 上下文在那里是不同的实体,并且会破坏 window不会影响 GL 上下文,您稍后可以将其绑定到另一个 window,但您必须确保 window 与上下文兼容(根据您使用的平台有不同的规则) .