help with viewports

i’m making a CAD-style level editor with the conventional 4-viewports. i’m having a problem with gluUnProject (if that is what i should be using) i use my window w & h and create 4 viewports for each one, and setting up the projection matrix, yada yada yada…thats easy. i want to lay a grid over each viewport. so for each viewport, i use gluUnProject with the viewports’ corners to find the world coords to create my grid! <whew> is there an easier way? also the first 3 coords to gluUnProject (winx, winy, winz) theses are the window coords to be used to find 3 world coords. by passing 0 in for winz, i got crappy output. should this be >0? one more…i have a viewport class that sets up the projection, which is where i want to draw my grid…would the following work?

glViewport(m_iOriginX, m_iOriginY, m_iWidth, m_iHeight);
gluPerspective(45.0, m_fAspect, 0.01, 1000.0);
gluLookAt(m_fEye.x, m_fEye.y, m_fEye.z, m_fAt.x, m_fAt.y, m_fAt.z, m_fUp.x, m_fUp.y, m_fUp.z);
getCoords(); // <- gluUnProject crap in here

GLdouble model[16];
GLdouble proj[16];
GLint viewport[4];
glGetDoublev(GL_MODELVIEW_MATRIX, model);
glGetDoublev(GL_PROJECTION_MATRIX, proj);
glGetIntegerv(GL_VIEWPORT, viewport);
gluUnProject(m_iOriginX, m_iOriginY, 0, model, proj, viewport, &ll.x, &ll.y, &ll.z); // lower left corner
// gluUnProject for lr, ul, ur corners

then taking ll, ul, lr, and ur, a grid can be created (depending on how much the user has zoomed in/out and the grid spacing selected)

my problem is in the first code snippet. am i getting the coordinates in the right order (after the call to gluLookAt) and should i be drawing the grid immediately after? any help would be greatly appreciated.


“You know…when you think about it,
mud is really nothing but dirt and water.”
- Homer Simpson

that looks right to me…maybe a push/pop around your geometry.

i fixed it…the problem was in my call to gluUnProject to get the window corners. i was passing in the relative width and height values instead of the absolute values (duh!)