-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLesson02.hs
67 lines (58 loc) · 1.96 KB
/
Lesson02.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
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
translate $ Vector3 (-1.5) 0 ((-6)::GLfloat)
renderPrimitive Triangles $ do
vertex $ Vertex3 0 1 (0::GLfloat)
vertex $ Vertex3 (-1) (-1) (0::GLfloat)
vertex $ Vertex3 1 (-1) (0::GLfloat)
translate $ Vector3 3 0 (0::GLfloat)
renderPrimitive Quads $ do
vertex $ Vertex3 (-1) 1 (0::GLfloat)
vertex $ Vertex3 1 1 (0::GLfloat)
vertex $ Vertex3 1 (-1) (0::GLfloat)
vertex $ Vertex3 (-1) (-1) (0::GLfloat)
swapBuffers