Last active
November 20, 2020 22:26
-
-
Save prozacchiwawa/8c920bca3ae8697f03a80e90d1cee842 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module GLFW | |
-- https://gist.github.com/alrunner4/8a026f3bfea354b48d3294a20c9812e2 | |
export data Monitor : Type where {} | |
export data Window : Type where {} | |
%foreign "C:glfwInit,libglfw" | |
Init: PrimIO Int | |
%foreign "C:glfwCreateWindow,libglfw" | |
CreateWindow: Int -> Int -> String -> Ptr Monitor -> Ptr Window -> PrimIO( Ptr Window ) | |
%foreign "C:glfwWindowShouldClose,libglfw" | |
WindowShouldClose: Ptr Window -> PrimIO Int | |
%foreign "C:glfwPollEvents,libglfw" | |
PollEvents: PrimIO () | |
pollingLoop: Ptr Window -> IO () | |
pollingLoop w = | |
do | |
wsc <- primIO (WindowShouldClose w) | |
continueOrEndPolling wsc | |
where | |
continueOrEndPolling : Int -> IO () | |
continueOrEndPolling wsc = | |
if wsc /= 0 | |
then pure () | |
else primIO PollEvents >> pollingLoop w | |
main: IO () | |
main = if !( primIO Init ) /= 1 | |
then printLn "Init failed" | |
else do | |
putStrLn "Creating window..." | |
w <- primIO( CreateWindow 1920 1080 "glfw" | |
( prim__castPtr prim__getNullAnyPtr ) | |
( prim__castPtr prim__getNullAnyPtr ) ) | |
putStrLn "Polling events..." | |
pollingLoop w | |
putStrLn "Shutting down..." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment