diff options
author | Joshua Rahm <joshua.rahm@colorado.edu> | 2014-04-19 13:49:52 -0600 |
---|---|---|
committer | Joshua Rahm <joshua.rahm@colorado.edu> | 2014-04-19 13:49:52 -0600 |
commit | fe5eb547f97cb65d4e792b389a231d4e69e9d519 (patch) | |
tree | 8902589c23a728615c4af0b2961b7b29a8716b03 /Resources.hs | |
parent | a2bfedb319d42650d1919134c440353503538c59 (diff) | |
parent | a2224be33baae7ae07473e74fe94414cdb8f41d2 (diff) | |
download | terralloc-fe5eb547f97cb65d4e792b389a231d4e69e9d519.tar.gz terralloc-fe5eb547f97cb65d4e792b389a231d4e69e9d519.tar.bz2 terralloc-fe5eb547f97cb65d4e792b389a231d4e69e9d519.zip |
refactored drawing routines
Diffstat (limited to 'Resources.hs')
-rw-r--r-- | Resources.hs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/Resources.hs b/Resources.hs index 6754742..e6effb2 100644 --- a/Resources.hs +++ b/Resources.hs @@ -61,11 +61,18 @@ data Resources = Resources { pMatrix :: Mat4 GLfloat, mvMatrix :: Mat4 GLfloat, +<<<<<<< HEAD routines :: [ResourcesClosure -> IO ()], -- object :: GlyphObject (), -- forest :: GlyphObject (), -- jungle :: GlyphObject (), -- waterObj :: GlyphObject (), +======= + object :: GlyphObject (), + forest :: Maybe (GlyphObject ()), + jungle :: Maybe (GlyphObject ()), + waterObj :: GlyphObject (), +>>>>>>> a2224be33baae7ae07473e74fe94414cdb8f41d2 speed :: Int, timeSpeed :: Int, @@ -133,11 +140,17 @@ eventHandle event res = do KeyUp (Keysym SDLK_s _ _) -> return $ setSpeed (speed res + 1) res + KeyUp (Keysym SDLK_g _ _) -> do + SDL.showCursor False + SDL.grabInput True + return res KeyUp (Keysym SDLK_f _ _) -> do ret <- reshape 1920 1080 res SDL.toggleFullscreen $ rSurface ret SDL.showCursor False + SDL.grabInput True return ret + _ -> return res displayHandle :: Resources -> IO Resources @@ -155,6 +168,7 @@ displayHandle resources = do let l_mvMatrix = buildMVMatrix $ cameraPos let normalMatrix = glslModelViewToNormalMatrix l_mvMatrix +<<<<<<< HEAD clearColor $= Color4 0 0 0 0 clear [ColorBuffer, DepthBuffer] SDL.flip $ rSurface resources @@ -169,6 +183,53 @@ displayHandle resources = do (Vec4 globalAmbient) cameraPos in mapM_ (Prelude.$rc) $ routines resources +======= + cullFace $= Just Front + draw $ prepare (object resources) $ \_ -> do + uniform (UniformLocation 5) $= l_mvMatrix + uniform (UniformLocation 4) $= pMatrix resources + uniform (UniformLocation 6) $= l_mvMatrix `glslMatMul` lightPos + uniform (UniformLocation 7) $= normalMatrix + uniform (UniformLocation 8) $= Vec4 (r,g,b,a::GLfloat) + return () + + blend $= Enabled + cullFace $= Just Back + blendFunc $= (GL.SrcAlpha,OneMinusSrcAlpha) + + when (isJust $ forest resources) $ + draw $ prepare (fromJust $ forest resources) $ \_ -> do + uniform (UniformLocation 5) $= l_mvMatrix + uniform (UniformLocation 4) $= pMatrix resources + uniform (UniformLocation 7) $= l_mvMatrix `glslMatMul` lightPos + uniform (UniformLocation 8) $= Index1 (fromIntegral $ time resources::GLfloat) + uniform (UniformLocation 9) $= normalMatrix + + uniform (UniformLocation 10) $= Vec4 (r,g,b,a::GLfloat) + return () + + when (isJust $ jungle resources) $ do + draw $ prepare (fromJust $ jungle resources) $ \_ -> do + uniform (UniformLocation 5) $= l_mvMatrix + uniform (UniformLocation 4) $= pMatrix resources + uniform (UniformLocation 7) $= l_mvMatrix `glslMatMul` lightPos + uniform (UniformLocation 8) $= Index1 (fromIntegral $ time resources::GLfloat) + uniform (UniformLocation 9) $= normalMatrix + + uniform (UniformLocation 10) $= Vec4 (r,g,b,a::GLfloat) + return () + + cullFace $= Nothing + draw $ prepare (waterObj resources) $ \_ -> do + patchVertices SV.$= 4 + uniform (UniformLocation 4) $= pMatrix resources + uniform (UniformLocation 5) $= l_mvMatrix + uniform (UniformLocation 7) $= normalMatrix + uniform (UniformLocation 8) $= l_mvMatrix `glslMatMul` lightPos + uniform (UniformLocation 9) $= Index1 ((fromIntegral $ time resources) / 20::GLfloat) + uniform (UniformLocation 10) $= Vec4 (r,g,b,a::GLfloat) + return () +>>>>>>> a2224be33baae7ae07473e74fe94414cdb8f41d2 SDL.glSwapBuffers return resources @@ -231,6 +292,7 @@ buildTerrainObject builder = do uniform dXlocation $= Index1 (dx::GLfloat) uniform dYlocation $= Index1 (dy::GLfloat) printErrors "terrainObjectClosure" +<<<<<<< HEAD return $ \rc -> do draw $ prepare obj $ \_ -> do cullFace $= Just Front @@ -243,6 +305,13 @@ buildTerrainObject builder = do buildForestObject :: Seq.Seq GLfloat -> String -> String -> IO (ResourcesClosure -> IO ()) buildForestObject seq obj tex = if Seq.null seq then return ((const.return) ()) else do +======= + +buildForestObject :: Seq.Seq GLfloat -> String -> String -> IO (Maybe (GlyphObject ())) +buildForestObject seq obj tex = + if Seq.null seq then return Nothing else liftM Just $ + do +>>>>>>> a2224be33baae7ae07473e74fe94414cdb8f41d2 let bufferIO :: IO BufferObject bufferIO = (newArray . Fold.toList) seq >>= ptrToBuffer ArrayBuffer (Seq.length seq * 4) |