I’m trying to use glFrustum() but I’m having mixed results because I
have no idea how the thing works. I’ve read many thing about it, but
yet, I can’t get it to display a model properly. I get mixed results no
matter what numbers I put in, and I just can’t find the logic of it.
There is no glPerpective or glLookAt as you do with Glut, so I assume
that glFrustum() is what needs to be used instead, but can’t get to do
‘Jack’. Can anyone please explain to me how to use glFrustum? All I want
to do is set the FOV and not clip half the model. glTranslatef() I
assume I need to use to pan and zoom by moving the camera right? and
glRotatef() to rotate right? Thanks!
Please log in or register to post a reply.
Did you want
These aren’t part of GLUT, just GLU, which will always be there if
OpenGL is there, so they’re perfectly fine to use in your app.
However, if you want to use glFrustum, try
float halfWidth = tan(0.5 * fovHorizontal);
float halfHeight = tan(0.5 * fovVertical);
glFrustum(-halfWidth, halfWidth, -halfHeight, halfHeight, zNear, zFar);
That’s what gluPerspective does internally (except it calculates
fovHorizontal as aspect * fovVertical), so that should do it.
I use an OpenGL control that doesn’t use Glut/Glu whatever, so glu… is
not available to me, so glFrustum is what I have to use.
so if I have a FOV of 35, how do I get the fovH and fovV? Is FOV
normally horizontal or vertical? fovH = fovV * width / height; but how
to get fovV?
What about the near/far? how do we know what to use? Is it the bbox max
size of the model for zFar? what about zNear?
You have to decide if your FOV of 35 is intended to be the vertical or
horizontal fov, or the max or min fov, or whatever. (Also don’t forget
to convert it from degrees to radians if your trig functions require
Near clip is how close you want the camera to be able get to a polygon
before clipping it. And far clip is how far away you want to be able to
see things before they clip out. You have to decide these too. If the
near clip is too small it will cause Z-fighting and suchlike. For
example, for rendering a human-scale world you might use a near clip of
10 centimeters and a far clip of 10 kilometers.
oh ok! so if I decide that my FOV of 35 is horixontal, then how do I get
about the near/far clipping, do the units are those of the model or
glFrustum uses meteric? Way, if a house is 50’ x 50’ is it safe to set
zNear to 1 and zFar to 51? Because on my end, one of the corner of the
house is at 0,0,0 and I set the zFar to 50 and when I rotate it with
glRotatef() it gets clipped when going away from the eye!?
fovH = tan(degtorad(35)*0.5);
I trired fovV = 2*atan(fovH*(Width/Height)); but now everything is
almost flat ha ha!
halfWidth = tan(0.5 * degtorad(35.0));
halfHeight = halfWidth * height / width;
(or: halfHeight = halfWidth / aspect, if you have the aspect ratio
Got it, thanks once more Reedbeta, you’re a lifesaver :)))
One more thing, does glu32.dll installed by the video driver as part of
OpenGL on Windows systems?
Yes, opengl32.dll and glu32.dll should always be available on Windows.
ok thanks Reedbeta.