我有以下功能:
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
,它就能正常工作。
为什么会发生这种情况,我该如何解决这个问题?
发布于 2020-11-28 17:57:22
在GLFW中,GL上下文被绑定到窗口,当您销毁窗口时,您将销毁GL上下文-以及与之相关的所有GL对象:纹理、缓冲区、着色器、VAOs等等。并且您的代码仍然保留的所有GL对象名称都将无效。如果重新创建窗口,则必须使用它重新创建所有GL对象。
在GLFW中没有简单的方法可以绕过这一点。您可以摆弄共享上下文-但即使是共享上下文也只共享像纹理和缓冲区这样的“重”状态对象,而不是像VAOs这样的“轻量级”状态容器。
注意底层的GL绑定API (wgl,glX,egl,...)不要有这样的限制-窗口和总账上下文是不同的实体,销毁窗口不会影响总账上下文,您可以稍后将其绑定到另一个窗口,但您必须确保窗口与上下文兼容(根据您所使用的平台,规则会有所不同)。
https://stackoverflow.com/questions/65052665
复制相似问题