6
\$\begingroup\$

I am currently learning GLFW using C++. I have found many tutorials on initializing windows, but not many on initializing full screen, and next to nothing on initializing full screen on a secondary display (In this case, my television). This way I can use my primary display for logging and debugging.

I have visited the man-pages for GLFW. However, even after going over examples for glfwGetMonitors(), I am still not entirely sure how to use these in conjunction with glfwCreateWindow().

I have included links to the reference pages.

GLFW Monitor Guide

GLFW Window Guide

\$\endgroup\$
  • \$\begingroup\$ Would be so kind as to accept my answer if it helped you? \$\endgroup\$ – Miles Rout Dec 3 at 20:42
1
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.