View Full Version : glFrustum ?
I'm wondering how glFrustum works.
Let's say, I set a projection matrix using
How would a call to glFrustum that creates
the same projection matrix look like ?
Ok, I'l give it a try...
n=near clipping plane
f=far clipping plane
glFrustum(l, r, b, t, n, f)
Based on what I know (think it is), please say if it works or not. To get the matrix, just look on the web/in a book and see how to calculate each element with l, r, b, t, n and f.
Also, be sure use radians when calling the standard C-function tan(), since you specify fov in gluPerspective in degrees.
[This message has been edited by Bob (edited 05-31-2000).]
You have to first give you somekind of world proportion :
Let's say that when something is 1 meters away from me, an object of 2 meters X 2 meters would fill all my view.
This give those parameters :
zNear = 1;
top = 1; bottom = -1;
left = -1; right = 1;
Now everyone knows( http://www.opengl.org/discussion_boards/ubb/smile.gif) that because of the way the z-buffer is done, having a zNear of 1 is not really good. So we will set zNear = 10.
to keep our proportions :
zNear = 10;
left = -10; right =10
top = 10
bottom = -10
That is just what there is to it!!! It's just simple proportions. You can even say :
I am blind of the right eye! So the values are :
zNear = 10;
left = -10; right = 5; (5 for right because the two eyes field of view overlap)
top = 10; bottom = -10;
To tell you the truth, I really never understood why people don't understand the view frustum and can work with gluPerspective!!!! I mean, since when working with an angle is easier than with little "standard number" and proportions?? http://www.opengl.org/discussion_boards/ubb/smile.gif
It's because in many OpenGL books
you can read :
"Since glFrustum is soooo difficult to use, we will simply use gluPerspective etcblabla..."
However, for some strange reason I don't feel like linking to glu.dll only because
of one function.
Depending on the type of project you are working on, you might need another VERY useful function from the GLU library : the tesselators...
You know, libraries have been done so that you do not have to reinvent the wheel each time you start a new program...
Of course, you will find how to use glFrustum to obtain the same results than gluPerspective but is worth a waste of time ?
P.S. : nevertheless, I will be happy if you find a solution to your problem !
coding is a hobby of me. currently i'm working on an opengl 4k intro, and i'm happy
for every library i can throw out, since
this will create a (slightly) smaller exe.
believe me, i know what i'm doing, i'm
just new to opengl programming and i know
also what libraries are good for http://www.opengl.org/discussion_boards/ubb/smile.gif
if the result is a cool 4k intro, it's
not a waste of time.
Got your point !
P.S. : it reminds me the good old days when I was coding demos on Atari ST/Falcon030 !
Ann, if you need more clarifications on glFrustum just ask.
Gorg : No, you explained very well how
glFrustum works, thanx.
06-01-2000, 11:38 AM
I want to point out again that having a znear of 1 is not bad unless you have a large zfar. It's the ratio that matters. If you set the znear to 1 and zfar to 10, it's the same as setting znear to 10 and zfar to 100, but scaled. So set it to whatever you need to http://www.opengl.org/discussion_boards/ubb/smile.gif
Good point Kaeto. I just usually set a huge zfar for my program (technical reason), so I kind forget about the real truth! http://www.opengl.org/discussion_boards/ubb/smile.gif
03-27-2005, 04:02 PM
In my understanding, r = -l, and t = -b. I am not sure if it is correct or not to use
Can you explain why?
[QUOTE]Originally posted by Bob:
[QB]Ok, I'l give it a try...
This thread is like 5 years old by now. Good for you I'm still here to answer... 5 years? Don't I have other things to do now? :mad:
Yes, my formula is incorrect. I have learned better since I posted the above. It was based on how I though glFrustum worked, which was slightly wrong.
This is the correct formula.
t = n * tan(fov/2);
b = -t;
r = a*t;
l = -r;Same notation as above.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.