Code Snippets
What's That?
I am using it actively
I planning to use/learn it
I don't plan to lean/use it
5th option
Home :: Programming :: Code Snippets :: OpenGL :: gluPerspective Replacement

[ gluPerspective Replacement ]

This should be familiar to you: because you would like to create a hot, little OpenGL demo using a perspective projection you have to use gluPerspective(..) - unless you're one of those rare people that understand the magic behind glFrustrum(..) - and logically link GLU against your application but unfortunately you load the library only to use this little, damn function. Help if here now!

The solution: code your own gluPerspective(..) implementation. Fortunately all this isn't that difficult and if you don't understand the code, be sure, it works! Btw. the code has been partly borrowed from the GLU implementation of Mesa GL. Thanks to them!

//additional includes
#include <math.h>

gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
   GLdouble xmin, xmax, ymin, ymax;

   ymax = zNear * tan(fovy * M_PI / 360.0);
   ymin = -ymax;
   xmin = ymin * aspect;
   xmax = ymax * aspect;

   glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);

I assume you have basic knowledge of how to use this function - otherwise you wouldn't have read this snippet, right? From now on you'll never have to link GLU only for this function. Happy c0ding!

 Last edited 2003-11-12 21:28:53 by André Stein - printable version
» copyright by andré stein
» using stCM v1.0
» steinsoft.net revision 5.0