Commit f271e41d authored by Oscar Leijendekker's avatar Oscar Leijendekker

Added most basic animation. Resolves issue #7.

parent ba468b72
......@@ -14,6 +14,13 @@ export
JSNative String where
asAnyPtr = prim__anyType_string
%foreign "browser:lambda: i => i"
prim__anyType_int : Int -> AnyPtr
export
JSNative Int where
asAnyPtr = prim__anyType_int
%foreign "browser:lambda: () => true"
prim__jsTrue : AnyPtr
......@@ -30,10 +37,10 @@ consoleLog val = primIO $ prim__console_log $ asAnyPtr val
%foreign "browser:lambda: callback => {window.requestAnimationFrame(x=>callback(x)())}"
prim__requestAnimationFrame : (AnyPtr -> PrimIO ()) -> PrimIO ()
prim__requestAnimationFrame : (Double -> PrimIO ()) -> PrimIO ()
export
requestAnimationFrame : HasIO io => (AnyPtr -> IO ()) -> io ()
requestAnimationFrame : HasIO io => (Double -> IO ()) -> io ()
requestAnimationFrame callback =
primIO $ prim__requestAnimationFrame (\ptr => toPrim $ callback ptr)
......@@ -12,26 +12,25 @@ record Drawable where
aLocation : AttribLocation
uLocation : WebGLUniformLocation
drawTriangle : GLContext -> Drawable -> Int -> IO ()
drawTriangle : GLContext -> Drawable -> Double -> IO ()
drawTriangle gl obj time = do
WebGL2.useProgram gl obj.program
WebGL2.enableVertexAttribArray gl obj.aLocation
WebGL2.bindBuffer gl GL_ARRAY_BUFFER obj.buffer
WebGL2.vertexAttribPointer gl obj.aLocation 2 FLOAT False 0 0
scaleData <- float32Array [0.5]
scaleData <- float32Array [sin $ time / 200.0]
WebGL2.uniform1fv gl obj.uLocation scaleData 0 1
WebGL2.drawArrays gl TRIANGLES 0 3
loop : WebGL2.GLContext -> Drawable -> IO ()
loop gl obj = do
loop : WebGL2.GLContext -> Drawable -> Double -> IO ()
loop gl obj time = do
WebGL2.clearColor gl 0 0 0 1
WebGL2.clear gl
drawTriangle gl obj 0
requestAnimationFrame (\ptr => loop gl obj)
drawTriangle gl obj time
requestAnimationFrame (loop gl obj)
createShaderFromSource : HasIO io => WebGL2.GLContext -> WebGL2.GLShaderType -> String -> io WebGL2.GLShader
......@@ -92,4 +91,4 @@ main : IO ()
main = do
gl <- WebGL2.initGL
obj <- makeTriangle gl
loop gl obj
requestAnimationFrame (loop gl obj)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment