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 › perspective() doesn't work in OpenGL
Page Index Toggle Pages: 1
perspective() doesn't work in OpenGL? (Read 871 times)
perspective() doesn't work in OpenGL?
Dec 8th, 2006, 11:37am
 
Hi,

I may be doing something wrong here, but I can't get the perspective() function to work after more than one call using OPENGL in the setup method.


This code works brilliantly (from the website examples), but replacing the "P3D" in the size() function with "OPENGL" breaks it (I see nothing drawn onscreen).  Looking at it further, it seems that the 1st call to perspective works fine, but successive calls result in a blank screen with only the background color.  Does anyone have any advice, or is this a limitation of Processing?


import processing.opengl.*;

void setup() {
 size(400, 400, P3D);
 background(204, 204, 204);
 noStroke();
 frameRate(30);  // set the frame rate
}

void draw()
{
 
 float ctr = 0;
 
 lights();
 background(204);
 float cameraY = height*0.5;
 float fov = (mouseY/float(height) + 0.25) * PI/2;
 float cameraZ = cameraY / tan(fov * 0.5);
 float aspect = float(width)/float(height);
 if(mousePressed) {
   println(fov);
 }
 perspective(fov, aspect, cameraZ*0.1, cameraZ*10.0);
 
 translate(0,40,0);
 
 for (ctr=0; ctr <= 25; ctr++)
 {
   box(width*0.025, 200, 20);
   translate(4.0*width*0.01, 0, 0);
 }
}
Re: perspective() doesn't work in OpenGL?
Reply #1 - Dec 8th, 2006, 6:51pm
 
perspective() is actually handled by P3D, and the coordinates are passed off to OpenGL.. so the issue is actually that P3D's clipping is less aggressive (some might say "less accurate" or "broken") than OpenGL (which might be called "correct").

soo.. if it works in P3D, the issue is that you're not actually using the perspective properly and things are being drawn outside OpenGL's more accurate clipping planes.
Page Index Toggle Pages: 1