How to create multiple window?

In some games,like Minecraft,they have two windows,one for the game and one launcher to launch the game.
So in GLFW,how do I create multiple window??
I know I need to use glfwMakeContextCurrent to choose which window you are currently using,but how do i program the game loop(poll event and update) for both window???
Example code also,please??
Pseudocode is fine too…

Here is the documentation page example extended to create two windows.

#include <GLFW/glfw3.h>

int main(void)
{
    GLFWwindow* window1;
    GLFWwindow* window2;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window1 = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window1)
    {
        glfwTerminate();
        return -1;
    }

    /* Create a second windowed mode window and its OpenGL context */
    window2 = glfwCreateWindow(640, 480, "World Hello", NULL, NULL);
    if (!window2)
    {
        glfwTerminate();
        return -1;
    }

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window1) && !glfwWindowShouldClose(window2))
    {
        /* Make the window's context current */
        glfwMakeContextCurrent(window1);
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);
        /* Swap front and back buffers */
        glfwSwapBuffers(window1);

        /* Make the second window's context current */
        glfwMakeContextCurrent(window2);
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);
        /* Swap front and back buffers */
        glfwSwapBuffers(window2);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

The order of operations inside the while loop are only an example of how rendering to more than one window could look.

2 Likes

You can also see the test code windows.c on Github.

Note that normally games use two processes for the launcher and the game, rather than two windows with the same process.

2 Likes