Permalink
Browse files

implemented working createGraphics 3D with example [#179 state:peer-r…

…eview-requested]
  • Loading branch information...
1 parent c46603a commit 8c8ce89ed29594c504bd82c6e9de8867514f4100 aSydiK committed Jul 5, 2010
@@ -19,7 +19,7 @@
void setup() {
size(200, 200);
- pg = createGraphics(80, 80, P3D);
+ pg = createGraphics(80, 80);
}
void draw() {
@@ -47,7 +47,7 @@
void setup() {
size(200, 200);
- pg = createGraphics(80, 80, P3D);
+ pg = createGraphics(80, 80);
}
void draw() {
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <script src="../../../processing.js"></script>
+ <link rel="stylesheet" href="../../style.css" />
+ </head>
+ <body>
+ <h1>createGraphics() test - 3D</h1>
+
+ <p>
+ <canvas datasrc="createGraphics3D.pjs" height="200" width="200"></canvas>
+ </p>
+
+ <pre>
+PGraphics pg;
+float r = 0;
+
+void setup() {
+ size(200, 200);
+ pg = createGraphics(80, 80, P3D);
+}
+
+void draw() {
+ fill(0, 12);
+ rect(0, 0, width, height);
+ fill(255);
+ noStroke();
+ ellipse(mouseX, mouseY, 60, 60);
+
+ pg.beginDraw();
+ pg.background(255, 0, 0);
+ pg.noFill();
+ pg.stroke(255);
+ pg.pushMatrix();
+ pg.translate(40, 40, 0);
+ pg.rotateY(mouseY);
+ pg.rotateX(mouseX);
+ pg.box(20);
+ pg.popMatrix();
+ pg.endDraw();
+
+ image(pg, 60, 60);
+}
+ </pre>
+ </body>
+</html>
@@ -0,0 +1,29 @@
+PGraphics pg;
+float r = 0;
+
+void setup() {
+ size(200, 200);
+ pg = createGraphics(80, 80, P3D);
+}
+
+void draw() {
+ fill(0, 12);
+ rect(0, 0, width, height);
+ fill(255);
+ noStroke();
+ ellipse(mouseX, mouseY, 60, 60);
+
+ pg.beginDraw();
+ pg.background(255, 0, 0);
+ pg.noFill();
+ pg.stroke(255);
+ pg.pushMatrix();
+ pg.translate(40, 40, 0);
+ pg.rotateY(mouseY);
+ pg.rotateX(mouseX);
+ pg.box(20);
+ pg.popMatrix();
+ pg.endDraw();
+
+ image(pg, 60, 60);
+}
View
@@ -4721,14 +4721,11 @@
if(!p.use3DContext){
return curContext.getImageData(0, 0, this.width, this.height);
} else {
-
- var c = document.createElement('canvas');
- var ctx = c.getContext("2d");
+ var c = document.createElement("canvas");
+ var ctx = c.getContext("2d");
var obj = ctx.createImageData(this.width, this.height);
-
var uBuff = curContext.readPixels(0,0,this.width,this.height,curContext.RGBA,curContext.UNSIGNED_BYTE);
-
- for(var i in uBuff){
+ for(var i =0; i < uBuff.length; i++){
obj.data[i] = uBuff[(this.height - 1 - Math.floor(i / 4 / this.width)) * this.width * 4 + (i % (this.width * 4))];
}

0 comments on commit 8c8ce89

Please sign in to comment.