diff --git a/shaders/fragment.shader b/shaders/fragment.shader index 576f612..1ef8c2c 100644 --- a/shaders/fragment.shader +++ b/shaders/fragment.shader @@ -9,5 +9,5 @@ out vec4 fg_FragColor; void main(void) { //copy-shader - fg_FragColor = fg_SmoothColor; + fg_FragColor = vec4(0.5,0.5,0.5,1.0);//fg_SmoothColor; } \ No newline at end of file diff --git a/shaders/vertex.shader b/shaders/vertex.shader index 780ea0c..af4183f 100644 --- a/shaders/vertex.shader +++ b/shaders/vertex.shader @@ -4,17 +4,17 @@ uniform mat4 fg_ProjectionMatrix; //vertex-data -in vec4 fg_Color; +//in vec4 fg_Color; in vec3 fg_VertexIn; -in vec3 fg_Normal; +//in vec3 fg_Normal; //output-data for later stages -smooth out vec4 fg_SmoothColor; +//smooth out vec4 fg_SmoothColor; void main() { //transform vec3 into vec4, setting w to 1 vec4 fg_Vertex = vec4(fg_VertexIn, 1.0); - fg_SmoothColor = fg_Color + 0.001* fg_Normal.xyzx; + //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..db47fb5 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -44,8 +44,6 @@ data State = State , stateFrustum :: [GL.GLfloat] -- pointer to bindings for locations inside the compiled shader -- mutable because shaders may be changed in the future. - , shdrColorIndex :: !GL.AttribLocation - , shdrNormalIndex :: !GL.AttribLocation , shdrVertexIndex :: !GL.AttribLocation , shdrProjMatIndex :: !GL.UniformLocation -- the map @@ -105,7 +103,7 @@ main = do --generate map vertices (mapBuffer, vert) <- getMapBufferObject - (ci, ni, vi, pi) <- initShader + (vi, pi) <- initShader let zDistClosest = 10 zDistFarthest = zDistClosest + 20 @@ -134,8 +132,6 @@ main = do , stateDragStartY = 0 , stateDragStartXAngle = 0 , stateDragStartYAngle = 0 - , shdrColorIndex = ci - , shdrNormalIndex = ni , shdrVertexIndex = vi , shdrProjMatIndex = pi , stateMap = mapBuffer @@ -378,8 +374,6 @@ draw = do ya = stateYAngle state za = stateZAngle state (GL.UniformLocation proj) = shdrProjMatIndex state - ci = shdrColorIndex state - ni = shdrNormalIndex state vi = shdrVertexIndex state numVert = mapVert state map' = stateMap state @@ -387,8 +381,6 @@ draw = do liftIO $ do 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 - GL.vertexAttribPointer ni GL.$= fgNormalIndex GL.vertexAttribPointer vi GL.$= fgVertexIndex GL.drawArrays GL.Triangles 0 numVert diff --git a/src/Map/Map.hs b/src/Map/Map.hs index d613c25..73446ab 100644 --- a/src/Map/Map.hs +++ b/src/Map/Map.hs @@ -47,9 +47,7 @@ lineHeight :: GLfloat lineHeight = 0.8660254 numComponents :: Int -numComponents = 4 --color - +3 --normal - +3 --vertex +numComponents = 3 mapStride :: Stride mapStride = fromIntegral (sizeOf (0.0 :: GLfloat)) * fromIntegral numComponents @@ -73,14 +71,14 @@ fgVertexIndex = (ToFloat, mapVertexArrayDescriptor 3 7) --vertex after normal getMapBufferObject :: IO (BufferObject, NumArrayIndices) getMapBufferObject = do map' <- testmap - map' <- return $ generateTriangles map' + map' <- return $ generateCube --generateTriangles map' putStrLn $ P.unlines $ P.map show (prettyMap map') len <- return $ fromIntegral $ P.length map' `div` numComponents putStrLn $ P.unwords ["num verts",show len] 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 (P.length map' * sizeOf(P.head map')), buffer, StaticDraw) checkError "initBuffer" return (bo,len) @@ -88,6 +86,51 @@ prettyMap :: [GLfloat] -> [(GLfloat,GLfloat,GLfloat,GLfloat,GLfloat,GLfloat,GLfl prettyMap (a:b:c:d:x:y:z:u:v:w:ms) = (a,b,c,d,x,y,z,u,v,w):(prettyMap ms) prettyMap _ = [] +generateCube :: [GLfloat] +generateCube = [ -- lower plane + -0.3,-0.3,-0.3, + 0.3,-0.3,0.3, + 0.3,-0.3,-0.3, + -0.3,-0.3,-0.3, + -0.3,-0.3,0.3, + 0.3,-0.3,0.3, + -- upper plane + -0.3,0.3,-0.3, + 0.3,0.3,0.3, + 0.3,0.3,-0.3, + -0.3,0.3,-0.3, + -0.3,0.3,0.3, + 0.3,0.3,0.3, + -- left plane + -0.3,-0.3,-0.3, + -0.3,0.3,0.3, + -0.3,-0.3,0.3, + -0.3,-0.3,-0.3, + -0.3,0.3,0.3, + -0.3,0.3,-0.3, + -- right plane + 0.3,-0.3,-0.3, + 0.3,0.3,0.3, + 0.3,-0.3,0.3, + 0.3,-0.3,-0.3, + 0.3,0.3,0.3, + 0.3,0.3,-0.3, + -- front plane + -0.3,-0.3,-0.3, + 0.3,0.3,-0.3, + 0.3,-0.3,-0.3, + -0.3,-0.3,-0.3, + 0.3,0.3,-0.3, + -0.3,0.3,-0.3, + -- back plane + -0.3,-0.3,0.3, + 0.3,0.3,0.3, + 0.3,-0.3,0.3, + -0.3,-0.3,0.3, + 0.3,0.3,0.3, + -0.3,0.3,0.3 + ] + generateTriangles :: PlayMap -> [GLfloat] generateTriangles map' = let ((xl,yl),(xh,yh)) = bounds map' in diff --git a/src/Render/Render.hs b/src/Render/Render.hs index 413c561..cd073b0 100644 --- a/src/Render/Render.hs +++ b/src/Render/Render.hs @@ -33,7 +33,7 @@ initBuffer varray = checkError "initBuffer" return bufferObject -initShader :: IO (AttribLocation, AttribLocation, AttribLocation, UniformLocation) +initShader :: IO (AttribLocation, UniformLocation) initShader = do ! vertexSource <- B.readFile vertexShaderFile ! fragmentSource <- B.readFile fragmentShaderFile @@ -49,20 +49,12 @@ initShader = do projectionMatrixIndex <- get (uniformLocation program "fg_ProjectionMatrix") checkError "projMat" - colorIndex <- get (attribLocation program "fg_Color") - vertexAttribArray colorIndex $= Enabled - checkError "colorInd" - - normalIndex <- get (attribLocation program "fg_Normal") - vertexAttribArray normalIndex $= Enabled - checkError "normalInd" - vertexIndex <- get (attribLocation program "fg_VertexIn") vertexAttribArray vertexIndex $= Enabled checkError "vertexInd" checkError "initShader" - return (colorIndex, normalIndex, vertexIndex, projectionMatrixIndex) + return (vertexIndex, projectionMatrixIndex) initRendering :: IO () initRendering = do