【问题标题】:OpenGL nvoglv32.dll error after resizing window调整窗口大小后出现 OpenGL nvoglv32.dll 错误
【发布时间】:2020-11-28 17:41:27
【问题描述】:

我有以下功能:

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;
}

,我用它来调整窗口大小和/或设置它的参数。我首先销毁当前的,然后创建一个新的。当我在此之后调用第一个函数时,会发生以下错误:OpenGL nvoglv32.dll error

如果我不拨打buildWindow function,它可以正常工作。

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

【问题讨论】:

    标签: c++ opengl glfw


    【解决方案1】:

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

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

    请注意,底层的 GL 绑定 API(wgl、glX、egl、...)没有这样的限制 - 窗口和 GL 上下文在那里是不同的实体,销毁窗口不会影响 GL 上下文,您可以稍后将其绑定到另一个窗口,但您必须确保该窗口与上下文兼容(根据您所使用的平台使用不同的规则)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-11
      • 2015-05-23
      • 2019-10-12
      • 2013-02-09
      相关资源
      最近更新 更多