diff options
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 |