Hi guys,

An assignment I’m doing requires that we implement our own matrice and vector classes, etc so we can draw in software mode (using SDL, if it’s relevant), using everything in OpenGL as a base and implementing it ourselves.

I’m almost finished, but the last part of the assignment deals with frustums and has me stumped. Here’s the instructions:

6.2.3 Projection Transformation

There are two parts to this. First, we transform the polygon into the clip coordinates

with a perspective frustum. This page has a good picture:

http://www.songho.ca/opengl/gl_projectionmatrix.html#perspective

Once we have the frustum, we normalise so that X, Y, and Z all range from -1 to 1, which

is called the Normalised Device Coordinates (NDC).

The two steps:

- Apply Perspective transform to each of the vertices in the triangle
- Divide x, y, and z by the w value of the vector.

To me, this implies that we should be constructing our frustum and transforming the polygon into the clip coords every frame, which I’m sure isn’t correct, as I’m lead to believe that frustums are constructed in the projection matrix at the very beginning of your program and aren’t altered. I’m confused because we also have to construct our own perspective matrix, so the two are supposed to somehow co-exist.

So here’s the gist of what I think I’m supposed to be doing (according to the instructions)

initialisation (called once):

matrix mode to projection

load identity matrix

glMultMatrix perspective matrix (equilavent to gluPerspective)

matrix mode to model view

load identity

glMultMatrix look at

render (called repeatedly):

matrix mode to model view

glpushmatrix

transformations (translations, rotations, etc.) on an Object

glpopmatrix

matrix mode to projection

glpushmatrix

glMultMatrix frustum (of my own creation)

normalise x, y and z of Object using frustum

map the Object’s x and y coords to the pixels (0 - width, 0 - height)

glpopmatrix

But I’m really not sure about this because as I said, I don’t think it’s good practice to change the mode to the projection matrix every time rendering occurs. I know I’m asking a lot here but I’m really unsure, so if you guys could at least tell me if I’m going wrong and where, that would be awesome.

Thanks heaps.