From 306381c4ed3ff626da9cc17d45880f8e374d5b0d Mon Sep 17 00:00:00 2001 From: Stefan Dresselhaus Date: Thu, 2 Jan 2014 13:02:01 +0100 Subject: [PATCH] little cleanup - some formatting - changed y/z-Coords on Map (y is height now, map is in x/z-plane) --- src/Main.hs | 3 ++- src/Map/Map.hs | 6 +++--- src/Render/Misc.hs | 20 ++++++++++---------- src/Render/Render.hs | 33 ++++++++++++++++++++------------- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 985847d..7cd2f5f 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -26,6 +26,7 @@ import GHC.Conc.Sync (unsafeIOToSTM) import Prelude as P import System.IO.Unsafe (unsafePerformIO) import Foreign.Marshal.Array (allocaArray) +import Render.Misc (dumpInfo) data ProgramState = PS { keysPressed :: IntSet , px :: GLfloat @@ -365,6 +366,7 @@ keyEvent state press = do | code == 25 -> accept $ ps { dheading = dheading - deltaH } | code == 27 -> accept $ ps { dheading = dheading + deltaH } | code == 42 -> accept $ ps { showShadowMap = not showShadowMap } + | code == 31 -> dumpInfo >> accept ps | otherwise -> deny ps -- on RELEASE only False @@ -522,7 +524,6 @@ main = do (w', h') <- liftIO $ reconfigure w h liftIO $ Gtk.labelSetText label $ unwords ["Width:",show w',"Height:",show h'] - Gtk.widgetShowAll window Gtk.mainGUI diff --git a/src/Map/Map.hs b/src/Map/Map.hs index 04dd897..4b81628 100644 --- a/src/Map/Map.hs +++ b/src/Map/Map.hs @@ -105,11 +105,11 @@ colorLookup hs t = if inRange (bounds hs) t then c else (0.0, 0.0, 0.0) Mountain -> (0.5, 0.5, 0.5) coordLookup :: (Int,Int) -> GLfloat -> (GLfloat, GLfloat, GLfloat) -coordLookup (x,y) h = +coordLookup (x,z) y = if even x then - (fromIntegral $ x `div` 2, fromIntegral (2 * y) * lineHeight, h) + (fromIntegral $ x `div` 2, y, fromIntegral (2 * z) * lineHeight) else - (fromIntegral (x `div` 2) / 2.0, fromIntegral (2 * y + 1) * lineHeight, h) + (fromIntegral (x `div` 2) / 2.0, y, fromIntegral (2 * z + 1) * lineHeight) -- if writing in ASCII-Format transpose so i,j -> y,x diff --git a/src/Render/Misc.hs b/src/Render/Misc.hs index 5e2607b..0d56abd 100644 --- a/src/Render/Misc.hs +++ b/src/Render/Misc.hs @@ -1,24 +1,24 @@ module Render.Misc where -import Graphics.Rendering.OpenGL.GL.StringQueries -import Graphics.Rendering.OpenGL.GL.StateVar -import Graphics.Rendering.OpenGL.GLU.Errors -import System.IO (hPutStrLn, stderr) -import Control.Monad -import Graphics.Rendering.OpenGL.GL.Shaders -import qualified Data.ByteString as B (ByteString) +import Control.Monad +import qualified Data.ByteString as B (ByteString) +import Graphics.Rendering.OpenGL.GL.Shaders +import Graphics.Rendering.OpenGL.GL.StateVar +import Graphics.Rendering.OpenGL.GL.StringQueries +import Graphics.Rendering.OpenGL.GLU.Errors +import System.IO (hPutStrLn, stderr) checkError :: String -> IO () checkError functionName = get errors >>= mapM_ reportError - where reportError e = + where reportError e = hPutStrLn stderr (showError e ++ " detected in " ++ functionName) showError (Error category message) = "GL error " ++ show category ++ " (" ++ message ++ ")" dumpInfo :: IO () dumpInfo = do - let dump message var = putStrLn . ((message ++ ": ") ++) =<< get var + let dump message var = putStrLn . ((message ++ ": ") ++) =<< get var dump "Vendor" vendor dump "Renderer" renderer dump "Version" glVersion @@ -50,4 +50,4 @@ createProgramUsing shaders = do program <- createProgram attachedShaders program $= shaders linkAndCheck program - return program \ No newline at end of file + return program diff --git a/src/Render/Render.hs b/src/Render/Render.hs index 1bbeec9..a97792a 100644 --- a/src/Render/Render.hs +++ b/src/Render/Render.hs @@ -1,17 +1,19 @@ {-# LANGUAGE BangPatterns #-} module Render.Render where -import Graphics.Rendering.OpenGL.GL.BufferObjects -import Graphics.Rendering.OpenGL.GL.ObjectName -import Graphics.Rendering.OpenGL.GL.StateVar -import Render.Misc -import Graphics.Rendering.OpenGL.Raw.Core31.Types (GLfloat) -import Foreign.Storable (sizeOf) -import Foreign.Marshal.Array (withArray) -import Graphics.Rendering.OpenGL.GL.VertexSpec -import Graphics.Rendering.OpenGL.GL.Shaders -import Graphics.Rendering.OpenGL.GL.VertexArrays (Capability(..), vertexAttribArray) -import qualified Data.ByteString as B +import qualified Data.ByteString as B +import Foreign.Marshal.Array (withArray) +import Foreign.Storable (sizeOf) +import Graphics.Rendering.OpenGL.GL.BufferObjects +import Graphics.Rendering.OpenGL.GL.Framebuffer (clearColor) +import Graphics.Rendering.OpenGL.GL.ObjectName +import Graphics.Rendering.OpenGL.GL.Shaders +import Graphics.Rendering.OpenGL.GL.StateVar +import Graphics.Rendering.OpenGL.GL.VertexArrays (Capability (..), + vertexAttribArray) +import Graphics.Rendering.OpenGL.GL.VertexSpec +import Graphics.Rendering.OpenGL.Raw.Core31.Types (GLfloat) +import Render.Misc vertexShaderFile :: String vertexShaderFile = "shaders/vertex.shader" @@ -19,7 +21,7 @@ fragmentShaderFile :: String fragmentShaderFile = "shaders/fragment.shader" initBuffer :: [GLfloat] -> IO BufferObject -initBuffer varray = +initBuffer varray = let sizeOfVarray = length varray * sizeOfComponent sizeOfComponent = sizeOf (head varray) @@ -49,4 +51,9 @@ initShader = do vertexAttribArray vertexIndex $= Enabled checkError "initShader" - return (projectionMatrixIndex, colorIndex, vertexIndex) \ No newline at end of file + return (projectionMatrixIndex, colorIndex, vertexIndex) + +initRendering :: IO () +initRendering = do + clearColor $= Color4 0 0 0 0 + checkError "initRendering"