move uniform write into loop

This commit is contained in:
nek0 2020-05-17 17:28:39 +02:00
parent c377d27cb2
commit 01b6134331

View file

@ -141,10 +141,14 @@ main = do
-- -- UNIFORMS
-- get the uniform's location out of the shader program
uniLoc <- get $ GL.uniformLocation sp "u_color"
-- write data to the uniform
GL.uniform uniLoc $= (GL.Color4 1 0.5 0 1 :: GL.Color4 GL.GLfloat)
-- -- get the uniform's location out of the shader program
-- uniLoc <- get $ GL.uniformLocation sp "u_color"
-- -- write data to the uniform
-- GL.uniform uniLoc $= (GL.Color4 1 0.5 0 1 :: GL.Color4 GL.GLfloat)
-- create an MVar for pulsating red channel
red <- newMVar 0
increment <- newMVar 0.05
err <- get GL.errors
print $ "pre-loop errors: " <> show err
@ -171,6 +175,17 @@ main = do
-- clear buffers before drawing
GL.clear [GL.ColorBuffer]
-- throw away previous errors
-- void $ get GL.errors
-- get the uniform's location out of the shader program
uniLoc <- get $ GL.uniformLocation sp "u_color"
-- write data to the uniform
redValue <- takeMVar red
incrementValue <- takeMVar increment
let newRed = redValue + incrementValue
GL.uniform uniLoc $= (GL.Color4 newRed 0.5 0 1 :: GL.Color4 GL.GLfloat)
-- the actual drawing happens here
void $ get GL.errors
GL.drawElements GL.Triangles 6 GL.UnsignedInt nullPtr