forked from haskell-game/dear-imgui.hs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hs
67 lines (50 loc) · 1.36 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import DearImGui
import Control.Exception
import Graphics.GL
import SDL
main :: IO ()
main = do
initializeAll
bracket (createWindow "Hello, Dear ImGui!" defaultWindow { windowGraphicsContext = OpenGLContext defaultOpenGL }) destroyWindow \w ->
bracket (glCreateContext w) glDeleteContext \glContext ->
bracket createContext destroyContext \_imguiContext ->
bracket_ (sdl2InitForOpenGL w glContext) sdl2Shutdown $
bracket_ openGL2Init openGL2Shutdown do
checkVersion
styleColorsLight
openGL2Init
loop w
openGL2Shutdown
loop :: Window -> IO ()
loop w = do
ev <- pollEventWithImGui
openGL2NewFrame
sdl2NewFrame w
newFrame
-- showDemoWindow
-- showMetricsWindow
-- showAboutWindow
-- showUserGuide
begin "My Window"
text "Hello!"
button "Click me" >>= \case
True -> putStrLn "Oh hi Mark"
False -> return ()
smallButton "Click me" >>= \case
True -> putStrLn "Oh hi Mark"
False -> return ()
end
render
glClear GL_COLOR_BUFFER_BIT
openGL2RenderDrawData =<< getDrawData
glSwapWindow w
case ev of
Nothing -> loop w
Just Event{ eventPayload } -> case eventPayload of
QuitEvent -> return ()
_ -> loop w