Does GLFW get screen height / width?

After playing with OpenGL for a while using the freeglut library, I decided that instead I would use GLFW for my next training project, as I was told that GLUT is for educational purposes only and should not be used professionally. I had no problems linking lib with my NetBeans project and it compiles just fine using mingw32 4.6.2.

However, I am having difficulty trying to position the window in the center of the screen. In the freeglut area, I previously used:

glutInitWindowPosition ( (glutGet(GLUT_SCREEN_WIDTH)-RES_X) / 2, (glutGet(GLUT_SCREEN_HEIGHT)-RES_Y) / 2 ); 

I can not find any glfw function that will return the size or width of the screen. Is such a function simply not implemented?

+8
c ++ opengl glfw
source share
4 answers

What about glfwGetDesktopMode , I think this is what you want.

Example:

 GLFWvidmode return_struct; glfwGetDesktopMode( &return_struct ); int height = return_struct.Height; 
+8
source share

you will first need two variables to store your width and height.

 int width, height; 

as described on page 14 of the manual.

 glfwSetWindowPos(width / 2, height / 2); 

and as a bonus you can call

 glfwGetWindowSize(&width, &height); 

this function is void and does not return any value, however it will update the two previously declared variables .. so put it in mainloop or in a window to change the callback function.

this can be checked in the official manual here on page 15.

+4
source share

It might help someone ...

 void Window::CenterTheWindow(){ GLFWmonitor* monitor = glfwGetPrimaryMonitor(); const GLFWvidmode* mode = glfwGetVideoMode(monitor); glfwSetWindowPos(m_Window, (mode->width - m_Width) / 2, (mode->height - m_Height) / 2); } 

m_Width and m_Height are variables that have the width and height of the window.

Link: http://www.glfw.org/docs/latest/monitor.html

+2
source share
 // Settings int SCR_WIDTH = 800; int SCR_HEIGHT = 600; char TITLE[] = "Stack Overflow"; /*..Initilized..*/ const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); GLFWwindow* window = glfwCreateWindow(SCR_WIDTH,SCR_HEIGHT,TITLE,nullptr,nullptr); // Because (x,y) starts from the top left corner, We got to subtract our window size. glfwSetWindowPos(window,(mode->width-SCR_WIDTH)/2,(mode->height-SCR_HEIGHT)/2); //divided by two to center. 
0
source share

All Articles