How to center a Window at Screen?

phoenix94 wrote on Wednesday, July 10, 2013:


I tried to create a Window with GLFW an then Center it on the Screen with glfwSetWindowPos().
But unfortunately I’m not able to get the current size of my Desktop Screen, to center my window.
Is there a functino for it, or another way to do it?

Thanks for help. :slight_smile:

elmindreda wrote on Wednesday, July 10, 2013:

You can retrieve the current video mode for your chosen monitor and then figure out where to put the window for it to be centred.

Video mode sizes use screen coordinates, same as window positions and sizes.

phoenix94 wrote on Wednesday, July 10, 2013:

Do you mean the glfwGetVideoMode() function? It doesn’t seem to work.

GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());

causes the following error:

error C2440: ‘initialization’: ‘const GLFWvidmode *’ could not be converted into ‘GLFWvidmode *’

By the way, if it is necessary: I use Windows 7 and C++ Express 2010 :slight_smile:

Edit: OK, I was a little bit stupid. -.-

When I use reinterpret_cast all works well. Thank you for your great help. :smiley:

markspeir wrote on Wednesday, July 10, 2013:

I had the same issue.

Change: GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
to: const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());

phoenix94 wrote on Thursday, July 11, 2013:

Thank you all for your Help. It works fine now.

So I think this is a closed topic now? :smiley: