Added lighting

This commit is contained in:
Matthias Schiffer 2010-04-12 04:42:26 +02:00
parent a4f2d991da
commit d56001cb33
3 changed files with 592 additions and 573 deletions

File diff suppressed because it is too large Load diff

View file

@ -10,7 +10,7 @@ import Data.Fixed
import Data.Ratio
tankWidth :: Micro
tankWidth = 0.95
tankWidth = 0.4
tankLength :: Micro
tankLength = 0.95

View file

@ -25,9 +25,10 @@ import Bindings.GLPng
import Graphics.Rendering.OpenGL.GL (($=), GLfloat, GLdouble, Capability(..), Vector3(..))
import Graphics.Rendering.OpenGL.GL.BeginEnd (unsafeRenderPrimitive, PrimitiveMode(..))
import Graphics.Rendering.OpenGL.GL.CoordTrans (matrixMode, MatrixMode(..), viewport, Position(..), Size(..), loadIdentity, unsafePreservingMatrix, ortho, translate, rotate, scale)
import Graphics.Rendering.OpenGL.GL.CoordTrans
import Graphics.Rendering.OpenGL.GL.Colors
import Graphics.Rendering.OpenGL.GL.Framebuffer (clear, ClearBuffer(..))
import Graphics.Rendering.OpenGL.GL.PerFragment (blend, blendFunc, BlendingFactor(..))
import Graphics.Rendering.OpenGL.GL.PerFragment (blend, blendFunc, BlendingFactor(..), depthFunc, ComparisonFunction(..))
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)
@ -88,9 +89,29 @@ getModel m = do
setup :: Main ()
setup = do
(lw, lh) <- gets (level . gameState) >>= \l -> return (fromIntegral . levelWidth $ l :: GLfloat, fromIntegral . levelHeight $ l :: GLfloat)
liftIO $ do
blend $= Enabled
blendFunc $= (SrcAlpha, OneMinusSrcAlpha)
matrixMode $= Projection
scale 1 1 (0.1 :: GLfloat)
translate $ Vector3 (lw/2) (lh/2) 0
rotate (-30) $ Vector3 1 0 (0 :: GLfloat)
translate $ Vector3 (-lw/2) (-lh/2) 0
matrixMode $= Modelview 0
blend $= Enabled
blendFunc $= (SrcAlpha, OneMinusSrcAlpha)
depthFunc $= Just Lequal
shadeModel $= Smooth
lighting $= Enabled
light (Light 0) $= Enabled
position (Light 0) $= Vertex4 (-1) (-1) 1 (0 :: GLfloat)
colorMaterial $= Just (Front, AmbientAndDiffuse)
clientState VertexArray $= Enabled
clientState NormalArray $= Enabled
clientState TextureCoordArray $= Enabled
-- cache textures & models
getTexture TextureWood
@ -121,11 +142,13 @@ render = do
(lw, lh) <- gets (level . gameState) >>= \l -> return (fromIntegral . levelWidth $ l :: GLfloat, fromIntegral . levelHeight $ l :: GLfloat)
liftIO $ do
clear [ColorBuffer]
clear [ColorBuffer, DepthBuffer]
texture Texture2D $= Enabled
textureBinding Texture2D $= Just textureWood
normal $ Normal3 0 0 (1 :: GLfloat)
unsafeRenderPrimitive Quads $ do
texCoord $ TexCoord2 (0 :: GLfloat) (0 :: GLfloat)
vertex $ Vertex2 0 lh
@ -141,9 +164,6 @@ render = do
texture Texture2D $= Disabled
clientState VertexArray $= Enabled
clientState NormalArray $= Enabled
clientState TextureCoordArray $= Enabled
bindInterleavedArrays modelTank
forM_ tanklist $ \tank -> unsafePreservingMatrix $ do
@ -153,7 +173,6 @@ render = do
rotAim = realToFrac . tankAim $ tank
translate $ Vector3 x y (0 :: GLfloat)
scale 0.1 0.1 (0.1 :: GLfloat)
rotate rotDir $ Vector3 0 0 (1 :: GLfloat)
--textureBinding Texture2D $= Just textureTank
@ -212,16 +231,16 @@ render = do
unsafeRenderPrimitive Quads $ do
texCoord $ TexCoord2 (0 :: GLfloat) (0 :: GLfloat)
vertex $ Vertex2 (-0.1 :: GLfloat) (-0.1 :: GLfloat)
vertex $ Vertex3 (-0.1 :: GLfloat) (-0.1 :: GLfloat) 0.01
texCoord $ TexCoord2 (0 :: GLfloat) (1 :: GLfloat)
vertex $ Vertex2 (-0.1 :: GLfloat) (0.1 :: GLfloat)
vertex $ Vertex3 (-0.1 :: GLfloat) (0.1 :: GLfloat) 0.01
texCoord $ TexCoord2 (1 :: GLfloat) (1 :: GLfloat)
vertex $ Vertex2 (0.1 :: GLfloat) (0.1 :: GLfloat)
vertex $ Vertex3 (0.1 :: GLfloat) (0.1 :: GLfloat) 0.01
texCoord $ TexCoord2 (1 :: GLfloat) (0 :: GLfloat)
vertex $ Vertex2 (0.1 :: GLfloat) (-0.1 :: GLfloat)
vertex $ Vertex3 (0.1 :: GLfloat) (-0.1 :: GLfloat) 0.01
textureBinding Texture2D $= Just textureCrosshair
forM_ playerlist renderPlayer