From dc2205d3dce6323217f952a6f1f555467dd38c97 Mon Sep 17 00:00:00 2001 From: Stefan Dresselhaus Date: Sun, 24 Aug 2014 22:46:53 +0200 Subject: [PATCH] it is showing something on the screen! finally! --- src/Importer/IQM/Parser.hs | 15 ++++++++------- src/Main.hs | 1 + src/Render/Render.hs | 34 ++++++++++++++++++++++------------ 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/Importer/IQM/Parser.hs b/src/Importer/IQM/Parser.hs index a86fc40..e69de34 100644 --- a/src/Importer/IQM/Parser.hs +++ b/src/Importer/IQM/Parser.hs @@ -226,8 +226,8 @@ parseIQM a = -- generate array buffers -- --for pos,normal,tex: - let initBuffer :: AttribLocation -> IQMVertexArrayType -> [IQMVertexArray] -> IO () - initBuffer l t vas = + let initBuffer :: AttribLocation -> IQMVertexArrayType -> [IQMVertexArray] -> Int -> IO () + initBuffer l t vas len' = do -- find array with type t, otherwise abort hard. let (IQMVertexArray _ _ format num _ dat) = case filter (\(IQMVertexArray ty _ _ _ _ _) -> ty == t) vas of @@ -237,13 +237,14 @@ parseIQM a = -- create buffer and write data withVBO buf (toBufferTargetfromVAType t) $ do -- copy data - bufferData (toBufferTargetfromVAType t) $= (fromIntegral num * (fromIntegral.vaSize) format,dat,StaticDraw) + bufferData (toBufferTargetfromVAType t) $= (fromIntegral len' * fromIntegral num * (fromIntegral.vaSize) format,dat,StaticDraw) checkError "bufferData vao" -- tell layout vertexAttribPointer l $= (ToFloat, VertexArrayDescriptor num Float 0 nullPtr) - initBuffer (AttribLocation 0) IQMPosition va' - initBuffer (AttribLocation 1) IQMNormal va' - initBuffer (AttribLocation 2) IQMTexCoord va' + let len = (fromIntegral.num_triangles.bareheader) bare + initBuffer (AttribLocation 0) IQMPosition va' len + initBuffer (AttribLocation 1) IQMNormal va' len + initBuffer (AttribLocation 2) IQMTexCoord va' len -- for indices tbo <- genObjectName @@ -299,7 +300,7 @@ toVBOfromVAO (IQMVertexArray type' _ _ num _ ptr) = toBufferTargetfromVAType :: IQMVertexArrayType -> BufferTarget toBufferTargetfromVAType IQMPosition = ArrayBuffer -toBufferTargetfromVAType IQMTexCoord = TextureBuffer +toBufferTargetfromVAType IQMTexCoord = ArrayBuffer toBufferTargetfromVAType IQMNormal = ArrayBuffer toBufferTargetfromVAType IQMBlendIndexes = ElementArrayBuffer toBufferTargetfromVAType IQMBlendWeights = ArrayBuffer diff --git a/src/Main.hs b/src/Main.hs index 92184c3..caae918 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -78,6 +78,7 @@ main = do ] $ \window' -> do SDL.withOpenGL window' $ do + SDL.glSwapWindow window' -- swap to get the glew-stuff out of the way --Create Renderbuffer & Framebuffer -- We will render to this buffer to copy the result into textures renderBuffer <- GL.genObjectName diff --git a/src/Render/Render.hs b/src/Render/Render.hs index b4fd059..23f0310 100644 --- a/src/Render/Render.hs +++ b/src/Render/Render.hs @@ -128,11 +128,6 @@ initMapShader tessFac (buf, vertDes) = do smap <- genObjectName - testobj <- parseIQM "models/box.iqm" - - let - objs = [MapObject testobj (L.V3 0 10 0) (MapObjectState ())] - currentProgram $= Nothing ! vertexSource' <- B.readFile objectVertexShaderFile @@ -185,6 +180,9 @@ initMapShader tessFac (buf, vertDes) = do putStrLn $ unlines $ "Model-Uniforms: ":map show uni' putStrLn $ unlines $ ["Model-Indices: ", show (texIndex', normalIndex', vertexIndex')] + testobj <- parseIQM "models/box.iqm" + let objs = [MapObject testobj (L.V3 0 10 0) (MapObjectState ())] + currentProgram $= Nothing checkError "initShader" @@ -298,6 +296,7 @@ renderIQM m p@(L.V3 x y z) s@(L.V3 sx sy sz) = do drawElements Triangles n UnsignedInt nullPtr checkError "drawing model" bindBuffer ElementArrayBuffer $= Nothing + vertexAttribArray (AttribLocation 0) $= Disabled checkError "unbind buffer" return () @@ -339,6 +338,10 @@ drawMap = do glDrawArrays gl_PATCHES 0 (fromIntegral numVert) checkError "draw map" + bindBuffer ArrayBuffer $= Nothing + vertexAttribArray ci $= Disabled + vertexAttribArray ni $= Disabled + vertexAttribArray vi $= Disabled -- set sample 1 as target in renderbuffer {-framebufferRenderbuffer @@ -401,6 +404,7 @@ render = do (state ^. gl.glRenderbuffer)-} ---- RENDER SHADOWMAP <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +{- liftIO $ do textureBinding Texture2D $= Just (state ^. gl.glMap.shadowMapTexture) framebufferTexture2D Framebuffer @@ -449,11 +453,14 @@ render = do mapM_ renderObject (state ^. gl.glMap.mapObjects) checkError "draw mapobjects" - checkError "draw ShadowMap" + checkError "draw ShadowMap"-} ---- RENDER MAP IN TEXTURE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -- COLORMAP - tex <- liftIO $ readTVarIO (state ^. mapTexture) + liftIO $ do + bindFramebuffer Framebuffer $= defaultFramebufferObject + drawBuffer $= BackBuffers + {-tex <- liftIO $ readTVarIO (state ^. mapTexture) textureBinding Texture2D $= Just tex framebufferTexture2D Framebuffer @@ -463,7 +470,7 @@ render = do 0 -- Render to FrameBufferObject - drawBuffers $= [FBOColorAttachment 0] + drawBuffers $= [FBOColorAttachment 0]-} checkError "setup Render-Target" clear [ColorBuffer, DepthBuffer] @@ -481,22 +488,21 @@ render = do drawMap liftIO $ do ---- RENDER MAPOBJECTS -------------------------------------------- - checkError "clear buffer" currentProgram $= Just (state ^. gl.glMap.objectProgram) checkError "setting up shadowmap-program" --set up projection (= copy from state) - mat44ToGPU frust projmo "mapObjects-projection" + {-mat44ToGPU frust projmo "mapObjects-projection" --set up camera mat44ToGPU cam' vmatmo "mapObjects-cam" --set up normal - mat33ToGPU nmap nmatmo "mapObjects-nmat" + mat33ToGPU nmap nmatmo "mapObjects-nmat"-} mapM_ renderObject (state ^. gl.glMap.mapObjects) checkError "draw mapobjects" ---- COMPOSE RENDERING -------------------------------------------- -- Render to BackBuffer (=Screen) - bindFramebuffer Framebuffer $= defaultFramebufferObject + {-bindFramebuffer Framebuffer $= defaultFramebufferObject drawBuffer $= BackBuffers -- Drawing HUD clear [ColorBuffer, DepthBuffer] @@ -523,4 +529,8 @@ render = do bindBuffer ElementArrayBuffer $= Just (hud ^. hudEBO) drawElements TriangleStrip 4 UnsignedInt offset0 + + bindBuffer ArrayBuffer $= Nothing + bindBuffer ElementArrayBuffer $= Nothing-} +