blob: 2b6946e5bb354fe386bbee052ab4dffabb615e39 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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();
}
|