I’m trying to take NeHe’s tuts and write my own classes based on them. I’m working on a class for a Font and for a Flyer (the player in my little game). Everything compiles, but neither my font nor my flyer is displayed on the screen.
//Here’s the flyer class:
class CFlyer {
public:
CFlyer();
GLvoid Draw();
GLvoid SetPos( GLfloat xpos, GLfloat ypos, GLfloat zpos );
private:
XYZType pos;
RGBType color;
GLuint flyer;
};
CFlyer::CFlyer() {
flyer = glGenLists(1);
glNewList( flyer, GL_COMPILE );
glBegin(GL_TRIANGLES);
// Front
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 1.0f);
glVertex3f( 1.0f,-1.0f, 1.0f);
// Right
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 1.0f);
glVertex3f( 1.0f,-1.0f,-1.0f);
// Back
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
// Left
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glVertex3f(-1.0f,-1.0f, 1.0f);
glEnd();
glEndList();
pos.x = 0.0f;
pos.y = 0.0f;
pos.z = -10.0f; // so its into the screen
color.red = 1.0f;
color.green = 0.5f;
color.blue = 0.5f;
}
GLvoid CFlyer::SetPos( GLfloat xpos, GLfloat ypos, GLfloat zpos ) {
pos.x = xpos;
pos.y = ypos;
pos.z = zpos;
}
GLvoid CFlyer: :Draw() {
glTranslatef( pos.x, pos.y, pos.z );
glCallList( flyer );
glLoadIdentity();
}
Here’s my render loop:
int DrawGLScene(GLvoid) {
glClear GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)glLoadIdentity();
myFlyer.Draw();
return TRUE;
}
Yeah, pretty simple (right now the flyer is just a bottomless pyramid, lol). Eventually I want it to be a physics affected player controllable flying machine, but it has to display first! lol
Now if I just skip the flyer class and it’s corresponding display list all together, and just move the:
glBegin(GL_TRIANGLES)
draw my pyramid
glEnd()
directly into the render loop it works just fine.
Anybody see a gross error in my code? I know all the OpenGL stuff in my engine.h is solid, it’s just when I use classes in this manner they won’t display on the screen.
Thanks in advance!
- = TEFLON DRAGON = -
[This message has been edited by teflon_dragon (edited 03-28-2002).]