I'm making a C++ game, and I want it to automatically get the user's desktop resolution.
I've found windows-only solutions so far - is there a way/library to find the resolution on Windows/Mac/Linux?
I'm making a C++ game, and I want it to automatically get the user's desktop resolution.
I've found windows-only solutions so far - is there a way/library to find the resolution on Windows/Mac/Linux?
I did a cross-platform c++ function:
There are several libraries helping you at getting the low-level stuff to work out. You'll probably need more stuff on those platforms anyways, so I'll list some:
GLFW provides a crossplatform (for Windows, Mac, and Linux) way to get the desktop video mode. It is a C api, but it will work in C++. The relevant function (and documentation) is here:
void glfwGetDesktopMode( GLFWvidmode *mode )
Parameters
mode
Pointer to aGLFWvidmode
structure, which will be filled out by the function.Return values
The
GLFWvidmode
structure pointed to by mode is filled out with the desktop video mode.Description
This function returns the desktop video mode in a
GLFWvidmode
structure. SeeglfwGetVideoModes
for a definition of theGLFWvidmode
structure.Notes
The color depth of the desktop display is always reported as the number of bits for each individual color component (red, green and blue), even if the desktop is not using an RGB or RGBA color format. For instance, an indexed 256 color display may report RedBits = 3, GreenBits = 3 and BlueBits = 2, which adds up to 8 bits in total.
The desktop video mode is the video mode used by the desktop at the time the GLFW window was opened, not the current video mode (which may differ from the desktop video mode if the GLFW window is a fullscreen window).
See Jonas Wielicki's answer for alternatives.