summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2010-02-25 03:48:17 +0100
committerMatthias Schiffer <matthias@gamezock.de>2010-02-25 03:48:17 +0100
commit656b5e8bc14b7abda8a836f8eeb3b0a972f0484a (patch)
tree4b19f889e5ce498d2bdf2efcc17fa9f7161619a4
parentc23e63e66786410f53b9460a6456b7c893d2a234 (diff)
downloadhtanks-656b5e8bc14b7abda8a836f8eeb3b0a972f0484a.tar
htanks-656b5e8bc14b7abda8a836f8eeb3b0a972f0484a.zip
Render floor
-rw-r--r--Render.hs45
1 files changed, 39 insertions, 6 deletions
diff --git a/Render.hs b/Render.hs
index cee9e6c..b72324c 100644
--- a/Render.hs
+++ b/Render.hs
@@ -18,12 +18,14 @@ import qualified Data.Map as M
import Bindings.GLPng
-import Graphics.Rendering.OpenGL.GL (($=), GLfloat, GLdouble)
+import Graphics.Rendering.OpenGL.GL (($=), GLfloat, GLdouble, Capability(..))
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.Objects (TextureObject(..))
+import Graphics.Rendering.OpenGL.GL.Texturing.Application (texture)
+import Graphics.Rendering.OpenGL.GL.Texturing.Objects (textureBinding, TextureObject(..))
import Graphics.Rendering.OpenGL.GL.Texturing.Parameters (Repetition(..), Clamping(..), TextureFilter(..), MinificationFilter, MagnificationFilter)
+import Graphics.Rendering.OpenGL.GL.Texturing.Specification (TextureTarget(..))
import Graphics.Rendering.OpenGL.GL.VertexSpec
@@ -78,15 +80,46 @@ 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)
+
+ textureWood <- getTexture TextureWood
liftIO $ do
clear [ColorBuffer]
+ loadIdentity
+
+ texture Texture2D $= Enabled
+ textureBinding Texture2D $= Just textureWood
+
+ renderPrimitive Quads $ do
+ texCoord $ TexCoord2 (0 :: GLfloat) (0 :: GLfloat)
+ vertex $ Vertex2 (-0.5*lw) (-0.5*lh)
+
+ texCoord $ TexCoord2 0 lw
+ vertex $ Vertex2 (-0.5*lw) (0.5*lh)
+
+ texCoord $ TexCoord2 lh lw
+ vertex $ Vertex2 (0.5*lw) (0.5*lh)
+
+ texCoord $ TexCoord2 lh (0 :: GLfloat)
+ vertex $ Vertex2 (0.5*lw) (-0.5*lh)
+
+
+ texture Texture2D $= Disabled
+
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)
+ texCoord $ TexCoord2 (0 :: GLfloat) (0 :: GLfloat)
+ vertex $ Vertex2 (x-0.5 :: GLfloat) (y-0.5 :: GLfloat)
+
+ texCoord $ TexCoord2 (0 :: GLfloat) (1 :: GLfloat)
+ vertex $ Vertex2 (x-0.5 :: GLfloat) (y+0.5 :: GLfloat)
+
+ texCoord $ TexCoord2 (1 :: GLfloat) (1 :: GLfloat)
+ vertex $ Vertex2 (x+0.5 :: GLfloat) (y+0.5 :: GLfloat)
+
+ texCoord $ TexCoord2 (1 :: GLfloat) (0 :: GLfloat)
+ vertex $ Vertex2 (x+0.5 :: GLfloat) (y-0.5 :: GLfloat)
fromReal :: (Real a, Fractional b) => a -> b
fromReal = fromRational . toRational \ No newline at end of file