it is showing something on the screen! finally!

This commit is contained in:
Nicole Dresselhaus 2014-08-24 22:46:53 +02:00
parent 53775c559d
commit dc2205d3dc
No known key found for this signature in database
GPG Key ID: BC16D887851A1A80
3 changed files with 31 additions and 19 deletions

View File

@ -226,8 +226,8 @@ parseIQM a =
-- generate array buffers -- generate array buffers
-- --
--for pos,normal,tex: --for pos,normal,tex:
let initBuffer :: AttribLocation -> IQMVertexArrayType -> [IQMVertexArray] -> IO () let initBuffer :: AttribLocation -> IQMVertexArrayType -> [IQMVertexArray] -> Int -> IO ()
initBuffer l t vas = initBuffer l t vas len' =
do do
-- find array with type t, otherwise abort hard. -- find array with type t, otherwise abort hard.
let (IQMVertexArray _ _ format num _ dat) = case filter (\(IQMVertexArray ty _ _ _ _ _) -> ty == t) vas of let (IQMVertexArray _ _ format num _ dat) = case filter (\(IQMVertexArray ty _ _ _ _ _) -> ty == t) vas of
@ -237,13 +237,14 @@ parseIQM a =
-- create buffer and write data -- create buffer and write data
withVBO buf (toBufferTargetfromVAType t) $ do withVBO buf (toBufferTargetfromVAType t) $ do
-- copy data -- 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" checkError "bufferData vao"
-- tell layout -- tell layout
vertexAttribPointer l $= (ToFloat, VertexArrayDescriptor num Float 0 nullPtr) vertexAttribPointer l $= (ToFloat, VertexArrayDescriptor num Float 0 nullPtr)
initBuffer (AttribLocation 0) IQMPosition va' let len = (fromIntegral.num_triangles.bareheader) bare
initBuffer (AttribLocation 1) IQMNormal va' initBuffer (AttribLocation 0) IQMPosition va' len
initBuffer (AttribLocation 2) IQMTexCoord va' initBuffer (AttribLocation 1) IQMNormal va' len
initBuffer (AttribLocation 2) IQMTexCoord va' len
-- for indices -- for indices
tbo <- genObjectName tbo <- genObjectName
@ -299,7 +300,7 @@ toVBOfromVAO (IQMVertexArray type' _ _ num _ ptr) =
toBufferTargetfromVAType :: IQMVertexArrayType -> BufferTarget toBufferTargetfromVAType :: IQMVertexArrayType -> BufferTarget
toBufferTargetfromVAType IQMPosition = ArrayBuffer toBufferTargetfromVAType IQMPosition = ArrayBuffer
toBufferTargetfromVAType IQMTexCoord = TextureBuffer toBufferTargetfromVAType IQMTexCoord = ArrayBuffer
toBufferTargetfromVAType IQMNormal = ArrayBuffer toBufferTargetfromVAType IQMNormal = ArrayBuffer
toBufferTargetfromVAType IQMBlendIndexes = ElementArrayBuffer toBufferTargetfromVAType IQMBlendIndexes = ElementArrayBuffer
toBufferTargetfromVAType IQMBlendWeights = ArrayBuffer toBufferTargetfromVAType IQMBlendWeights = ArrayBuffer

View File

@ -78,6 +78,7 @@ main = do
] $ \window' -> do ] $ \window' -> do
SDL.withOpenGL window' $ do SDL.withOpenGL window' $ do
SDL.glSwapWindow window' -- swap to get the glew-stuff out of the way
--Create Renderbuffer & Framebuffer --Create Renderbuffer & Framebuffer
-- We will render to this buffer to copy the result into textures -- We will render to this buffer to copy the result into textures
renderBuffer <- GL.genObjectName renderBuffer <- GL.genObjectName

View File

