GLFW: size, position & monitorsGLFW 3.0

glfwGetPrimaryMonitor

Returns the user's main monitor, where the taskbar or menu bar usually is.

Signature

GLFWmonitor* glfwGetPrimaryMonitor(void);

How it works

A GLFWmonitor* is a handle you pass to the monitor functions (work area, video mode) or to glfwCreateWindow / glfwSetWindowMonitor for full screen. Other monitors come from glfwGetMonitors.

Return value

The primary monitor, or NULL if no monitor was found.

Tips & pitfalls

  • The handle becomes invalid if the monitor is disconnected; do not keep it forever.

Errors

When the call is invalid it does nothing and sets an error, which glGetError returns:

GLFW_NOT_INITIALIZED
Called before glfwInit or after glfwTerminate.

Example

example.cpp
1GLFWmonitor* monitor = glfwGetPrimaryMonitor();
2const GLFWvidmode* mode = glfwGetVideoMode(monitor);
3std::printf("%dx%d @ %d Hz\n", mode->width, mode->height, mode->refreshRate);
Official GLFW documentation