I am using GLFW 3.0.2 and when I want to switch the application to fullscreen, I create a new window and intend to use the OpenGL context of the old window so I don’t have to reload all the meshes, materials, etc and can just draw it again…
This is what I do when I want to create a new window, such as when first creating the window or switching fullscreen mode:
bool GLFWWindowManager::SetupWindow(const uint32_t width, const uint32_t height)
{
glfwWindowHint(GLFW_SAMPLES, mMSAA);
auto newWindow = glfwCreateWindow(width, height, mWindowTitle.c_str(), mFullscreen ? glfwGetPrimaryMonitor() : NULL, mWindow); // mWindow is NULL first time
if (!newWindow)
return false;
if (mWindow) // if old window present, destroy the old window
glfwDestroyWindow(mWindow);
glfwMakeContextCurrent(newWindow);
mWindow = newWindow;
glewExperimental = GL_TRUE;
GLenum glewErr = glewInit();
const GLubyte* l = glewGetErrorString(glewErr);
glViewport(0, 0, (GLsizei) width, (GLsizei)height);
return true;
}
// the flow:
void GLFWWindowManager::Test()
{
SetupWindow(800, 600);
glfwMakeContextCurrent(mWindow);
// draw meshes
mFullscreen = true;
SetupWindow(800, 600);
// try to draw some meshes, crashes on GLDrawElements
}
What am I doing wrong?
also - how on earth to you encase something in code blocks here?
Alright, tried that (edited first post) and glewInit() passes without error both times, still crashes on glDrawElements - what else could be the problem?
(note: glewInit() did throw an error when I tried to do it before glfwMakeContextCurrent(), but glewInit() runs fine with what I posted)
Ah, you have to set ALL the state again? I thought that would be carried over, as it is the same context?
I suppose the OpenGL objects persist though? so I dont have to recreate all the buffer objects; but I have to set all their state again (GL_ARRAY_BUFFER, VAO’s, etc)?