glFrustum ?

I’m wondering how glFrustum works.

Let’s say, I set a projection matrix using

gluPerspective(60,(640/480),0.1,400)

How would a call to glFrustum that creates
the same projection matrix look like ?

regards
Ann

Ok, I’l give it a try…

n=near clipping plane
f=far clipping plane
a=aspect ratio

l=-1ntan((afov)/2)
r=far
tan((afov)/2)
b=-1
ntan(fov/2)
t=far
tan(fov/2)

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( ) 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??

Gorg :
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.

regards
Ann

Ann,

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 ?

Regards.

Eric

P.S. : nevertheless, I will be happy if you find a solution to your problem !

Eric :

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

if the result is a cool 4k intro, it’s
not a waste of time.

regards
Ann

Got your point !

Eric

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.

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

Good point Kaeto. I just usually set a huge zfar for my program (technical reason), so I kind forget about the real truth!

Bob, Hi:

In my understanding, r = -l, and t = -b. I am not sure if it is correct or not to use

r=fartan((afov)/2)

Can you explain why?

[QUOTE]Originally posted by Bob:
[QB]Ok, I’l give it a try…

l=-1ntan((afov)/2)
r=far
tan((afov)/2)
b=-1
ntan(fov/2)
t=far
tan(fov/2)

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.