We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › resetting perspective and camera after endGL()
Page Index Toggle Pages: 1
resetting perspective and camera after endGL() (Read 823 times)
resetting perspective and camera after endGL()
Nov 24th, 2009, 9:33am
 
My Processing app does most of its drawing using straight OpenGL calls and makes adjustments to both the projection and modelview matrices. The trouble is that I'm using the ControlP5 library for some GUI stuff. Before, it was alright to have it draw before all the stuff I do between PGraphicsOpenGL.beginGL() and PGraphicsOpenGL.endGL(), but now I'm drawing a full screen quad in the OpenGL part which will occlude the GUI stuff. I'd like to draw ControlP5 after I finish my OpenGL stuff and turn off depth testing, but something with the matrices is totally off.

After calling PGraphicsOpenGL.endGL(), I call perspective() and camera() thinking that this will reset the matrix stack to how you can expect it to be at the beginning of draw(). Am I missing anything?

-Aaron
Re: resetting perspective and camera after endGL()
Reply #1 - Nov 24th, 2009, 10:09am
 
Try something like this...
Code:
PMatrix3D currCameraMatrix;
PGraphics3D g3;

void setup() {
size(200,200,P3D);
g3 = (PGraphics3D)g;
hint(DISABLE_DEPTH_TEST);
}

void draw(){

currCameraMatrix = new PMatrix3D(g3.camera);
camera(); // Start HUD
fill(255);
rect(10,10,80,30); // End HUD
g3.camera = currCameraMatrix;
}

Re: resetting perspective and camera after endGL()
Reply #2 - Nov 24th, 2009, 10:26am
 
No luck with that solution I'm afraid.
Re: resetting perspective and camera after endGL()
Reply #3 - Nov 24th, 2009, 10:34am
 
I guess a decent solution is to just reset the matrices with the Processing defaults using OpenGL commands before calling endGL().
Code:
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(60, width/(float)height, .1f, 1000f);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
glu.gluLookAt(width/2.0f, height/2.0f, (height/2.0f) / tan(PI*60.0f / 360.0f), width/2.0f, height/2.0f, 0, 0, 1, 0);


Ba-da-boom.
Page Index Toggle Pages: 1