# How gluPerspective( ) should be used?

Hello

I want to ask question related to gluPerspective() function. We use gluPerspective() function in opengl for the persective projection.I can know the extents of my scene in z direction by the parameter 'far' and 'near' of this function. But what about extents in x direction and y direction. I mean how can I know that a given parameter will lie in my view volume or not.

For example if I use gluPerspective like this

gluPerspective( 45.0, aspect, 1.0, 20.0 );

and in my draw function if I write the following set of code

glBegin( GL_TRIANGLES );
glVertex2f( -0.5f, -0.5f, -10.0 );
glVertex2f( 0.5f, -0.5f, -10.0 );
glVertex2f( 0.0f, 0.5f, -10.0 );
glEnd();

How can i confirm that this triangle will lie in my viewing volume created by gluPerspective.

Thanks

• gluPerspective is used to setup perspective projection. So in effect its done once to setup how the scene will be rendered. If gluPerspective is used - perspective correction will happen while rendering. If glOrtho is used it will render on 1:1 basis ie it will not do any perspective correction and objects which are far will be of the same size as that of objects that are near. They wont become smaller as they go far.

For what you want to do, you can do frustum culling to determine that. Frustum culling essentially does what you want to do. How to achieve this is as simple as

1. Check if the z is more than the far plane value. If yes it cant be rendered. For eg:- if far = 50, anything with z < -50 ie z=-51 and more will not be rendered
2. Check if the z is less than near plane value. For eg:- near = 1, then anything above -1 will not render. So if z = 0 or z > 0 its outside the viewing volume
3. Create a plane equation for left quad. Check if the triangle is inside the plane or not.
4. Create a plane equation for right quad. Check if the triangle is inside or outside the plane.
Same goes for top and bottom.

If any one fails its outside the viewing volume.

This may be of more use as well
http://www.sjbaker.org/steve/omniv/frustcull.html

: Hello
:
: I want to ask question related to gluPerspective() function. We use gluPerspective() function in opengl for the persective projection.I can know the extents of my scene in z direction by the parameter 'far' and 'near' of this function. But what about extents in x direction and y direction. I mean how can I know that a given parameter will lie in my view volume or not.
:
: For example if I use gluPerspective like this
:
: gluPerspective( 45.0, aspect, 1.0, 20.0 );
:
:
:
: and in my draw function if I write the following set of code
:
: glBegin( GL_TRIANGLES );
: glVertex2f( -0.5f, -0.5f, -10.0 );
: glVertex2f( 0.5f, -0.5f, -10.0 );
: glVertex2f( 0.0f, 0.5f, -10.0 );
: glEnd();
:
:
: How can i confirm that this triangle will lie in my viewing volume created by gluPerspective.
:
: Thanks
:
: