2010-02-23 20:51:30 +01:00
|
|
|
module Render ( setup
|
|
|
|
, resize
|
|
|
|
, render
|
2010-02-23 15:05:31 +01:00
|
|
|
) where
|
|
|
|
|
|
|
|
|
|
|
|
import Game
|
2010-02-25 02:15:26 +01:00
|
|
|
import Level
|
2010-02-23 23:31:11 +01:00
|
|
|
import Tank
|
2010-02-23 15:05:31 +01:00
|
|
|
|
2010-02-25 02:15:26 +01:00
|
|
|
import Bindings.GLPng
|
|
|
|
|
2010-02-23 15:05:31 +01:00
|
|
|
import Control.Monad.State
|
2010-02-23 20:51:30 +01:00
|
|
|
|
2010-02-24 02:42:10 +01:00
|
|
|
import Data.Fixed
|
|
|
|
import Data.Ratio
|
|
|
|
|
2010-02-25 02:15:26 +01:00
|
|
|
import Graphics.Rendering.OpenGL.GL (($=), GLfloat, GLdouble)
|
2010-02-23 20:51:30 +01:00
|
|
|
import Graphics.Rendering.OpenGL.GL.BeginEnd (renderPrimitive, PrimitiveMode(..))
|
|
|
|
import Graphics.Rendering.OpenGL.GL.CoordTrans (matrixMode, MatrixMode(..), viewport, Position(..), Size(..), loadIdentity, ortho)
|
2010-02-23 15:05:31 +01:00
|
|
|
import Graphics.Rendering.OpenGL.GL.Framebuffer (clear, ClearBuffer(..))
|
2010-02-25 02:15:26 +01:00
|
|
|
import Graphics.Rendering.OpenGL.GL.Texturing.Parameters (Repetition(..), Clamping(..), TextureFilter(..), MinificationFilter, MagnificationFilter)
|
2010-02-23 20:51:30 +01:00
|
|
|
import Graphics.Rendering.OpenGL.GL.VertexSpec
|
|
|
|
|
|
|
|
|
2010-02-25 02:15:26 +01:00
|
|
|
setup :: Int -> Int -> Game ()
|
2010-02-23 23:31:11 +01:00
|
|
|
setup w h = do
|
|
|
|
resize w h
|
2010-02-25 02:15:26 +01:00
|
|
|
(tex, info) <- liftIO $ pngBind "tex/Wood.png" NoMipmap Solid (Repeated, Repeat) (Linear', Nothing) Linear'
|
|
|
|
liftIO $ print info
|
|
|
|
|
2010-02-23 23:31:11 +01:00
|
|
|
|
2010-02-25 02:15:26 +01:00
|
|
|
resize :: Int -> Int -> Game ()
|
2010-02-23 20:51:30 +01:00
|
|
|
resize w h = do
|
|
|
|
let wn = fromIntegral w
|
|
|
|
hn = fromIntegral h
|
2010-02-25 02:15:26 +01:00
|
|
|
aspect = fromReal (wn/hn)
|
2010-02-23 20:51:30 +01:00
|
|
|
|
2010-02-25 02:15:26 +01:00
|
|
|
lvl <- gets level
|
|
|
|
let s = max (0.5*(fromIntegral $ levelWidth lvl)/aspect) (0.5*(fromIntegral $ levelHeight lvl)) :: GLdouble
|
2010-02-23 20:51:30 +01:00
|
|
|
|
2010-02-25 02:15:26 +01:00
|
|
|
liftIO $ do
|
|
|
|
matrixMode $= Projection
|
|
|
|
loadIdentity
|
|
|
|
ortho (-s*aspect) (s*aspect) (-s) s (-1) 1
|
|
|
|
|
|
|
|
matrixMode $= Modelview 0
|
|
|
|
|
|
|
|
viewport $= ((Position 0 0), (Size (fromIntegral w) (fromIntegral h)))
|
2010-02-23 15:05:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
render :: Game ()
|
2010-02-23 23:31:11 +01:00
|
|
|
render = do
|
|
|
|
tank <- liftM head $ gets tanks
|
2010-02-25 02:15:26 +01:00
|
|
|
let x = fromReal . posx $ tank
|
|
|
|
y = fromReal . posy $ tank
|
2010-02-23 23:31:11 +01:00
|
|
|
|
|
|
|
liftIO $ do
|
2010-02-23 20:51:30 +01:00
|
|
|
clear [ColorBuffer]
|
|
|
|
|
2010-02-25 02:15:26 +01:00
|
|
|
renderPrimitive Quads $ do
|
2010-02-24 02:42:10 +01:00
|
|
|
vertex $ Vertex2 (x-0.5 :: GLfloat) (y-0.5 :: GLfloat)
|
2010-02-25 02:15:26 +01:00
|
|
|
vertex $ Vertex2 (x-0.5 :: GLfloat) (y+0.5 :: GLfloat)
|
2010-02-23 23:31:11 +01:00
|
|
|
vertex $ Vertex2 (x+0.5 :: GLfloat) (y+0.5 :: GLfloat)
|
|
|
|
vertex $ Vertex2 (x+0.5 :: GLfloat) (y-0.5 :: GLfloat)
|
2010-02-24 02:42:10 +01:00
|
|
|
|
2010-02-25 02:15:26 +01:00
|
|
|
fromReal :: (Real a, Fractional b) => a -> b
|
|
|
|
fromReal = fromRational . toRational
|