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 | |
parent | a2bfedb319d42650d1919134c440353503538c59 (diff) | |
parent | a2224be33baae7ae07473e74fe94414cdb8f41d2 (diff) | |
download | terralloc-fe5eb547f97cb65d4e792b389a231d4e69e9d519.tar.gz terralloc-fe5eb547f97cb65d4e792b389a231d4e69e9d519.tar.bz2 terralloc-fe5eb547f97cb65d4e792b389a231d4e69e9d519.zip |
refactored drawing routines
-rw-r--r-- | Final.hs | 1 | ||||
-rw-r--r-- | Resources.hs | 69 | ||||
-rw-r--r-- | maps/spain_terrain.png | bin | 4870 -> 4464 bytes | |||
-rw-r--r-- | maps/svalbard_height.png | bin | 0 -> 2908 bytes | |||
-rw-r--r-- | maps/svalbard_terrain.png | bin | 0 -> 1862 bytes |
5 files changed, 70 insertions, 0 deletions
@@ -288,6 +288,7 @@ main = do let !forestLocations = runMonadPlusBuilder $ createLocations arr stgen 7 Forest let !jungleLocations = runMonadPlusBuilder $ createLocations arr stgen2 2 Jungle + putStrLn $ "Jungle locations: " ++! jungleLocations water <- getWaterQuads arr coloredArr -- putStrLn $ "ForestLocations :" ++! forestLocations makeResources surface (createBuilder arr) forestLocations jungleLocations water 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) diff --git a/maps/spain_terrain.png b/maps/spain_terrain.png Binary files differindex 22b1165..1983d16 100644 --- a/maps/spain_terrain.png +++ b/maps/spain_terrain.png diff --git a/maps/svalbard_height.png b/maps/svalbard_height.png Binary files differnew file mode 100644 index 0000000..7670da1 --- /dev/null +++ b/maps/svalbard_height.png diff --git a/maps/svalbard_terrain.png b/maps/svalbard_terrain.png Binary files differnew file mode 100644 index 0000000..5afd0b4 --- /dev/null +++ b/maps/svalbard_terrain.png |