For a while now, I have been playing around with making a game using OpenGL, and glfw3. I have been perfectly happy to create windows at my native resolution of 1920x1080. I'm getting to the point where I want to share it with other developers, so I cannot keep hard coding the screen resolution in. I went looking for ways to find the maximum resolution of the available monitor, which glfw provides using the function glfwGetVideoModes(GLFWwindow*, int);. It supposedly finds all available displays for a monitor (resolution, color depth, refresh rate), and returns them as an array of possibilities.

void GetMaxMonitorResolution(int* w, int* h)
    int count;
    const GLFWvidmode* modes = glfwGetVideoModes(glfwGetPrimaryMonitor(), &count);

    int maxWidth = 0;
    int maxHeight = 0;
    for (int i = 0; i < count; i++)
        if (modes[i].width > maxWidth)
            maxWidth = modes[i].width;
        if (modes[i].height > maxHeight)
            maxHeight = modes[i].height;

    *w = maxWidth;
    *h = maxHeight;

The problem is, even though my monitor supports 1920x1080, it keeps creating a window at 800x600, the smallest resolution possible on my monitor. I am relatively new to C++, so I am only 80% sure how pointers work, especially pointers to arrays and the such. So if I am somehow messing up the pointers, or if it truly is a problem with glfw, I would appreciate any help.

EDIT: The documentation for glfw3 monitors is here and here, in case anyone was wondering.

  • 2
    \$\begingroup\$ Have you considered debugging into the code and/or printing out all the available video modes? That way you can actually see what's available. \$\endgroup\$ Aug 5, 2013 at 0:47
  • \$\begingroup\$ I think that there may be case, that you get max width from one mode and max height from another mode, getting at end resolution that is not in any mode, and mode resets to default. \$\endgroup\$
    – Somnium
    Mar 2, 2017 at 16:36

1 Answer 1


Your code works perfectly on my computer.

What happens if you simply use glfwGetVideoMode instead? For example,

void get_resolution() {
    const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor());

    window_width = mode->width;
    window_height = mode->height;

That should give you the user's desktop resolution, which is probably what you want. If the above doesn't work either, I'm going to guess that it is a bug in the build of GLFW that you are using.

  • \$\begingroup\$ I'm using GLFW 3.0.2, so I don't think that this is a bug. I'm sure I just messed up the math somewhere, but until I fix that I tried this and it worked! Thanks. \$\endgroup\$
    – sm81095
    Aug 6, 2013 at 5:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .