glOrtho/gluPerspective/glFrustum ?

  • Follow


I can get glOrtho to work fine in the below snippet of code however why do 
gluPerspective and glFrustum not work. I am attempting to draw an image 
within the _bounds at a depth of 0 however the image only appears when using 
glOrtho.

// Resize drawing viewport

glViewport(_bounds.left, _bounds.top, _bounds.right, _bounds.bottom);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

//glFrustum(_bounds.left,_bounds.right,_bounds.bottom,_bounds.top,0,25);

//gluPerspective(30.0,(_bounds.right-_bounds.left)/(_bounds.bottom-_bounds.top),0.0,25.0);

glOrtho(_bounds.left, _bounds.right, _bounds.bottom, _bounds.top, 0.0, 
25.0);

glMatrixMode(GL_MODELVIEW);


Thanks

PS: I thought the main difference between them was depth related. 


0
Reply slycaper 9/23/2004 5:28:00 PM

slycaper wrote:
> I can get glOrtho to work fine in the below snippet of code however why do 
> gluPerspective and glFrustum not work. I am attempting to draw an image 
> within the _bounds at a depth of 0 however the image only appears when using 
> glOrtho.
> 
> // Resize drawing viewport
> 
> glViewport(_bounds.left, _bounds.top, _bounds.right, _bounds.bottom);
> 
> glMatrixMode(GL_PROJECTION);
> 
> glLoadIdentity();
> 
> //glFrustum(_bounds.left,_bounds.right,_bounds.bottom,_bounds.top,0,25);
> 
> //gluPerspective(30.0,(_bounds.right-_bounds.left)/(_bounds.bottom-_bounds.top),0.0,25.0);

   There could be more than one reason why a perspective projection
would result in a blank screen. The Red Book discusses them pretty clearly.
    The camera could be pointing towards the wrong direction. Think about
the FOV, near - far planes


    near should be really small. may be 0.0001 should help.

    far can be pretty much large, at least to get something in the
viewport in the first place. You can always tune it later.

    Try increasing the FOV.


> 
> glOrtho(_bounds.left, _bounds.right, _bounds.bottom, _bounds.top, 0.0, 
> 25.0);
> 
> glMatrixMode(GL_MODELVIEW);
> 
> 
> Thanks
> 
> PS: I thought the main difference between them was depth related. 

   perspective projection with the camera at infinity is orthographic
projection.

-- 
   Karthik.
0
Reply Karthik 9/23/2004 10:53:10 PM


Hi

u are correct.

U can't have value of zero for near parameter. This is defined along -ve Z
axis. Try to put it as 1 / 2 and check.

that's what i can think of
bye
k

On Thu, 23 Sep 2004, slycaper wrote:

> I can get glOrtho to work fine in the below snippet of code however why do
> gluPerspective and glFrustum not work. I am attempting to draw an image
> within the _bounds at a depth of 0 however the image only appears when using
> glOrtho.
>
> // Resize drawing viewport
>
> glViewport(_bounds.left, _bounds.top, _bounds.right, _bounds.bottom);
>
> glMatrixMode(GL_PROJECTION);
>
> glLoadIdentity();
>
> //glFrustum(_bounds.left,_bounds.right,_bounds.bottom,_bounds.top,0,25);
>
> //gluPerspective(30.0,(_bounds.right-_bounds.left)/(_bounds.bottom-_bounds.top),0.0,25.0);
>
> glOrtho(_bounds.left, _bounds.right, _bounds.bottom, _bounds.top, 0.0,
> 25.0);
>
> glMatrixMode(GL_MODELVIEW);
>
>
> Thanks
>
> PS: I thought the main difference between them was depth related.
>
>
>

0
Reply Ketan 9/23/2004 11:22:49 PM

"Ketan Mehta" <km223@CSE.MsState.Edu> wrote in message 
news:Pine.GSO.4.33.0409231821250.1007-100000@disney.cs.msstate.edu...
> U can't have value of zero for near parameter. This is defined along -ve Z
> axis. Try to put it as 1 / 2 and check.

Right, a near plane value of 0 is definitely illegal.

However, the original poster said he's trying to draw an object at 0 (at the 
origin), but didn't say what camera transform was being used. In an 
orthographic projection, the eye is at infinity, so anything within the 
glOrtho volume will be displayed. With a perspective projection, eye 
position is important. If you're not specifying a camera transform 
(modelview matrix is identity), then your eye is effectively at the 
origin -- the same place where your geometry is! So that would also cause 
things to not render correctly.
   -Paul 


0
Reply Paul 9/24/2004 12:09:06 AM

My draw method is this:

void DrawCircle(void)

{

GLfloat radius = 20.0;

GLfloat x = static_cast<GLfloat>(GetX());

GLfloat y = static_cast<GLfloat>(GetY());

glLoadIdentity();

glPushMatrix();

glColor3f(0.2f,0.4f,0.7f);

glTranslatef(x,y,0.0f);

glBegin(GL_TRIANGLE_FAN);

for(int i = 0; i < 360; i++)

{

GLfloat x1 = static_cast<GLfloat>(cos(i*M_PI/180));

GLfloat y1 = static_cast<GLfloat>(sin(i*M_PI/180));

glNormal3f(radius*x1,radius*y1,0.0f);

glVertex3f(radius*x1,radius*y1,0.0f);

}

glEnd();


glPopMatrix();

}

GetX() & GetY() are simply cursor position values. I've changed my 
perspective to be:

gluPerspective(90.0,1.0,10,1000.0);

and it still doesn't work. Does zNear value 10 mean that the 'z' value for 
the object should be -10 units back into the screen before it will be seen. 
And no, I didn't set camera position yet. Should I be using gluLookAt?



Thanks


"Paul Martz" <pmartz 'at' frii.com> wrote in message 
news:41536597$0$207$75868355@news.frii.net...
> "Ketan Mehta" <km223@CSE.MsState.Edu> wrote in message 
> news:Pine.GSO.4.33.0409231821250.1007-100000@disney.cs.msstate.edu...
>> U can't have value of zero for near parameter. This is defined along -ve 
>> Z
>> axis. Try to put it as 1 / 2 and check.
>
> Right, a near plane value of 0 is definitely illegal.
>
> However, the original poster said he's trying to draw an object at 0 (at 
> the origin), but didn't say what camera transform was being used. In an 
> orthographic projection, the eye is at infinity, so anything within the 
> glOrtho volume will be displayed. With a perspective projection, eye 
> position is important. If you're not specifying a camera transform 
> (modelview matrix is identity), then your eye is effectively at the 
> origin -- the same place where your geometry is! So that would also cause 
> things to not render correctly.
>   -Paul
> 


0
Reply slycaper 9/24/2004 3:30:57 PM

4 Replies
702 Views

(page loaded in 0.07 seconds)

Similiar Articles:







7/24/2012 2:49:34 PM


Reply: