GLUT and MD2

I wrote an md2 class, based on nehe’s. When I goto run it I dont see the md2 but, I see everything else just fine. I read threw the md2 code and im 100% its not that. What is wrong is something with how I set up glut. There is something wrong with the reshape funtion, init, or draw. Ill post all of them.

void init()
{
axy.x = 0.0f;
axy.y = 0.0f;
axy.z = -25.0f;

if(ng.LoadTexture(“jon.bmp”, texture, 0) == 0)
{
cout << "Texture loading failed
";
}

if(ng.LoadTexture(“alien.bmp”, texture, 1) == 0)
{
cout << "Texture loading failed
";
}

    glShadeModel(GL_SMOOTH);                                // Enable Smooth Shading
    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);                   // Black Background
    glClearDepth(1.0f);                                     // Depth Buffer Setup
    glEnable(GL_DEPTH_TEST);                                // Enables Depth Testing
    glDepthFunc(GL_LEQUAL);
    glEnable(GL_LIGHT0);                                    // Quick And Dirty Lighting (Assumes Light0 Is Set Up)
    glEnable(GL_LIGHTING);                                  // Enable Lighting
    glEnable(GL_COLOR_MATERIAL);

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}

static void Reshape(int width, int height)
{
GLfloat h = (GLfloat) height / (GLfloat) width;

glViewport(0, 0, (GLint) width, (GLint) height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -h, h, 5.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, 40.0);
}

static void Draw()
{
static GLfloat move = 0.0;
ng.Clear();

glPushMatrix();

glPushMatrix();
ng.SetColor(RGB(0.0, 1.0, 1.0));
ng.MoveAxis(XYZ(-2.5, 0, -20));
ng.RotateAllAxis(move);
ng.Sphere(0.275, 32, 32);
glPopMatrix();

glPushMatrix();
ng.SetColor(RGB(0.0f, 1.0f, 0.0f));
ng.MoveAxis(XYZ(-2.5, 0, -20));
ng.RotateAxis(XYZ(move + 270, move, move));
ng.WireRing(0.275, 0.85, 10, 30);
glPopMatrix();

glPushMatrix();
ng.SetColor(RGB(0.0f, 0.0f, 1.0f));
ng.MoveAxis(XYZ(-2.5, 0, -20));
ng.RotateAllAxis(move);
ng.WireRing(0.275, 0.85, 10, 30);
glPopMatrix();

glEnable(GL_TEXTURE_2D);

glPushMatrix();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
ng.SetColor(RGB(1.0, 1.0, 1.0));
ng.MoveAxis(XYZ(3.0, 0.0, -60.0));
ng.RotateAllAxis(move);
ng.Cube();
glPopMatrix();

glBindTexture(GL_TEXTURE_2D, texture[1]);
ng.MoveAxis(axy);
glScalef(0.5, 0.5, 0.5);
md2.Animate(md2.StateStart, md2.StateEnd, 0.2);
glBindTexture(GL_TEXTURE_2D, texture[1]);
md2.Animate(md2.StateStart, md2.StateEnd, 0.2);

glFlush();

glDisable(GL_TEXTURE_2D);

move += 1.0f;

glutSwapBuffers();
}

Please help.

Thanks,
Nuke

P.S I am using Linux.

Can’t say for sure what your problem is as I don’t use GLUT. But one thing that I can say is that it is rarely wise to assume anything about bugs in your code i.e. ‘the bug is definitely not in module x’. These assumptions have a nasty habit of biting you in the ass.

Kevin

You assume that it is something with the way you setup glut, yet you show almost NO glut code. I kind of doubt that glut is your problem anyway, but the SETUP portion of glut is done in the main function. The only glut function I’m even seeing in your code is glutSwapBuffers.

A couple of odd things that I do see wrong with your GL code:

  • You appear to have a glPushMatrix without a matching glPopmatrix in your display function. The very first glPushMatrix never seems to get popped.
  • I assume this is probably what is supposed to be popped, but the way your glScalef is before the md2.Animate, you’ll be scaling it smaller and smaller every frame.
  • What is the center of your model? In your reshape you set the near/far planes at 5-1000. And then for the modelview, you do a translate of 40 in the z axis. Your 0,0,0 point is now essentially 45 units in FRONT of your near clip plane. Are you sure you didn’t mean to use -40 here?