summaryrefslogtreecommitdiffstats
path: root/Render.hs
blob: 86a7ccf513ac4cc51324969c4e008e088f5bf823 (plain)
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
module Render ( setup
              , resize
              , render
              ) where


import Game

import Control.Monad.State

import Graphics.Rendering.OpenGL.GL (($=), GLfloat)
import Graphics.Rendering.OpenGL.GL.BeginEnd (renderPrimitive, PrimitiveMode(..))
import Graphics.Rendering.OpenGL.GL.CoordTrans (matrixMode, MatrixMode(..), viewport, Position(..), Size(..), loadIdentity, ortho)
import Graphics.Rendering.OpenGL.GL.Framebuffer (clear, ClearBuffer(..))
import Graphics.Rendering.OpenGL.GL.VertexSpec


setup :: Int -> Int -> IO ()
setup = resize
  
resize :: Int -> Int -> IO ()
resize w h = do
  let wn = fromIntegral w
      hn = fromIntegral h
      aspect = wn/hn
  
  matrixMode $= Projection
  loadIdentity
  ortho (-aspect) (aspect) (-1) 1 (-1) 1
  
  matrixMode $= Modelview 0
  
  viewport $= ((Position 0 0), (Size (fromIntegral w) (fromIntegral h)))


render :: Game ()
render = liftIO $ do
           clear [ColorBuffer]
           
           renderPrimitive Triangles $ do
                    vertex $ Vertex2 (-0.5 :: GLfloat) (0.5 :: GLfloat)
                    vertex $ Vertex2 (0.5 :: GLfloat) (0.5 :: GLfloat)
                    vertex $ Vertex2 (0.5 :: GLfloat) (-0.5 :: GLfloat)