You can use glfwGetMonitors
to get a pointer into an array of GLFWmonitor*
pointers.
You can create a window on a particular monitor using glfwCreateWindow
. The fourth parameter is the monitor you want to create the window on.
As it says in the GLFW documentation
To create a full screen window, you need to specify which monitor the window should use. In most cases, the user's primary monitor is a good choice.
The example given is
GLFWwindow* window = glfwCreateWindow(640, 480, "My Title",
glfwGetPrimaryMonitor(), NULL);
But for your purpose, creating a window on a secondary monitor, you should do this:
int count;
GLFWmonitor **monitors = glfwGetMonitors(&count);
GLFWwindow *window = glfwCreateWindow(640, 480, "My Title",
monitors[1], NULL);
Of course, you need to ensure that there are enough monitors and there are no errors (check that count >= 2
and monitors != NULL
). The error-handling is up to you. There are many ways to deal with errors.
This function stores the length of the array in the integer you pass a pointer to. This is quite standard in C, as C does not support tuples or pairs or multiple return values.
You also need to get the dimensions of the monitor so you can create a window of the correct size. You can do this like this:
const GLFWvidmode *mode = glfwGetVideoMode(monitors[1]);
... = glfwCreateWindow(mode->width, mode->height, ...);
There are other video modes as well that you might want to set on the window, like the refresh rate. If the video modes you set match the current video modes of the monitor exactly, you will get a 'borderless fullscreen' window, which is basically fullscreen but smoother.
If the closest match for the desired video mode is the current one, the video mode will not be changed, making window creation faster and application switching much smoother. This is sometimes called windowed full screen or borderless full screen window and counts as a full screen window. To create such a window, simply request the current video mode.