init
This commit is contained in:
77
src/Main.hs
Normal file
77
src/Main.hs
Normal file
@@ -0,0 +1,77 @@
|
||||
module Main (main) where
|
||||
|
||||
-- IMPORTS --
|
||||
|
||||
import Graphics.Rendering.OpenGL as GL
|
||||
import Graphics.UI.GLFW as GLFW
|
||||
import Control.Monad (forever)
|
||||
import System.Exit (exitSuccess)
|
||||
|
||||
-- MAIN --
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
putStrLn "haskengl 2025 Andromeda; WTFPL"
|
||||
window <- openWindow "window :)"
|
||||
onPaint window
|
||||
closeWindow window
|
||||
return ()
|
||||
|
||||
-- EVENTS --
|
||||
|
||||
keyPressed :: GLFW.KeyCallback
|
||||
keyPressed window GLFW.Key'Escape _ GLFW.KeyState'Pressed _ = shutdownWindow window
|
||||
keyPressed _ _ _ _ _ = return ()
|
||||
|
||||
-- PAINT --
|
||||
|
||||
onPaint :: GLFW.Window -> IO ()
|
||||
onPaint window =
|
||||
do
|
||||
GL.clearColor $= Color4 1 0 1 1
|
||||
GL.clear [ColorBuffer]
|
||||
GLFW.swapBuffers window
|
||||
forever $ do
|
||||
GLFW.pollEvents
|
||||
onPaint window
|
||||
|
||||
-- WINDOW --
|
||||
|
||||
openWindow :: String -> IO GLFW.Window
|
||||
openWindow
|
||||
title
|
||||
= do
|
||||
GLFW.init
|
||||
GLFW.defaultWindowHints
|
||||
GLFW.windowHint (GLFW.WindowHint'ContextVersionMajor 4)
|
||||
GLFW.windowHint (GLFW.WindowHint'ContextVersionMinor 5)
|
||||
GLFW.windowHint (GLFW.WindowHint'OpenGLProfile GLFW.OpenGLProfile'Core)
|
||||
monitor <- GLFW.getPrimaryMonitor
|
||||
Just window <- GLFW.createWindow 256 256 title monitor Nothing -- get an error n ur cooked. TODO graceful failure here
|
||||
GLFW.makeContextCurrent (Just window)
|
||||
GLFW.maximizeWindow window
|
||||
GLFW.setWindowCloseCallback window (Just shutdownWindow)
|
||||
GLFW.setWindowSizeCallback window (Just resizeWindow)
|
||||
GLFW.setKeyCallback window (Just keyPressed)
|
||||
return window
|
||||
|
||||
shutdownWindow :: GLFW.WindowCloseCallback
|
||||
shutdownWindow window =
|
||||
do
|
||||
closeWindow window
|
||||
_ <- exitSuccess
|
||||
return ()
|
||||
|
||||
resizeWindow :: GLFW.WindowSizeCallback
|
||||
resizeWindow _ w h =
|
||||
do
|
||||
GL.viewport $= (GL.Position 0 0, GL.Size (fromIntegral w) (fromIntegral h))
|
||||
GL.matrixMode $= GL.Projection
|
||||
GL.loadIdentity
|
||||
GL.ortho2D 0 (realToFrac w) (realToFrac h) 0
|
||||
|
||||
closeWindow :: GLFW.Window -> IO ()
|
||||
closeWindow window =
|
||||
do
|
||||
GLFW.destroyWindow window
|
||||
GLFW.terminate
|
||||
Reference in New Issue
Block a user