diff options
Diffstat (limited to 'kue/disc.cpp')
-rw-r--r-- | kue/disc.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/kue/disc.cpp b/kue/disc.cpp new file mode 100644 index 00000000..2b6946e5 --- /dev/null +++ b/kue/disc.cpp @@ -0,0 +1,46 @@ +#include <GL/gl.h> +#include <GL/glu.h> + +#include <math.h> + +#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(); +} |