1
\$\begingroup\$

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

        mWindow = newWindow;
        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?

\$\endgroup\$
3
  • \$\begingroup\$ gamedev.stackexchange.com/questions/38620/… this might help. Looks like you don't need to destroy the window, just close it. \$\endgroup\$ Jul 30 '13 at 15:30
  • \$\begingroup\$ I see; in any case, I still need to re-create the window and keep the context for other issues, so the question remains \$\endgroup\$ Jul 30 '13 at 16:13
  • \$\begingroup\$ I believe if you destroy the window you lose the context. My link implies that you do no destruction or re-creation. glfwCloseWindow() and glfwOpenWindow() will close the current window and open a new one with the current context. \$\endgroup\$ Jul 30 '13 at 18:06

You must log in to answer this question.

Browse other questions tagged .