@ -128,11 +128,6 @@ initMapShader tessFac (buf, vertDes) = do
smap <- genObjectName smap <- genObjectName
testobj <- parseIQM "models/box.iqm"
let
objs = [MapObject testobj (L.V3 0 10 0) (MapObjectState ())]
currentProgram $= Nothing currentProgram $= Nothing
! vertexSource' <- B.readFile objectVertexShaderFile ! vertexSource' <- B.readFile objectVertexShaderFile
@ -185,6 +180,9 @@ initMapShader tessFac (buf, vertDes) = do
putStrLn $ unlines $ "Model-Uniforms: ":map show uni' putStrLn $ unlines $ "Model-Uniforms: ":map show uni'
putStrLn $ unlines $ ["Model-Indices: ", show (texIndex', normalIndex', vertexIndex')] 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 currentProgram $= Nothing
checkError "initShader" 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 drawElements Triangles n UnsignedInt nullPtr
checkError "drawing model" checkError "drawing model"
bindBuffer ElementArrayBuffer $= Nothing bindBuffer ElementArrayBuffer $= Nothing
vertexAttribArray (AttribLocation 0) $= Disabled
checkError "unbind buffer" checkError "unbind buffer"
return () return ()
@ -339,6 +338,10 @@ drawMap = do
glDrawArrays gl_PATCHES 0 (fromIntegral numVert) glDrawArrays gl_PATCHES 0 (fromIntegral numVert)
checkError "draw map" checkError "draw map"
bindBuffer ArrayBuffer $= Nothing
vertexAttribArray ci $= Disabled
vertexAttribArray ni $= Disabled
vertexAttribArray vi $= Disabled
-- set sample 1 as target in renderbuffer -- set sample 1 as target in renderbuffer
{-framebufferRenderbuffer {-framebufferRenderbuffer
@ -401,6 +404,7 @@ render = do
(state ^. gl.glRenderbuffer)-} (state ^. gl.glRenderbuffer)-}
---- RENDER SHADOWMAP <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ---- RENDER SHADOWMAP <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
{- liftIO $ do
textureBinding Texture2D $= Just (state ^. gl.glMap.shadowMapTexture) textureBinding Texture2D $= Just (state ^. gl.glMap.shadowMapTexture)
framebufferTexture2D framebufferTexture2D
Framebuffer Framebuffer
@ -449,11 +453,14 @@ render = do
mapM_ renderObject (state ^. gl.glMap.mapObjects) mapM_ renderObject (state ^. gl.glMap.mapObjects)
checkError "draw mapobjects" checkError "draw mapobjects"
checkError "draw ShadowMap" checkError "draw ShadowMap"-}
---- RENDER MAP IN TEXTURE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ---- RENDER MAP IN TEXTURE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-- COLORMAP -- COLORMAP
tex <- liftIO $ readTVarIO (state ^. mapTexture) liftIO $ do
bindFramebuffer Framebuffer $= defaultFramebufferObject
drawBuffer $= BackBuffers
{-tex <- liftIO $ readTVarIO (state ^. mapTexture)
textureBinding Texture2D $= Just tex textureBinding Texture2D $= Just tex
framebufferTexture2D framebufferTexture2D
Framebuffer Framebuffer
@ -463,7 +470,7 @@ render = do
0 0
-- Render to FrameBufferObject -- Render to FrameBufferObject
drawBuffers $= [FBOColorAttachment 0] drawBuffers $= [FBOColorAttachment 0]-}
checkError "setup Render-Target" checkError "setup Render-Target"
clear [ColorBuffer, DepthBuffer] clear [ColorBuffer, DepthBuffer]
@ -481,22 +488,21 @@ render = do
drawMap drawMap
liftIO $ do liftIO $ do
---- RENDER MAPOBJECTS -------------------------------------------- ---- RENDER MAPOBJECTS --------------------------------------------
checkError "clear buffer"
currentProgram $= Just (state ^. gl.glMap.objectProgram) currentProgram $= Just (state ^. gl.glMap.objectProgram)
checkError "setting up shadowmap-program" checkError "setting up shadowmap-program"
--set up projection (= copy from state) --set up projection (= copy from state)
mat44ToGPU frust projmo "mapObjects-projection" {-mat44ToGPU frust projmo "mapObjects-projection"
--set up camera --set up camera
mat44ToGPU cam' vmatmo "mapObjects-cam" mat44ToGPU cam' vmatmo "mapObjects-cam"
--set up normal --set up normal
mat33ToGPU nmap nmatmo "mapObjects-nmat" mat33ToGPU nmap nmatmo "mapObjects-nmat"-}
mapM_ renderObject (state ^. gl.glMap.mapObjects) mapM_ renderObject (state ^. gl.glMap.mapObjects)
checkError "draw mapobjects" checkError "draw mapobjects"
---- COMPOSE RENDERING -------------------------------------------- ---- COMPOSE RENDERING --------------------------------------------
-- Render to BackBuffer (=Screen) -- Render to BackBuffer (=Screen)
bindFramebuffer Framebuffer $= defaultFramebufferObject {-bindFramebuffer Framebuffer $= defaultFramebufferObject
drawBuffer $= BackBuffers drawBuffer $= BackBuffers
-- Drawing HUD -- Drawing HUD
clear [ColorBuffer, DepthBuffer] clear [ColorBuffer, DepthBuffer]
@ -524,3 +530,7 @@ render = do
bindBuffer ElementArrayBuffer $= Just (hud ^. hudEBO) bindBuffer ElementArrayBuffer $= Just (hud ^. hudEBO)
drawElements TriangleStrip 4 UnsignedInt offset0 drawElements TriangleStrip 4 UnsignedInt offset0
bindBuffer ArrayBuffer $= Nothing
bindBuffer ElementArrayBuffer $= Nothing-}