PDA

View Full Version : How to create multiple windows on multiple displays with GLFW



Wally Lee
06-29-2017, 12:08 PM
I'm trying to create 2 windows in fullscreen mode for 2 external monitors with GLFW. My program runs and output 2 windows in 2 monitors but 1 of them need to be minimized and cannot be both displayed at the same time.

I suspect it is because of switching context between the two windows that make it unable to run both but I'm not sure.

My code is below. windows size are corresponding to the monitors that they're being created. Anyone has ideas about this?


// glfw window creation
// --------------------
//WINDOW 1 AT MONITOR 1
GLFWwindow* window = glfwCreateWindow(mode1->width, mode1->height, "LearnOpenGL", m1, NULL);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);

//WINDOW 2 AT MONITOR 2
GLFWwindow* window2 = glfwCreateWindow(mode2->width,mode2->height,"LearnOpenGL2", m1,NULL);
glfwSetFramebufferSizeCallback(window2, framebuffer_size_callback);



while (!glfwWindowShouldClose(window) )
{
glfwMakeContextCurrent(window);
glClearColor(0.2f, 0.7f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

glfwMakeContextCurrent(window2);
glClearColor(0.7f, 0.1f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

glfwSwapBuffers(window);
glfwSwapBuffers(window2);

glfwPollEvents();
}

john_connor
06-30-2017, 09:52 AM
here is the description of the window creation function:
http://www.glfw.org/docs/latest/group__window.html#ga5c336fddf2cbb5b92f65f10fb6043 344

when creating the 2nd window, give it as last argument hte first GLFWwindow*, and specify the monitor to cover with the 2nd-last argument (instead of "m1" for both)


To create a full screen window, you need to specify the monitor the window will cover. If no monitor is specified, the window will be windowed mode. Unless you have a way for the user to choose a specific monitor, it is recommended that you pick the primary monitor. For more information on how to query connected monitors, see Retrieving monitors.