From 7db4bff2e4d074cf5d94515a335bec081cbaa3cc Mon Sep 17 00:00:00 2001 From: Stefan Dresselhaus Date: Sat, 4 Jan 2014 02:45:13 +0100 Subject: [PATCH] moooaaarrr work on triangles ... still nothing --- Pioneers.cabal | 3 ++- shaders/fragment.shader | 3 +-- shaders/vertex.shader | 4 ++-- src/Main.hs | 34 ++++++++++++++++++++++++++++++---- src/Map/Map.hs | 4 +++- src/Render/Misc.hs | 8 ++++---- 6 files changed, 42 insertions(+), 14 deletions(-) diff --git a/Pioneers.cabal b/Pioneers.cabal index 1c96d4f..af29ed0 100644 --- a/Pioneers.cabal +++ b/Pioneers.cabal @@ -25,5 +25,6 @@ executable Pioneers pretty >=1.1, transformers >=0.3.0 && <0.4, mtl >=2.1.2, - stm >=2.4.2 + stm >=2.4.2, + vector >=0.10.9 && <0.11 diff --git a/shaders/fragment.shader b/shaders/fragment.shader index 576f612..3482b68 100644 --- a/shaders/fragment.shader +++ b/shaders/fragment.shader @@ -3,11 +3,10 @@ //color from earlier stages smooth in vec4 fg_SmoothColor; -//color of pixel out vec4 fg_FragColor; void main(void) { //copy-shader - fg_FragColor = fg_SmoothColor; + fg_FragColor = vec4(1,0,0,1) + 0.01* fg_SmoothColor; } \ No newline at end of file diff --git a/shaders/vertex.shader b/shaders/vertex.shader index 780ea0c..29fa933 100644 --- a/shaders/vertex.shader +++ b/shaders/vertex.shader @@ -9,12 +9,12 @@ in vec3 fg_VertexIn; in vec3 fg_Normal; //output-data for later stages -smooth out vec4 fg_SmoothColor; +out vec4 fg_SmoothColor; void main() { //transform vec3 into vec4, setting w to 1 - vec4 fg_Vertex = vec4(fg_VertexIn, 1.0); + vec4 fg_Vertex = vec4(fg_VertexIn.x, fg_VertexIn.y+0.1, fg_VertexIn.z, 1.0); fg_SmoothColor = fg_Color + 0.001* fg_Normal.xyzx; gl_Position = fg_ProjectionMatrix * fg_Vertex; } \ No newline at end of file diff --git a/src/Main.hs b/src/Main.hs index 0d49094..2ca7206 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -10,12 +10,14 @@ import Data.List (intercalate) import Data.Maybe (catMaybes) import Text.PrettyPrint -import qualified Graphics.Rendering.OpenGL.GL as GL -import qualified Graphics.UI.GLFW as GLFW +import qualified Graphics.Rendering.OpenGL.GL as GL +import qualified Graphics.Rendering.OpenGL.Raw.Core31 as GLRaw +import qualified Graphics.UI.GLFW as GLFW +import qualified Data.Vector.Storable as V import Map.Map import Render.Render (initShader) -import Render.Misc (up, lookAtUniformMatrix4fv, createFrustum) +import Render.Misc (up, lookAtUniformMatrix4fv, createFrustum, checkError) -------------------------------------------------------------------------------- @@ -385,13 +387,37 @@ draw = do map' = stateMap state frust = stateFrustum state liftIO $ do - lookAtUniformMatrix4fv (0.0,0.0,0.0) (0, 15, 0) up frust proj 1 + GLRaw.glClearDepth 1.0 + GLRaw.glDisable GLRaw.gl_CULL_FACE + --lookAtUniformMatrix4fv (0.0,0.0,0.0) (0, 15, 0) up frust proj 1 + +------------- + + let fov = 90 + s = recip (tan $ fov * 0.5 * pi / 180) + f = 1000 + n = 1 + + let perspective = V.fromList [ s, 0, 0, 0 + , 0, s, 0, 0 + , 0, 0, -(f/(f - n)), -1 + , 0, 0, -((f*n)/(f-n)), 0 + ] + + V.unsafeWith perspective $ \ptr -> GLRaw.glUniformMatrix4fv proj 1 0 ptr + +--------------- + GL.bindBuffer GL.ArrayBuffer GL.$= Just map' GL.vertexAttribPointer ci GL.$= fgColorIndex + GL.vertexAttribArray ci GL.$= GL.Enabled GL.vertexAttribPointer ni GL.$= fgNormalIndex + GL.vertexAttribArray ni GL.$= GL.Enabled GL.vertexAttribPointer vi GL.$= fgVertexIndex + GL.vertexAttribArray vi GL.$= GL.Enabled GL.drawArrays GL.Triangles 0 numVert + checkError "draw" getCursorKeyDirections :: GLFW.Window -> IO (Double, Double) getCursorKeyDirections win = do diff --git a/src/Map/Map.hs b/src/Map/Map.hs index d613c25..2222b96 100644 --- a/src/Map/Map.hs +++ b/src/Map/Map.hs @@ -80,7 +80,9 @@ getMapBufferObject = do bo <- genObjectName -- create a new buffer bindBuffer ArrayBuffer $= Just bo -- bind buffer withArray map' $ \buffer -> - bufferData ArrayBuffer $= (fromIntegral (sizeOf(P.head map')), buffer, StaticDraw) + bufferData ArrayBuffer $= (fromIntegral $ sizeOf (0 :: Float)*P.length map', + buffer, + StaticDraw) checkError "initBuffer" return (bo,len) diff --git a/src/Render/Misc.hs b/src/Render/Misc.hs index cd306f3..b08a259 100644 --- a/src/Render/Misc.hs +++ b/src/Render/Misc.hs @@ -77,10 +77,10 @@ lookAtUniformMatrix4fv :: (Double, Double, Double) --origin lookAtUniformMatrix4fv o c u frust num size = allocaArray 16 $ \projMat -> do pokeArray projMat $ - [1, 0, 0, 0, - 0, 0, 1, 0, - 0, 1, 0, 0, - 0, 0, 0, 1 + [0.1, 0, 0, 0, + 0, 0, 0.1, 0, + 0, 0.1, 0, 0, + 0, 0, 0, 1 ] --(lookAt o c u) >< frust glUniformMatrix4fv num size 1 projMat