From a2214082ca6706b3173ff31a7968dbe49244001e Mon Sep 17 00:00:00 2001 From: Stefan Dresselhaus Date: Fri, 3 Jan 2014 23:19:39 +0100 Subject: [PATCH] minor stuff .. STILL NO TRIANGLE -.- --- src/Main.hs | 49 ++++++++++++---------------------------------- src/Render/Misc.hs | 11 ++++++----- 2 files changed, 19 insertions(+), 41 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 910cd30..0d49094 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -10,8 +10,8 @@ import Data.List (intercalate) import Data.Maybe (catMaybes) import Text.PrettyPrint -import qualified Graphics.Rendering.OpenGL as GL -import qualified Graphics.UI.GLFW as GLFW +import qualified Graphics.Rendering.OpenGL.GL as GL +import qualified Graphics.UI.GLFW as GLFW import Map.Map import Render.Render (initShader) @@ -101,16 +101,6 @@ main = do GLFW.swapInterval 1 - GL.position (GL.Light 0) GL.$= GL.Vertex4 5 5 10 0 - GL.light (GL.Light 0) GL.$= GL.Enabled - GL.lighting GL.$= GL.Enabled - GL.cullFace GL.$= Just GL.FrontAndBack -- Back - GL.depthFunc GL.$= Just GL.Always -- Less - GL.clearColor GL.$= GL.Color4 0.05 0.05 0.05 1 - GL.normalize GL.$= GL.Enabled - - - (fbWidth, fbHeight) <- GLFW.getFramebufferSize win --generate map vertices @@ -231,6 +221,7 @@ run = do GLFW.swapBuffers win GL.flush -- not necessary, but someone recommended it GLFW.pollEvents + GL.finish -- getEvents & process processEvents @@ -368,29 +359,16 @@ processEvent ev = adjustWindow :: Pioneer () adjustWindow = do state <- get - let width = stateWindowWidth state - height = stateWindowHeight state - zDist = stateZDist state - - let pos = GL.Position 0 0 - size = GL.Size (fromIntegral width) (fromIntegral height) - h = fromIntegral height / fromIntegral width :: Double - znear = 1 :: Double - zfar = 40 :: Double - xmax = znear * 0.5 :: Double - liftIO $ do - GL.viewport GL.$= (pos, size) - GL.matrixMode GL.$= GL.Projection - GL.loadIdentity - GL.frustum (realToFrac $ -xmax) - (realToFrac xmax) - (realToFrac $ -xmax * realToFrac h) - (realToFrac $ xmax * realToFrac h) - (realToFrac znear) - (realToFrac zfar) - GL.matrixMode GL.$= GL.Modelview 0 - GL.loadIdentity - GL.translate (GL.Vector3 0 0 (negate $ realToFrac zDist) :: GL.Vector3 GL.GLfloat) + let fbWidth = stateWindowWidth state + fbHeight = stateWindowHeight state + fov = 90 --field of view + near = 1 --near plane + far = 100 --far plane + ratio = fromIntegral fbWidth / fromIntegral fbHeight + frust = createFrustum fov near far ratio + put $ state { + stateFrustum = frust + } draw :: Pioneer () draw = do @@ -407,7 +385,6 @@ draw = do map' = stateMap state frust = stateFrustum state liftIO $ do - GL.clear [GL.ColorBuffer, GL.DepthBuffer] lookAtUniformMatrix4fv (0.0,0.0,0.0) (0, 15, 0) up frust proj 1 GL.bindBuffer GL.ArrayBuffer GL.$= Just map' GL.vertexAttribPointer ci GL.$= fgColorIndex diff --git a/src/Render/Misc.hs b/src/Render/Misc.hs index 0a49437..cd306f3 100644 --- a/src/Render/Misc.hs +++ b/src/Render/Misc.hs @@ -2,13 +2,14 @@ module Render.Misc where import Control.Monad import qualified Data.ByteString as B (ByteString) +import Foreign.Marshal.Array (allocaArray, + pokeArray) 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 Graphics.Rendering.OpenGL.Raw.Core31 import System.IO (hPutStrLn, stderr) -import Graphics.Rendering.OpenGL.Raw.Core31 -import Foreign.Marshal.Array (allocaArray, pokeArray) up :: (Double, Double, Double) @@ -77,7 +78,7 @@ lookAtUniformMatrix4fv o c u frust num size = allocaArray 16 $ \projMat -> do pokeArray projMat $ [1, 0, 0, 0, - 0, 0, 1, 0.1, + 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1 ] @@ -92,7 +93,7 @@ infixl 5 >< ba, bb, bc, bd, ca, cb, cc, cd, da, db, dc, dd - ] >< + ] >< [ xx, xy, xz, xw, yx, yy, yz, yw, @@ -127,7 +128,7 @@ _ >< _ = error "non-conformat matrix-multiplication" -- generates 4x4-Projection-Matrix lookAt :: (Double, Double, Double) -> (Double, Double, Double) -> (Double, Double, Double) -> [GLfloat] -lookAt at eye up = +lookAt at eye up = map (fromRational . toRational) [ xx, yx, zx, 0, xy, yy, zy, 0,