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