Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
I
Idris Webgl
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
8
Issues
8
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Oscar Leijendekker
Idris Webgl
Commits
f271e41d
Commit
f271e41d
authored
Jan 08, 2021
by
Oscar Leijendekker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added most basic animation. Resolves issue
#7
.
parent
ba468b72
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
10 deletions
+16
-10
JSFFI.idr
JSFFI.idr
+9
-2
main.idr
main.idr
+7
-8
No files found.
JSFFI.idr
View file @
f271e41d
...
...
@@ -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)
main.idr
View file @
f271e41d
...
...
@@ -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)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment