1

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?

Max K
  • 171
  • 12

2 Answers2

8

There is the function is in Graphics.Gloss.Interface.Environment called getScreenSize it return a IO (Int,Int) the first value is width, the second is height.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
3

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.

ErikR
  • 51,541
  • 9
  • 73
  • 124