Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
skulpt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mohcine Chraibi
skulpt
Commits
9b7781e3
Commit
9b7781e3
authored
Apr 23, 2013
by
David Holmes
Browse files
Options
Downloads
Patches
Plain Diff
Basic WebGL with example.
parent
2121e18b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
example/webgl/webgl-0001-basic.html
+91
-0
91 additions, 0 deletions
example/webgl/webgl-0001-basic.html
src/lib/webgl/__init__.js
+188
-380
188 additions, 380 deletions
src/lib/webgl/__init__.js
with
279 additions
and
380 deletions
example/webgl/webgl-0001-basic.html
0 → 100644
+
91
−
0
View file @
9b7781e3
<!doctype html>
<html>
<head>
<meta
charset=
"utf-8"
>
<title>
WebGL
</title>
<style
type=
"text/css"
>
body
{
background-color
:
grey
;}
canvas
{
background-color
:
white
;}
</style>
<script
src=
"../../dist/skulpt.js"
type=
"text/javascript"
></script>
<script
src=
"../../dist/builtin.js"
type=
"text/javascript"
></script>
</head>
<body>
<h1>
WebGL
</h1>
<form>
<textarea
id=
"code"
name=
"code"
rows=
"40"
cols=
"120"
>
import webgl
gl = webgl.Context("my-canvas")
vs = gl.createShader(gl.VERTEX_SHADER)
gl.shaderSource(vs, "attribute vec3 aVertexPosition; void main(void) { gl_Position = vec4(aVertexPosition, 1.0); }")
gl.compileShader(vs)
print "Vertex shader COMPILE_STATUS: " + str(gl.getShaderParameter(vs, gl.COMPILE_STATUS))
fs = gl.createShader(gl.FRAGMENT_SHADER)
gl.shaderSource(fs, "void main(void) { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); }")
gl.compileShader(fs)
print "Fragment shader COMPILE_STATUS: " + str(gl.getShaderParameter(fs, gl.COMPILE_STATUS))
program = gl.createProgram()
gl.attachShader(program, vs)
gl.attachShader(program, fs)
gl.linkProgram(program)
print "Program LINK_STATUS: " + str(gl.getProgramParameter(program, gl.LINK_STATUS))
gl.useProgram(program)
triangleVertices = [-0.5, 0.5, 0.0,
0.0, 0.0, 0.0,
-0.5, -0.5, 0.0,
0.5, 0.5, 0.0,
0.0, 0.0, 0.0,
0.5, -0.5, 0.0]
trianglesVerticeBuffer = gl.createBuffer()
gl.bindBuffer(gl.ARRAY_BUFFER, trianglesVerticeBuffer)
gl.bufferData(gl.ARRAY_BUFFER, webgl.Float32Array(triangleVertices), gl.STATIC_DRAW)
vertexPositionAttribute = gl.getAttribLocation(program, "aVertexPosition")
gl.enableVertexAttribArray(vertexPositionAttribute)
gl.bindBuffer(gl.ARRAY_BUFFER, trianglesVerticeBuffer)
gl.vertexAttribPointer(vertexPositionAttribute, 3, gl.FLOAT, False, 0, 0)
gl.drawArrays(gl.TRIANGLES, 0, 6)
</textarea>
<button
type=
"button"
onclick=
"runit()"
>
Run
</button>
</form>
<canvas
id=
"my-canvas"
height=
"248"
width=
"400"
>
Your browser does not support the HTML5 canvas element.
</canvas>
<pre
id=
"my-output"
></pre>
<script>
function
outputHandler
(
text
)
{
var
output
=
document
.
getElementById
(
"
my-output
"
);
output
.
innerHTML
=
output
.
innerHTML
+
text
.
replace
(
/</g
,
'
<
'
);
}
function
builtinRead
(
x
)
{
if
(
Sk
.
builtinFiles
===
undefined
||
Sk
.
builtinFiles
[
"
files
"
][
x
]
===
undefined
)
{
throw
"
File not found: '
"
+
x
+
"
'
"
;
}
return
Sk
.
builtinFiles
[
"
files
"
][
x
];
}
function
runit
()
{
var
prog
=
document
.
getElementById
(
"
code
"
).
value
;
// Clear the output
document
.
getElementById
(
"
my-output
"
).
innerHTML
=
''
;
Sk
.
canvas
=
"
my-canvas
"
;
Sk
.
pre
=
"
my-output
"
;
Sk
.
configure
({
"
output
"
:
outputHandler
,
"
read
"
:
builtinRead
});
try
{
eval
(
Sk
.
importMainWithBody
(
"
<stdin>
"
,
false
,
prog
));
}
catch
(
e
)
{
alert
(
e
);
}
}
</script>
</body>
</html>
This diff is collapsed.
Click to expand it.
src/lib/webgl/__init__.js
+
188
−
380
View file @
9b7781e3
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment