Variable Sketch Size in 3D
in
Processing with Other Languages
•
1 month ago
I'm using processing.js in an HTML5 canvas on a web page and basically the canvas/sketch size will be variable, changing on page resize. With 2D I've been able to do this easily by placing size(setWidth,setHeight); in draw() where setWidth and setHeight hold the size of the web page.
With 3D however it's a bit different.
- float rotx = -PI/10;
- float roty = PI/10;
- void draw() {
- size(setWidth, setHeight, OPENGL);
- background(0);
- pushMatrix();
- translate(width/2,height/2);
- rotateX(rotx);
- rotateY(roty);
- box(50);
- popMatrix();
- }
The above code throws the error Uncaught TypeError: Object #<Object> has no method 'rotateX' and the sketch seems to execute draw() only once and the box is never drawn. If size(setWidth, setHeight, OPENGL); is taken out of draw and used in setup everything works fine, but since size is only executed once it's not fluid like I need.
I also tried putting size(setWidth, setHeight, OPENGL); in both setup() and draw() but this throws the error Uncaught Multiple calls to size() for 3D renders are not allowed.
So my real question is how can I get the sketch size to change to a variable within draw() using a 3D render?
1