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!
glFrustum problem!
Started by Alienizer, Mar 21 2012 11:36 PM
10 replies to this topic
#1
Posted 21 March 2012 - 11:36 PM
#2
Posted 21 March 2012 - 11:48 PM
Did you want gluPerspective or gluLookAt? 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
That's what gluPerspective does internally (except it calculates fovHorizontal as aspect * fovVertical), so that should do it.
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.
reedbeta.com - developer blog, OpenGL demos, and other projects
#3
Posted 22 March 2012 - 12:13 AM
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?
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?
#4
Posted 22 March 2012 - 12:32 AM
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 radians.)
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.
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.
reedbeta.com - developer blog, OpenGL demos, and other projects
#5
Posted 22 March 2012 - 12:48 AM
oh ok! so if I decide that my FOV of 35 is horixontal, then how do I get fovV?
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!?
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!?
#6
Posted 22 March 2012 - 01:02 AM
fovH = tan(degtorad(35)*0.5);
I trired fovV = 2*atan(fovH*(Width/Height)); but now everything is almost flat ha ha!
I trired fovV = 2*atan(fovH*(Width/Height)); but now everything is almost flat ha ha!
#7
Posted 22 March 2012 - 03:32 AM
Just do
halfWidth = tan(0.5 * degtorad(35.0));
halfHeight = halfWidth * height / width;
(or: halfHeight = halfWidth / aspect, if you have the aspect ratio handy)
halfWidth = tan(0.5 * degtorad(35.0));
halfHeight = halfWidth * height / width;
(or: halfHeight = halfWidth / aspect, if you have the aspect ratio handy)
reedbeta.com - developer blog, OpenGL demos, and other projects
#8
Posted 22 March 2012 - 03:42 AM
Got it, thanks once more Reedbeta, you're a lifesaver
))
#9
Posted 22 March 2012 - 01:29 PM
One more thing, does glu32.dll installed by the video driver as part of OpenGL on Windows systems?
#10
Posted 22 March 2012 - 04:50 PM
Yes, opengl32.dll and glu32.dll should always be available on Windows.
reedbeta.com - developer blog, OpenGL demos, and other projects
#11
Posted 22 March 2012 - 05:22 PM
ok thanks Reedbeta.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












