diff --git a/src/Render/Render.hs b/src/Render/Render.hs index 6b3e4d3..a8fafe1 100644 --- a/src/Render/Render.hs +++ b/src/Render/Render.hs @@ -22,6 +22,7 @@ import Types import Render.Misc import Render.Types import Graphics.GLUtil.BufferObjects (makeBuffer) +import Importer.IQM.Parser mapVertexShaderFile :: String mapVertexShaderFile = "shaders/map/vertex.shader" @@ -32,6 +33,11 @@ mapTessEvalShaderFile = "shaders/map/tessEval.shader" mapFragmentShaderFile :: String mapFragmentShaderFile = "shaders/map/fragment.shader" +objectVertexShaderFile :: String +objectVertexShaderFile = "shaders/objects/vertex.shader" +objectFragmentShaderFile :: String +objectFragmentShaderFile = "shaders/objects/fragment.shader" + uiVertexShaderFile :: String uiVertexShaderFile = "shaders/ui/vertex.shader" uiFragmentShaderFile :: String @@ -113,6 +119,21 @@ initMapShader tessFac (buf, vertDes) = do texts <- genObjectNames 6 + testobj <- parseIQM "sample.iqm" + + let + objs = [GLObject testobj (Coord3D 0 10 0)] + + ! vertexSource' <- B.readFile objectVertexShaderFile + ! fragmentSource' <- B.readFile objectFragmentShaderFile + vertexShader' <- compileShaderSource VertexShader vertexSource' + checkError "compile Object-Vertex" + fragmentShader' <- compileShaderSource FragmentShader fragmentSource' + checkError "compile Object-Fragment" + objProgram <- createProgramUsing [vertexShader', fragmentShader'] + checkError "compile Object-Program" + + currentProgram $= Just objProgram checkError "initShader" return GLMapState @@ -132,6 +153,8 @@ initMapShader tessFac (buf, vertDes) = do , _mapVert = vertDes , _overviewTexture = overTex , _mapTextures = texts + , _mapObjects = objs + , _objectProgram = objProgram } initHud :: IO GLHud @@ -354,6 +377,11 @@ render = do cullFace $= Just Front glDrawArrays gl_PATCHES 0 (fromIntegral numVert) + + + currentProgram $= Just (state ^. gl.glMap.objectProgram) + + checkError "draw map" -- set sample 1 as target in renderbuffer diff --git a/src/Types.hs b/src/Types.hs index 115796a..c75dce9 100644 --- a/src/Types.hs +++ b/src/Types.hs @@ -13,7 +13,9 @@ import Control.Lens import Graphics.Rendering.OpenGL.GL.Texturing.Objects (TextureObject) import Render.Types import UI.UIBaseData +import Importer.IQM.Types +data Coord3D a = Coord3D a a a --Static Read-Only-State data Env = Env @@ -113,8 +115,12 @@ data GLMapState = GLMapState , _renderedMapTexture :: !TextureObject --TODO: Probably move to UI? , _overviewTexture :: !TextureObject , _mapTextures :: ![TextureObject] --TODO: Fix size on list? + , _objectProgram :: !GL.Program + , _mapObjects :: ![GLObject] } +data GLObject = GLObject IQM (Coord3D Double) + data GLHud = GLHud { _hudTexture :: !TextureObject -- ^ HUD-Texture itself , _hudTexIndex :: !GL.UniformLocation -- ^ Position of Overlay-Texture in Shader