detecting screen resolution ?

Using GLFW
nicoo
2014-04-13
2014-04-15
  • nicoo
    nicoo
    2014-04-13

    Hi,
    is it possible to detect screen resolution with glfw ?
    I want to use

    glfwCreateWindow(w, h, "I will smoke your bones", glfwGetPrimaryMonitor(), NULL);

    where w and h depend of the current screen resolution

     
    Last edit: nicoo 2014-04-13
  • nicoo
    nicoo
    2014-04-14

    hi Doug and thank you for the answer.

    I tried,
    GLFWmonitor* monitor = glfwGetPrimaryMonitor();
    if(!monitor) exit(1);
    glfwGetMonitorPhysicalSize(monitor,&width,&height);

    std::cout << "wi=" << width <<" hei=" << height << std::endl;

    I got
    wi=0 hei=0

    so I guees on my OS I can't use glfwGetMonitorPhysicalSize...

     
  • arampl
    arampl
    2014-04-15

    Hi, begre1929!
    Doug shows to you correct documentation link. You've just used wrong function. You need to use "glfwGetVideoMode", which returns videomode structure with width and height members.

    #include "glfw3.h"
    #include <stdlib.h>
    #include <stdio.h>
    
    static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
    {
        if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
        glfwSetWindowShouldClose(window, GL_TRUE);
    }
    
    int main(int argc, const char * argv[])
    {
        GLFWvidmode *mode;
        GLFWwindow  *window;
    
        if(!glfwInit())
            exit(EXIT_FAILURE);
    
        mode = (GLFWvidmode*)glfwGetVideoMode(glfwGetPrimaryMonitor());
    
        window = glfwCreateWindow(mode->width, mode->height, "Screen resolution window", NULL, NULL);
    
        glfwMakeContextCurrent(window);
    
        glfwSetKeyCallback(window, key_callback);
    
        while(!glfwWindowShouldClose(window))
        {
            glClear(GL_COLOR_BUFFER_BIT);
            glfwSwapBuffers(window);
            glfwPollEvents();
        }
    
        glfwTerminate();
        exit(EXIT_SUCCESS);
    }
    

    Regards :)

     
    Last edit: arampl 2014-04-15
  • nicoo
    nicoo
    2014-04-15

    thx arample, this line,
    mode = (GLFWvidmode*)glfwGetVideoMode(glfwGetPrimaryMonitor());
    solved my problem.