diff options
Diffstat (limited to 'Render.hs')
-rw-r--r-- | Render.hs | 42 |
1 files changed, 27 insertions, 15 deletions
@@ -5,52 +5,64 @@ module Render ( setup import Game +import Level import Tank +import Bindings.GLPng + import Control.Monad.State import Data.Fixed import Data.Ratio -import Graphics.Rendering.OpenGL.GL (($=), GLfloat) +import Graphics.Rendering.OpenGL.GL (($=), GLfloat, GLdouble) 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.Texturing.Parameters (Repetition(..), Clamping(..), TextureFilter(..), MinificationFilter, MagnificationFilter) import Graphics.Rendering.OpenGL.GL.VertexSpec -setup :: Int -> Int -> IO () +setup :: Int -> Int -> Game () setup w h = do resize w h + (tex, info) <- liftIO $ pngBind "tex/Wood.png" NoMipmap Solid (Repeated, Repeat) (Linear', Nothing) Linear' + liftIO $ print info + -resize :: Int -> Int -> IO () +resize :: Int -> Int -> Game () resize w h = do let wn = fromIntegral w hn = fromIntegral h - aspect = wn/hn + aspect = fromReal (wn/hn) - matrixMode $= Projection - loadIdentity - ortho (-aspect) (aspect) (-1) 1 (-1) 1 + lvl <- gets level + let s = max (0.5*(fromIntegral $ levelWidth lvl)/aspect) (0.5*(fromIntegral $ levelHeight lvl)) :: GLdouble - matrixMode $= Modelview 0 - - viewport $= ((Position 0 0), (Size (fromIntegral w) (fromIntegral h))) + 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))) render :: Game () render = do tank <- liftM head $ gets tanks - let x = toFloat . posx $ tank - y = toFloat . posy $ tank + let x = fromReal . posx $ tank + y = fromReal . posy $ tank liftIO $ do clear [ColorBuffer] - renderPrimitive Triangles $ do + renderPrimitive Quads $ do vertex $ Vertex2 (x-0.5 :: GLfloat) (y-0.5 :: GLfloat) + vertex $ Vertex2 (x-0.5 :: GLfloat) (y+0.5 :: GLfloat) vertex $ Vertex2 (x+0.5 :: GLfloat) (y+0.5 :: GLfloat) vertex $ Vertex2 (x+0.5 :: GLfloat) (y-0.5 :: GLfloat) -toFloat :: Real a => a -> GLfloat -toFloat = fromRational . toRational
\ No newline at end of file +fromReal :: (Real a, Fractional b) => a -> b +fromReal = fromRational . toRational
\ No newline at end of file |