explain please

hi, can anyone explain the sub-program below pls:

void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(65.0, (GLfloat) w/(GLfloat) h, 2.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef (0.0, 0.0, -5.0);
}

Hi !

// Define the viewport, origin will be in
// the lower left corner and the viewport
// will use up all of the window, we tell
// OpenGL to use all of the window area to
// render output into.
glViewport (0, 0, w, h);

// Select projection matrix mode, all matrix
// operations will modify the projection
// matrix
glMatrixMode (GL_PROJECTION);

// Load the projection matrix with an
// identity or unit matrix, this is a matrix
// that does not do anything at all, like
// 1234*1 will still be 1234
glLoadIdentity ();

// We want a perspective projection with a
// view angle of 65 degrees, a smaller
// angler will “zoom” in because a smaller
// area will be displayed in the viewport.
// We set the aspect ratio to w/h, this
// will make sure the a quad that has the
// same width as height will look square.
// The 2.0 is the near clipping plane,
// anything that is closer to the viewer
// then 2.0 will be clipped away, same thing
// with 20.0 but this is the far clipping
// plane, anything beyond that point is
// clipped.
gluPerspective(65.0, (GLfloat) w/(GLfloat) h, 2.0, 20.0);

// Switch to modeview matrix mode.
glMatrixMode(GL_MODELVIEW);

// Load it with an identity matrix.
glLoadIdentity();

// Translate the coordinate system 5
// points along the Z axis.
glTranslatef (0.0, 0.0, -5.0);

Thats it, remember that you cannot move the camera in OpenGL, the camera is always at
0,0,0 looking down the Z axis, so to move things you have to transform the objects instead.

If you have a peek at the FAQ on this website I think you will be able to find lots of useful stuff.

Mikael

what is the different between (GLsizei)w and (GLfloat)w ?

by the way, how can i combine two cubes and make it into one straight line?

thanks

[This message has been edited by always1 (edited 07-16-2002).]

Hi !

the (GLsizei) does not do much, you don’t need it, it’s a typecast fron one interger type to another, but the (GLfloat) is needed to get a floating point result.

100 / 75 = 1
(GLfloat) 100 / (GLfloat) 75 = 1.3333333

That’s the reason for it.

I am not sure what you mean with the cubes ?

Mikael