PDA

View Full Version : How to use glFrustumf?



anime.igala.net
07-09-2008, 08:42 AM
Hello all,

I would like to make my scene always "fit to screen", I mean my scene is as big as possible but the user always can see my entire scene.

I don't know how to use glFrustumf to do this.

Thanks all,

knackered
07-09-2008, 12:43 PM
it's in the wiki, which is referenced at the top of every single forum.
http://www.opengl.org/wiki/index.php/Vie...d_up_vector..29 (http://www.opengl.org/wiki/index.php/Viewing_and_Transformations#How_can_I_automaticall y_calculate_a_view_that_displays_my_entire_model.3 F_.28I_know_the_bounding_sphere_and_up_vector..29)

anime.igala.net
07-11-2008, 03:54 AM
please see this thread: http://www.opengl.org/discussion_boards/...0949#Post240949 (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Main=47411&Number=240949#Post240949)


I have tried this, but i cannot see anything on the screen. My current code is:


glClearColor (0.f,0.f,0.f,1.f);
glMatrixMode (GL_PROJECTION);
glFrustumf (-100.f,1000.f,-1000.f,500.f,3.f,300.f);
glMatrixMode (GL_MODELVIEW);
glShadeModel (GL_SMOOTH);
glTranslatef (-1400.f, 1000.f, -3.f);
glScalef(2.0, 2.0, 2.0);
glColor4f(0,1,0,1);

DrawScene();




The code that i CANNOT see anything on the screen:




glClearColor (0.f,0.f,0.f,1.f);

float diam = 1000;
float zNear = 3.f;
float zFar = zNear + diam;

int cx = 0, cy = 0;

float left = cx - diam;
float right = cx + diam;
float bottom = cy - diam;
float top = cy + diam;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

float aspect = (float) iScreenWidth / iScreenHeight;

if ( aspect < 1.0 ) { // window taller than wide
bottom /= aspect;
top /= aspect;
} else {
left *= aspect;
right *= aspect;
}

//glOrtho(left, right, bottom, top, zNear, zFar);
glOrthof(left, right, bottom, top, zNear, zFar);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glColor4f(0,1,0,1);