topkata-0.2.4: Topkata/Render.hs
module Topkata.Render (render, mkRenderInfo, renderInit) where
import Graphics.Rendering.OpenGL
import Topkata.Textures
import Topkata.State ( State(..) )
import Topkata.Topka.Topka (topView, genTopkataCallList,
showTopkata)
import qualified Labygen.Render
data RenderInfo = RenderInfo {
renderInfoLabyDL :: !DisplayList
,renderInfoTopkata :: !GLuint
}
hit = False
whereToLook state =
let (x, y, z, phi) = topView $ stTopka state in
(x, 3, z-2, 0)
render renderInfo state = do
matrixMode $= Projection
depthRange $= (0.5, 20)
loadIdentity
--hit <- return False -- get (showHit state)
frustum (-0.2) 0.5 (-0.2) (0.5) (0.5) (if hit then 0.5 else 20)
matrixMode $= Modelview 0
loadIdentity
let (x, y, z, phi) = whereToLook state
--lookAt (Vertex3 x y z) (Vertex3 (x+1) (0.5) (z+2*cos phi)) (Vector3 0 1 0)
lookAt (Vertex3 x y z) (Vertex3 (x+2*sin phi) (0.5) (z+2*cos phi)) (Vector3 0 1 0)
clear [ ColorBuffer, DepthBuffer ]
preservingMatrix $ callList $ renderInfoLabyDL renderInfo
let ts = stTopka state
showTopkata ts $ renderInfoTopkata renderInfo
mkRenderInfo state = do
brickTex <- loadBrickTex
labyDL <- defineNewList Compile $ Labygen.Render.render brickTex laby
topTex <- loadEyes "eyes"
ghostTex <- loadEyes "geyes"
tops <- genTopkataCallList topTex ghostTex
return $ RenderInfo {
renderInfoLabyDL = labyDL
,renderInfoTopkata = tops
}
where
laby = stLaby state
renderInit :: IO ()
renderInit = do
clearColor $= Color4 0 0 0 0
polygonMode $= (Fill, Fill)
shadeModel $= Smooth
materialSpecular FrontAndBack $= Color4 1 1 1 1
materialShininess FrontAndBack $= 25
colorMaterial $= Just (FrontAndBack, Diffuse)
position (Light 1) $= Vertex4 0 0.5 (-0.5) 1
position (Light 0) $= Vertex4 1 2 (-8) 0
lighting $= Enabled
light (Light 0) $= Enabled
light (Light 1) $= Enabled
depthFunc $= Just Less
ambient (Light 0) $= Color4 0.2 0.2 0.2 1.0
diffuse (Light 0) $= Color4 1 1 1 1
diffuse (Light 1) $= Color4 1 1 1 1
specular (Light 1) $= Color4 1 1 1 1
--position (Light 0) $= Vertex4 0 3 2 0
lightModelAmbient $= Color4 0.4 0.4 0.4 1
lightModelLocalViewer $= Enabled
lightModelTwoSide $= Enabled
-- blend $= Enabled
-- blendFunc $= (SrcAlpha, OneMinusSrcAlpha)
-- hint PolygonSmooth $= Nicest
--polygonSmooth $= Enabled
-- hint LineSmooth $= Nicest
-- lineSmooth $= Enabled
normalize $= Enabled