system
April 13, 2014, 11:27pm
1
begre1929 wrote on Sunday, April 13, 2014 :
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
system
April 14, 2014, 8:47am
2
system
April 14, 2014, 8:48pm
3
begre1929 wrote on Monday, April 14, 2014 :
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…
system
April 15, 2014, 2:29am
4
arampl wrote on Tuesday, April 15, 2014 :
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
system
April 15, 2014, 3:26am
5
begre1929 wrote on Tuesday, April 15, 2014 :
thx arample, this line,
mode = (GLFWvidmode*)glfwGetVideoMode(glfwGetPrimaryMonitor());
solved my problem.
UAs
May 27, 2020, 8:58am
6
Hi this did solve my problem, but I wanted to ask, how did you know that mode must have two further variables as width and height?
I mean these guys:
mode->width
mode->height
In addition to looking at the documentation, you can search the GLFW header in your IDE or by opening it in an editor, for example here I’ve searched for GLFWvidmode
in the online code:
typedef struct GLFWvidmode
{
/*! The width, in screen coordinates, of the video mode.
*/
int width;
/*! The height, in screen coordinates, of the video mode.
*/
int height;
/*! The bit depth of the red channel of the video mode.
*/
int redBits;
/*! The bit depth of the green channel of the video mode.
*/
int greenBits;
/*! The bit depth of the blue channel of the video mode.
*/
int blueBits;
/*! The refresh rate, in Hz, of the video mode.
*/
int refreshRate;
} GLFWvidmode;
Some IDEs (for example Visual Studio, XCode, Eclipse etc.) will allow you to look at the declaration of a struct or function by right clicking on where you use it, and go to it’s declaration to view members etc.
UAs
May 27, 2020, 6:04pm
9
Yeah I did find that after a while, didn’t remove my comment. But anyway you took the initiative for helping. Thank you @dougbinks and @mmozeiko for the 100% helpful reply.