Using glMultMatrixf w/ glPopMatrix ?

I have an odd problem. My glut application positions some objects in the scene. I do this at init.

Later in the DisplayFinc I attempt to rotate an object but the object never moves. The strange part is that I can use the same commands in init and they work but when called from anywhere else in glut they fail. Seem odd? I debugged the matrix class and watched my rotation’s moving around the unit sphere, I watch the translation values changing but when multiplying the matrix against the world the object never moves from it’s original position\orientation set in init.
So, everything seems to work in init but not in the mail display loop.

Many Thanks

Chris

Some code:

#include “GraphicsLibrary.h”
#include <GL/glut.h>

CMatrix Camera;
CMatrix Tank;
CMatrix Building;
CMatrix Dish;

void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
glEnable(GL_DEPTH_TEST);

//Pull camera back
Tank.Forward(10);
Tank.Yaw(15);

//Position Building
Building.Translate(2,0,0);

//Position Disk above building
Dish.Translate(0,2,0);
}

void display(void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);

//Camera
glMatrixMode(GL_MODELVIEW);
Camera = Tank;
Camera.Invert();
glLoadMatrixf(Camera);

//Update positions
Dish.Yaw(0.2f);

//Transform and Render Objects

//Building
glPushMatrix();
glMultMatrixf(Building);
glutWireCube(2);

  //Dish
  glPushMatrix();
  	glMultMatrixf(Dish);
  	glutWireCone(1,1,10,6);
  glPopMatrix();

glPopMatrix();

glutSwapBuffers();
}

void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void keyboard (unsigned char key, int x, int y)
{
switch (key)
{
case 27:
exit(0);
break;
case ‘w’:
Tank.Forward(1);
break;
// case ‘s’:
// Tank.Backward(1);
// break;
// case ‘a’:
// Tank.StrafeLeft(1);
// break;
// case ‘d’:
// Tank.StrafeRight(1);
// break;

  default:
  	break;

}
}

int main(int argc, char** argv)
{
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (640, 480);
glutCreateWindow (argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

[This message has been edited by gimp (edited 03-08-2001).]

I don’t think this has anything to do with it but shouldn’t it be

glutCreateWindow(GLUT_DEPTH|GLUT_RGB|GLUT_DOUBLE);

my bad I mean

glutInitDisplayMode(GLUT_DEPTH|GLUT_RGB|GLUT_DOUBLE)

Yep it probably should but my init sets depth testing anyway. I poached this code probably from a nate miller demo then modified it…

I made the change and dropped the glEnable… No effect…

I believe you need both…
One is to enable the depth buffer (allocate) and the other is to enable the depth function

The GLUT_DEPTH isn’t really needed if you are compiling under Windows, but it is for Linux. I’ve had this problem bite me in the a$$ when moving things between Windows/Linux.

As for your question, I’m not sure. It looks correct. Is the object you’re referring to not moving the tank? I assume you don’t use glLoadIdentity() anywhere in the tank transformations, and use glMultMatrixf or the corresponding glTranslate/Rotate/Scale functions…