it is showing something on the screen! finally!
This commit is contained in:
parent
53775c559d
commit
dc2205d3dc
@ -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
|
||||
|
@ -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
|
||||
|
@ -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]
|
||||
@ -524,3 +530,7 @@ render = do
|
||||
bindBuffer ElementArrayBuffer $= Just (hud ^. hudEBO)
|
||||
drawElements TriangleStrip 4 UnsignedInt offset0
|
||||
|
||||
bindBuffer ArrayBuffer $= Nothing
|
||||
bindBuffer ElementArrayBuffer $= Nothing-}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user