diff options
Diffstat (limited to 'Render.hs')
-rw-r--r-- | Render.hs | 49 |
1 files changed, 24 insertions, 25 deletions
@@ -20,7 +20,7 @@ import Bindings.GLPng import Graphics.Rendering.OpenGL.GL (($=), GLfloat, GLdouble, Capability(..), Vector3(..)) import Graphics.Rendering.OpenGL.GL.BeginEnd (renderPrimitive, PrimitiveMode(..)) -import Graphics.Rendering.OpenGL.GL.CoordTrans (matrixMode, MatrixMode(..), viewport, Position(..), Size(..), loadIdentity, ortho, translate, rotate) +import Graphics.Rendering.OpenGL.GL.CoordTrans (matrixMode, MatrixMode(..), viewport, Position(..), Size(..), loadIdentity, preservingMatrix, ortho, translate, rotate) import Graphics.Rendering.OpenGL.GL.Framebuffer (clear, ClearBuffer(..)) import Graphics.Rendering.OpenGL.GL.PerFragment (blend, blendFunc, BlendingFactor(..)) import Graphics.Rendering.OpenGL.GL.Texturing.Application (texture) @@ -83,19 +83,15 @@ resize w h = do render :: Game () render = do - tank <- liftM head $ gets tanks - let x = fromReal . posx $ tank - y = fromReal . posy $ tank - (lw, lh) <- gets level >>= \l -> return (fromIntegral . levelWidth $ l :: GLfloat, fromIntegral . levelHeight $ l :: GLfloat) - + tanklist <- gets tanks textureWood <- getTexture TextureWood textureTank <- getTexture TextureTank + (lw, lh) <- gets level >>= \l -> return (fromIntegral . levelWidth $ l :: GLfloat, fromIntegral . levelHeight $ l :: GLfloat) + liftIO $ do clear [ColorBuffer] - loadIdentity - texture Texture2D $= Enabled textureBinding Texture2D $= Just textureWood @@ -111,25 +107,28 @@ render = do texCoord $ TexCoord2 lh (0 :: GLfloat) vertex $ Vertex2 (0.5*lw) (-0.5*lh) - - + textureBinding Texture2D $= Just textureTank - translate $ Vector3 x y (0 :: GLfloat) - rotate (90 + (fromReal . dir $ tank)) $ Vector3 0 0 (1 :: GLfloat) - - renderPrimitive Quads $ do - texCoord $ TexCoord2 (0 :: GLfloat) (0 :: GLfloat) - vertex $ Vertex2 (-0.5 :: GLfloat) (-0.5 :: GLfloat) - - texCoord $ TexCoord2 (0 :: GLfloat) (1 :: GLfloat) - vertex $ Vertex2 (-0.5 :: GLfloat) (0.5 :: GLfloat) - - texCoord $ TexCoord2 (1 :: GLfloat) (1 :: GLfloat) - vertex $ Vertex2 (0.5 :: GLfloat) (0.5 :: GLfloat) - - texCoord $ TexCoord2 (1 :: GLfloat) (0 :: GLfloat) - vertex $ Vertex2 (0.5 :: GLfloat) (-0.5 :: GLfloat) + forM_ tanklist $ \tank -> preservingMatrix $ do + let x = fromReal . posx $ tank + y = fromReal . posy $ tank + + translate $ Vector3 x y (0 :: GLfloat) + rotate (90 + (fromReal . dir $ tank)) $ Vector3 0 0 (1 :: GLfloat) + + renderPrimitive Quads $ do + texCoord $ TexCoord2 (0 :: GLfloat) (0 :: GLfloat) + vertex $ Vertex2 (-0.5 :: GLfloat) (-0.5 :: GLfloat) + + texCoord $ TexCoord2 (0 :: GLfloat) (1 :: GLfloat) + vertex $ Vertex2 (-0.5 :: GLfloat) (0.5 :: GLfloat) + + texCoord $ TexCoord2 (1 :: GLfloat) (1 :: GLfloat) + vertex $ Vertex2 (0.5 :: GLfloat) (0.5 :: GLfloat) + + texCoord $ TexCoord2 (1 :: GLfloat) (0 :: GLfloat) + vertex $ Vertex2 (0.5 :: GLfloat) (-0.5 :: GLfloat) fromReal :: (Real a, Fractional b) => a -> b fromReal = fromRational . toRational
\ No newline at end of file |