diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2010-02-25 03:16:44 +0100 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2010-02-25 03:16:44 +0100 |
commit | c23e63e66786410f53b9460a6456b7c893d2a234 (patch) | |
tree | 213a204572b94a9a864d9da9109a9f2a3f95a6ae /Render.hs | |
parent | b4c3367c63459607f0919e77998d5405634e2003 (diff) | |
download | htanks-c23e63e66786410f53b9460a6456b7c893d2a234.tar htanks-c23e63e66786410f53b9460a6456b7c893d2a234.zip |
Cache textures in game state
Diffstat (limited to 'Render.hs')
-rw-r--r-- | Render.hs | 32 |
1 files changed, 28 insertions, 4 deletions
@@ -7,28 +7,52 @@ module Render ( setup import Game import Level import Tank - -import Bindings.GLPng +import Texture import Control.Monad.State import Data.Fixed +import Data.Maybe import Data.Ratio +import qualified Data.Map as M + +import Bindings.GLPng import Graphics.Rendering.OpenGL.GL (($=), GLfloat, GLdouble) import Graphics.Rendering.OpenGL.GL.BeginEnd (renderPrimitive, PrimitiveMode(..)) import Graphics.Rendering.OpenGL.GL.CoordTrans (matrixMode, MatrixMode(..), viewport, Position(..), Size(..), loadIdentity, ortho) import Graphics.Rendering.OpenGL.GL.Framebuffer (clear, ClearBuffer(..)) +import Graphics.Rendering.OpenGL.GL.Texturing.Objects (TextureObject(..)) import Graphics.Rendering.OpenGL.GL.Texturing.Parameters (Repetition(..), Clamping(..), TextureFilter(..), MinificationFilter, MagnificationFilter) import Graphics.Rendering.OpenGL.GL.VertexSpec +texturePath :: Texture -> String +texturePath t + | t == TextureWood = "tex/Wood.png" + +getTexture :: Texture -> Game TextureObject +getTexture t = do + ts <- gets textures + let tobj = M.lookup t ts + + if (isJust tobj) + then + return $ fromJust tobj + else do + tex <- liftIO $ pngBind (texturePath t) NoMipmap Solid (Repeated, Repeat) (Linear', Nothing) Linear' >>= return . TextureObject . fromIntegral . fst + modify $ \state -> state {textures = M.insert t tex ts} + return tex + + setup :: Int -> Int -> Game () setup w h = do resize w h - (tex, info) <- liftIO $ pngBind "tex/Wood.png" NoMipmap Solid (Repeated, Repeat) (Linear', Nothing) Linear' - liftIO $ print info + -- cache textures + getTexture TextureWood + + return () resize :: Int -> Int -> Game () resize w h = do |