Added lighting
This commit is contained in:
parent
a4f2d991da
commit
d56001cb33
3 changed files with 592 additions and 573 deletions
1118
model/tank.obj
1118
model/tank.obj
File diff suppressed because it is too large
Load diff
|
@ -10,7 +10,7 @@ import Data.Fixed
|
||||||
import Data.Ratio
|
import Data.Ratio
|
||||||
|
|
||||||
tankWidth :: Micro
|
tankWidth :: Micro
|
||||||
tankWidth = 0.95
|
tankWidth = 0.4
|
||||||
|
|
||||||
tankLength :: Micro
|
tankLength :: Micro
|
||||||
tankLength = 0.95
|
tankLength = 0.95
|
||||||
|
|
|
@ -25,9 +25,10 @@ import Bindings.GLPng
|
||||||
|
|
||||||
import Graphics.Rendering.OpenGL.GL (($=), GLfloat, GLdouble, Capability(..), Vector3(..))
|
import Graphics.Rendering.OpenGL.GL (($=), GLfloat, GLdouble, Capability(..), Vector3(..))
|
||||||
import Graphics.Rendering.OpenGL.GL.BeginEnd (unsafeRenderPrimitive, PrimitiveMode(..))
|
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.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.Application (texture)
|
||||||
import Graphics.Rendering.OpenGL.GL.Texturing.Objects (textureBinding, TextureObject(..))
|
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.Parameters (Repetition(..), Clamping(..), TextureFilter(..), MinificationFilter, MagnificationFilter)
|
||||||
|
@ -88,9 +89,29 @@ getModel m = do
|
||||||
|
|
||||||
setup :: Main ()
|
setup :: Main ()
|
||||||
setup = do
|
setup = do
|
||||||
|
(lw, lh) <- gets (level . gameState) >>= \l -> return (fromIntegral . levelWidth $ l :: GLfloat, fromIntegral . levelHeight $ l :: GLfloat)
|
||||||
|
|
||||||
liftIO $ do
|
liftIO $ do
|
||||||
blend $= Enabled
|
matrixMode $= Projection
|
||||||
blendFunc $= (SrcAlpha, OneMinusSrcAlpha)
|
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
|
-- cache textures & models
|
||||||
getTexture TextureWood
|
getTexture TextureWood
|
||||||
|
@ -121,11 +142,13 @@ render = do
|
||||||
(lw, lh) <- gets (level . gameState) >>= \l -> return (fromIntegral . levelWidth $ l :: GLfloat, fromIntegral . levelHeight $ l :: GLfloat)
|
(lw, lh) <- gets (level . gameState) >>= \l -> return (fromIntegral . levelWidth $ l :: GLfloat, fromIntegral . levelHeight $ l :: GLfloat)
|
||||||
|
|
||||||
liftIO $ do
|
liftIO $ do
|
||||||
clear [ColorBuffer]
|
clear [ColorBuffer, DepthBuffer]
|
||||||
|
|
||||||
texture Texture2D $= Enabled
|
texture Texture2D $= Enabled
|
||||||
textureBinding Texture2D $= Just textureWood
|
textureBinding Texture2D $= Just textureWood
|
||||||
|
|
||||||
|
normal $ Normal3 0 0 (1 :: GLfloat)
|
||||||
|
|
||||||
unsafeRenderPrimitive Quads $ do
|
unsafeRenderPrimitive Quads $ do
|
||||||
texCoord $ TexCoord2 (0 :: GLfloat) (0 :: GLfloat)
|
texCoord $ TexCoord2 (0 :: GLfloat) (0 :: GLfloat)
|
||||||
vertex $ Vertex2 0 lh
|
vertex $ Vertex2 0 lh
|
||||||
|
@ -141,9 +164,6 @@ render = do
|
||||||
|
|
||||||
texture Texture2D $= Disabled
|
texture Texture2D $= Disabled
|
||||||
|
|
||||||
clientState VertexArray $= Enabled
|
|
||||||
clientState NormalArray $= Enabled
|
|
||||||
clientState TextureCoordArray $= Enabled
|
|
||||||
bindInterleavedArrays modelTank
|
bindInterleavedArrays modelTank
|
||||||
|
|
||||||
forM_ tanklist $ \tank -> unsafePreservingMatrix $ do
|
forM_ tanklist $ \tank -> unsafePreservingMatrix $ do
|
||||||
|
@ -153,7 +173,6 @@ render = do
|
||||||
rotAim = realToFrac . tankAim $ tank
|
rotAim = realToFrac . tankAim $ tank
|
||||||
|
|
||||||
translate $ Vector3 x y (0 :: GLfloat)
|
translate $ Vector3 x y (0 :: GLfloat)
|
||||||
scale 0.1 0.1 (0.1 :: GLfloat)
|
|
||||||
rotate rotDir $ Vector3 0 0 (1 :: GLfloat)
|
rotate rotDir $ Vector3 0 0 (1 :: GLfloat)
|
||||||
|
|
||||||
--textureBinding Texture2D $= Just textureTank
|
--textureBinding Texture2D $= Just textureTank
|
||||||
|
@ -212,16 +231,16 @@ render = do
|
||||||
|
|
||||||
unsafeRenderPrimitive Quads $ do
|
unsafeRenderPrimitive Quads $ do
|
||||||
texCoord $ TexCoord2 (0 :: GLfloat) (0 :: GLfloat)
|
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)
|
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)
|
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)
|
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
|
textureBinding Texture2D $= Just textureCrosshair
|
||||||
forM_ playerlist renderPlayer
|
forM_ playerlist renderPlayer
|
||||||
|
|
Reference in a new issue