#include #include #include #include "disc.h" // The pre-allocated number of our display list const int DISC_DISPLAY_LIST = 3; // The disc radius currently cached in our display list double disc_list_radius = 0.0; void disc::draw(double x, double y, double r) { glPushMatrix(); // Move to the specified location glTranslatef(x, y, 0.0001); // Have we cached this radius if ((r == disc_list_radius) && (glIsList(DISC_DISPLAY_LIST) == GL_TRUE)) { // Yes, just call the display list glCallList(DISC_DISPLAY_LIST); } else { // Nope, make a new quadric object GLUquadricObj *quad = gluNewQuadric(); // Make a new display list glNewList(DISC_DISPLAY_LIST, GL_COMPILE_AND_EXECUTE); // Draw the disc gluDisk(quad, 0.0, r, 10, 1); // End the display list glEndList(); // Update the cached value disc_list_radius = r; // Delete the quadric object gluDeleteQuadric(quad); } glPopMatrix(); }