haskellheightwidthscreengloss

function for getting window width and height with haskell gloss


Is there a function, similar to JS screen.width and screen.height in Haskell with the gloss graphic library, which returns the screen width and height?


Solution

  • I don't think gloss itself exports this capability, but you can use these calls from the GLFW package to determine the screen resolution:

    import Graphics.UI.GLFW
    
    main = do
      initialize
      desktopMode >>= print
      putStrLn "all video modes:"
      videoModes >>= mapM_ print
    

    Note that gloss may be compiled to use either GLUT or GLFW. If gloss uses GLFW as its interface to Open GL it will call GLFW's initialize function when you create a window, and it's possible there is an issue with calling initialize twice in the same process but I kinda doubt it.

    You can then use these dimensions to set the drawable area when creating a gloss window with the FullScreen constructor.