-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLesson01.hs
53 lines (47 loc) · 1.49 KB
/
Lesson01.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
module Main where
import Graphics.UI.GLUT
import Graphics.Rendering.OpenGL
import Control.Concurrent (threadDelay)
import Data.Maybe (fromJust)
main = do
(progname, _) <- getArgsAndInitialize
initialDisplayMode $= [ SingleBuffered, RGBMode
, WithAlphaComponent, WithDepthBuffer]
initialWindowSize $= Size 640 480
initialWindowPosition $= Position 0 0
createWindow "Nehe's GL Tutorial in Haskell"
displayCallback $= drawGLScene
fullScreen
idleCallback $= Just drawGLScene
reshapeCallback $= Just resizeGLScene
keyboardMouseCallback $= Just keyPressed
initGL $ Size 640 480
mainLoop
initGL size@(Size w h) = do
clearColor $= Color4 0 0 0 0
clearDepth $= 1
depthFunc $= Just Less
shadeModel $= Smooth
matrixMode $= Projection
loadIdentity
let h' = if h == 0 then 1 else h
perspective 45 (fromIntegral w / fromIntegral h') 0.1 100
matrixMode $= Modelview 0
resizeGLScene size@(Size w h) = do
viewport $= (Position 0 0, size)
matrixMode $= Projection
loadIdentity
let h' = if h == 0 then 1 else h
perspective 45 (fromIntegral w / fromIntegral h') 0.1 100
matrixMode $= Modelview 0
keyPressed key keyState modifiers position = do
threadDelay 100
case key of
Char '\ESC' -> do
window <- fmap fromJust $ get currentWindow
destroyWindow window
_ -> return ()
drawGLScene = do
clear [ColorBuffer, DepthBuffer]
loadIdentity
swapBuffers