diff --git a/src/Render.hs b/src/Render.hs index fd12699e9..9d2210232 100644 --- a/src/Render.hs +++ b/src/Render.hs @@ -1,6 +1,5 @@ module Render ( createLightMap, - divideSize, renderFoldable, renderLayer, pingPongBetween, @@ -20,15 +19,11 @@ import Dodge.Data.Config import Foreign hiding (rotate) import Geometry.Data import Graphics.GL.Core43 -import Graphics.Rendering.OpenGL hiding (Color, Line, Polygon, T, imageHeight, scale, translate) import Picture.Data import Shader import Shader.Data import Shader.ExtraPrimitive -divideSize :: Int -> Size -> Size -divideSize i (Size x y) = Size (div x $ fromIntegral i) (div y $ fromIntegral i) - -- | Determine where light is shining in the world. -- think of the produced texture as showing what RGB values should be "taken -- away" from the shape colors. @@ -55,26 +50,30 @@ createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos drawCPUSh ltextShad = _lightingTextureShader pdata -- we assume that the renderbuffer's depth has been correctly set elsewhere -- we will not be changing that here - depthMask $= Disabled + glDepthMask GL_FALSE -- clearColor is specified differently in preloadRender -- the colors are inverted - clearColor $= Color4 1 1 1 1 - clear [ColorBuffer] + glClearColor 1 1 1 1 + glClear GL_COLOR_BUFFER_BIT -- for each of the lights: -- 1. stencil out the shadows from this light's point of view -- 2. calculate lighting based on each fragment's position -- to consider: adding normals/a "material" for each fragment - blendFunc $= (Zero, OneMinusSrcColor) - stencilTest $= Enabled - stencilOpSeparate Front $= (OpKeep, OpKeep, OpIncrWrap) - stencilOpSeparate Back $= (OpKeep, OpKeep, OpDecrWrap) + glBlendFunc GL_ZERO GL_ONE_MINUS_SRC_COLOR + glEnable GL_STENCIL_TEST + --stencilTest $= Enabled + glStencilOpSeparate GL_FRONT GL_KEEP GL_KEEP GL_INCR_WRAP + --stencilOpSeparate Front $= (OpKeep, OpKeep, OpIncrWrap) + --stencilOpSeparate Back $= (OpKeep, OpKeep, OpDecrWrap) + glStencilOpSeparate GL_BACK GL_KEEP GL_KEEP GL_DECR_WRAP flip VFSM.mapM_ (VFSM.fromList lightPoints) $ \(V3 x y z, rad, V3 r g b) -> do - depthFunc $= Just Less + glDepthFunc GL_LESS -- setup stencil - colorMask $= Color4 Disabled Disabled Disabled Disabled - clear [StencilBuffer] - cullFace $= Nothing - stencilFunc $= (Always, 0, 255) + glColorMask GL_FALSE GL_FALSE GL_FALSE GL_FALSE + glClear GL_STENCIL_BUFFER_BIT + glDisable GL_CULL_FACE + --cullFace $= Nothing + glStencilFunc GL_ALWAYS 0 255 --draw wall shadows --currentProgram $= Just (_shadProg lwallShad) glUseProgram (_shadProg' lwallShad) @@ -104,7 +103,9 @@ createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos drawCPUSh GL_UNSIGNED_SHORT nullPtr --draw caps on the near plane as required - cullFace $= Just Back + glEnable GL_CULL_FACE + glCullFace GL_BACK + --cullFace $= Just Back --currentProgram $= Just (_shadProg lcapShad) --uniform (_shadUnis lcapShad V.! 0) $= Vector3 x y z glUseProgram (_shadProg' lcapShad) @@ -119,12 +120,14 @@ createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos drawCPUSh CPUObjShads -> drawCPUShadows (V3 x y z) rad _ -> return () --draw lightmap itself - depthFunc $= Just Always + glEnable GL_DEPTH_TEST + glDepthFunc GL_ALWAYS + --depthFunc $= Just Always -- bind world position texture bindTO toPos - colorMask $= Color4 Enabled Enabled Enabled Enabled + glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE --stencilOp $= (OpKeep, OpKeep, OpKeep) - stencilFunc $= (Equal, 0, 255) + glStencilFunc GL_EQUAL 0 255 --currentProgram $= ltextShad ^? shadProg --Just (_shadProg ltextShad) --uniform (_shadUnis ltextShad V.! 0) $= Vector3 x y z --uniform (_shadUnis ltextShad V.! 1) $= Vector4 r g b rad @@ -138,8 +141,8 @@ createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos drawCPUSh 0 (fromIntegral (4 :: Int)) --cleanup: may not be necessary, depending on what comes after... - cullFace $= Nothing - stencilTest $= Disabled + glDisable GL_CULL_FACE + glDisable GL_STENCIL_TEST -- assumes that vertices have already been sent to the shader pingPongBetween ::