From 01b61343312139b5fa0c22bac745fc0980141a36 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sun, 17 May 2020 17:28:39 +0200 Subject: [PATCH] move uniform write into loop --- src/Main.hs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index cf1d9d0..382c16e 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -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