Original Post
OK, I am writing a program in Visual Studio 2005 that has a ball class defined like this:
#ifndef BALL_H_
#define BALL_H_
class ball
{
public :
ball(float r, int g, float re = 1.0, float gr = 1.0, float bl = 1.0, float xpos = 0.0, float ypos = 0.0, float zpos = 0.0);
virtual void draw();
~ball();
private :
protected :
float radius;
int granularity;
float x,y,z;
float red, green, blue;
GLuint BALL;
};
#endif
#include <windows.h> // Header File For Window
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include "ball.h"
ball::ball(float r, int g, float re, float gr, float bl, float xpos, float ypos, float zpos) :
radius(r),
granularity(g),
red(re), green(gr), blue(bl),
x(xpos), y(ypos), z(zpos)
{
GLUquadricObj * tempBall;
tempBall = gluNewQuadric();
BALL = glGenLists(1);
glNewList(BALL, GL_COMPILE);
gluSphere(tempBall, 1.0, granularity, granularity);
glEndList();
gluDeleteQuadric(tempBall);
}
void ball::draw()
{
glPushMatrix();
glColor3f(red, green, blue);
glTranslatef(x, y, z);
glScalef(radius, radius, radius);
glCallList(BALL);
glPopMatrix();
}
ball::~ball()
{
glDeleteLists(BALL,1);
}
And a render function that looks like this:
bool DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity();
glRotatef(-yrot,0.0f,1.0f,0.0f);
glRotatef(-xrot,1.0f,0.0f,0.0f);
glTranslatef(0.0f,0.0f,z);
theBall->draw();
return true;
}
And it won't draw the sqhere. Now, if I put the code to draw the sphere directly in the draw() function it works, but it cannot call the list. I step through the code while running and I can see it does complete the glCallList function, but nothing happens. I've also tried to call the list directly in the DrawGLScene(GLvoid) function and that doesn't work either. Although if I compile a display list in that file and call it in DrawGLScene(GLvoid) it works. Any thoughts on this? This is killing me.