Permalink
Browse files

converted triangle.cc to triangle.js (not functional)

  • Loading branch information...
1 parent 305653d commit 77915e2bc94e1657d6468da17ef1948812abf2da @tmpvar committed Aug 20, 2011
Showing with 714 additions and 455 deletions.
  1. +4 −4 bin/SConstruct
  2. +4 −4 example/SConstruct
  3. +181 −7 example/js/main.cc
  4. +61 −3 example/triangle.js
  5. +2 −1 src/SConstruct
  6. +268 −240 src/js/spidermonkey.cc
  7. +194 −196 src/js/spidermonkey.h
View
@@ -11,10 +11,10 @@ spidermonkey_includes = spidermonkey_src
FRAMEWORKS = ['OpenGL', 'GLUT']
-Program('triangle', 'triangle.cc',
- LIBS = [webgl],
- FRAMEWORKS = FRAMEWORKS
- )
+#Program('triangle', 'triangle.cc',
+# LIBS = [webgl],
+# FRAMEWORKS = FRAMEWORKS
+# )
# Configure spidermonkey
if not path.isfile(path.join(spidermonkey_src, 'Makefile')):
View
@@ -11,10 +11,10 @@ spidermonkey_includes = spidermonkey_src
FRAMEWORKS = ['OpenGL', 'GLUT']
-Program('triangle', 'triangle.cc',
- LIBS = [webgl],
- FRAMEWORKS = FRAMEWORKS
- )
+#Program('triangle', 'triangle.cc',
+# LIBS = [webgl],
+# FRAMEWORKS = FRAMEWORKS
+# )
# Configure spidermonkey
if not path.isfile(path.join(spidermonkey_src, 'Makefile')):
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,3 +1,61 @@
-console.log('a');
-fail();
-console.log('b');
+var WebGLRenderingContext = require('lib/webctx.js');
+
+var ctx = new WebGLRenderingContext();
+var program = gl->createProgram();
+var shaders = {
+ vertex : "attribute vec3 pos;\nvoid main() {\n gl_Position = vec4(pos, 1.0);\n}",
+ frag : "void main() {\n gl_FragColor = vec4(1.0, 0, 1, 1.0);\n}"
+};
+
+var vertexShader = ctx.createShader(ctx.VERTEX_SHADER);
+var fragShader = ctx.createShader(ctx.FRAGMENT_SHADER);
+
+ctx.shaderSource(vertexShader, shaders.vertex);
+ctx.shaderSource(fragShader, shaders.frag);
+
+ctx.compileShader(vertexShader);
+ctx.compileShader(fragShader);
+
+ctx.attachShader(program, vertexShader);
+ctx.attachShader(program, fragShader);
+ctx.linkProgram(program);
+
+if (!ctx.getProgramParameter(program, ctx.LINK_STATUS)) {
+ console.log("Could not link program");
+ fail();
+}
+
+ctx.useProgram(program);
+var attr = glGetAttribLocation(program, "pos");
+var vertexBuffer = ctx.createBuffer();
+
+vertexBuffer.itemSize = 3;
+vertexBuffer.numItems = 3;
+
+/*
+ const float vertexPositions[] = {
+ 0.75f, 0.75f, 0.0f, 1.0f,
+ 0.75f, -0.75f, 0.0f, 1.0f,
+ -0.75f, -0.75f, 0.0f, 1.0f,
+ };
+*/
+
+var vertices = [
+ 0.0, 1.0, 0.0,
+ -1.0, -1.0, 0.0,
+ 1.0, -1.0, 0.0
+];
+
+ctx.bindBuffer(ctx.ARRAY_BUFFER, vertexBuffer);
+ctx.bufferData(ctx.ARRAY_BUFFER, new Float32Array(vertexBuffer));
+
+
+setInterval(function() {
+ ctx.clearColor(0.5, 0.5, 0.5, 1);
+ ctx.clear(ctx.COLOR_BUFFER_BIT, DEPTH_BUFFER_BIT);
+ ctx.bindBuffer(ctx.ARRAY_BUFFER, buffer);
+ ctx.enableVertexAttribArray(attr);
+ ctx.vertexAttribPointer(attr, vertexBuffer.itemSize, ctx.FLOAT, false, 0, 0);
+ ctx.drawArrays(ctx.TRIANGLES, 0, 3);
+ ctx.flush();
+}, 10);
View
@@ -10,8 +10,9 @@ env = Environment(
)
sources = Glob('*.cc')
+sources.extend(Glob('js/*.cc'))
sources.extend(Glob('dom/*.cc'))
-sources.extend(Glob('typedarray/*.cc'))
+#sources.extend(Glob('typedarray/*.cc'))
env.StaticLibrary('WebGL', sources)
Oops, something went wrong.

0 comments on commit 77915e2

Please sign in to comment.