Advertisement
Guest User

Untitled

a guest
May 26th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. -- | Initializes a window based on the cell counts and cell sizes, storing the
  2. -- window into the state. The window's context will be bound as the current ogl
  3. -- context, and the viewport will be sized to the window's framebuffer. If we
  4. -- can't create a window the program dies. If we create a window but it's not
  5. -- the size we expect then a warning is printed but we proceed anyway.
  6. initWindow :: Hexes ()
  7. initWindow = do
  8. (rows,cols) <- getRowColCount
  9. (cWidth, cHeight) <- getCellWidthHeight
  10. let fbWidth = cols * cWidth
  11. fbHeight = rows * cHeight
  12. mWin <- liftIO $ GLFW.createWindow fbWidth fbHeight "" Nothing Nothing
  13. window <- liftIO $ case mWin of
  14. Nothing -> error "FATAL: Could Not Create A Window!" -- FIXME a real exception
  15. Just window -> return window
  16. Hexes $ modify (\s -> s {window = window})
  17. liftIO $ GLFW.makeContextCurrent (Just window)
  18. (fbx,fby) <- liftIO $ GLFW.getFramebufferSize window
  19. when ((fbx,fby) /= (fbWidth,fbHeight)) (liftIO $ do
  20. putStrLn $ "WARNING: Framebuffer obtained was the incorrect size."
  21. putStrLn $ "WARNING: Requested: " ++ show (fbWidth,fbHeight) ++ ", Actual:" ++ show (fbx,fby))
  22. glViewport 0 0 (fromIntegral fbx) (fromIntegral fby)
  23. glClearColor 0.2 0.3 0.3 1.0
  24. -- TODO: Add a framebuffer size change callback to keep our viewport correct?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement