How to center a Window at Screen?

Using GLFW
  • phoeniX

    phoeniX - 2013-07-10


    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. :)

  • Camilla Löwy

    Camilla Löwy - 2013-07-10

    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.

    • phoeniX

      phoeniX - 2013-07-10

      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 :)

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

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

      Last edit: phoeniX 2013-07-10
      • Mark Speir

        Mark Speir - 2013-07-10

        I had the same issue.

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

        Last edit: Mark Speir 2013-07-10
  • phoeniX

    phoeniX - 2013-07-11

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

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


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks