We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Based on this thread
http://forum.processing.org/one/topic/set-3-viewports-from-3-camera-s-pointing-the-same-object.html
I was trying to understand the code by @amnon making 4 viewports. My real goal are 6, with specific sizes.
Questions:
1 - When using viewports are the coordinates inverted? Beginning from lower left corner?
2- Why this code (below) do not work as expected? Although the coordinates are right (either coord system) One of the viewports is always in the wrong place behind another? They seams to kind of interact. If you try with one the result is different than when you make more of them... Does any one know what is going on?
3- Is this using direct openGl commands? I think not, because the viewport()
command is in PGL
javadoc... But glViewport seams to de pure openGL... So... where am I? Where to go for the API?
Thanks a lot.
ps: the code linked above need this updates to run, as far as I could find out: PGL gl;
and in setup: PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
PGL gl;//
float rot;
void setup() {
size(900, 900, OPENGL); //<>//
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
gl = pgl.beginPGL();
colorMode(RGB, 1);
stroke(1, 1, 1);
strokeWeight(2.5);
}
void draw() {
background(1, 1, 1);
rot+=0.005;
// - -
// 0 -
gl.viewport (0, 0, 450, 450);
perspective(PI/6, (float) width/height, 1, 10000);
camera(-400, 200, -700, 0, 0, 0, 0, 1, 0);
renderGeometry();
//- 0
//- -
gl.viewport (450, 450, 450, 450);
perspective(PI/6, (float) width/height, 1, 10000);
camera(-400, 200, 1710, 0, 0, 0, 0, 1, 0);
renderGeometry();
// if alone will be the upper left, but
// it is behind the next, lower right???__________<<<<<<< !!
//0 -
//- -
gl.viewport (0, 450, 450, 450);
perspective(PI/6, (float) width/height, 1, 10000);
camera(200, -400, 2000, 0, 0, 0, 0, 1, 0);
renderGeometry();
// - -
// - 0
gl.viewport (450, 0, 450, 450);
perspective(PI/6, (float) width/height, 1, 10000);
camera(300, 300, 200, 0, 0, 0, 0, 1, 0);
renderGeometry();
}
void renderGeometry() {
pushMatrix();
scale(60);
rotateX(rot);
rotateY(rot);
beginShape(QUADS);
fill(0, 1, 1, 0.6);
vertex(-1, 1, 1);
fill(1, 1, 1, 0.6);
vertex( 1, 1, 1);
fill(1, 0, 1, 0.6);
vertex( 1, -1, 1);
fill(0, 0, 1, 0.6);
vertex(-1, -1, 1);
fill(1, 1, 1, 0.6);
vertex( 1, 1, 1);
fill(1, 1, 0, 0.6);
vertex( 1, 1, -1);
fill(1, 0, 0, 0.6);
vertex( 1, -1, -1);
fill(1, 0, 1, 0.6);
vertex( 1, -1, 1);
fill(1, 1, 0, 0.6);
vertex( 1, 1, -1);
fill(0, 1, 0, 0.6);
vertex(-1, 1, -1);
fill(0, 0, 0, 0.6);
vertex(-1, -1, -1);
fill(1, 0, 0, 0.6);
vertex( 1, -1, -1);
fill(0, 1, 0, 0.6);
vertex(-1, 1, -1);
fill(0, 1, 1, 0.6);
vertex(-1, 1, 1);
fill(0, 0, 1, 0.6);
vertex(-1, -1, 1);
fill(0, 0, 0, 0.6);
vertex(-1, -1, -1);
fill(0, 1, 0, 0.6);
vertex(-1, 1, -1);
fill(1, 1, 0, 0.6);
vertex( 1, 1, -1);
fill(1, 1, 1, 0.6);
vertex( 1, 1, 1);
fill(0, 1, 1, 0.6);
vertex(-1, 1, 1, 0.6);
fill(0, 0, 0);
vertex(-1, -1, -1, 0.6);
fill(1, 0, 0);
vertex( 1, -1, -1, 0.6);
fill(1, 0, 1);
vertex( 1, -1, 1, 0.6);
fill(0, 0, 1);
vertex(-1, -1, 1, 0.6);
endShape();
popMatrix();
}
Answers
Bumping! Where are you GL experts??? [-O< ^:)^
I can't say I'm sure why this happened, but in your case, you now have to place the
gl.viewport()
call for every shape after therenderGeometry()
call of every shape. That would explain why you see 2 shapes in one of the viewports.I.e, this:
V.S. this:
Genius!! Thanks very much!!! ^:)^
For the records, here the updated, working code:
Have I said thank you? Thank you!
:)