11 #include <gl\gl.h> // Header File For The OpenGL32 Library
12 #include <gl\glu.h> // Header File For The GLu32 Library
13 #include <gl\glaux.h> // Header File For The Glaux Library
17 static void compilecube(void);
18 static void drawcube(void);
19 static void init_cube(int list_id
);
20 static void rendercube(void);
23 #define CURRENT_OBJECT colorcube
26 // simple objects library
28 DriverObjects colorcube
=
30 init_cube
, // init, must be called first
31 compilecube
, // compile
33 rendercube
, // render to scene
39 // - load anything special about the cube
40 // one important function
42 static void init_cube(int list_id
)
45 CURRENT_OBJECT
.visible
= 0;
47 // store the id through the function
48 // there is probably a better way to do this
49 CURRENT_OBJECT
.call_id
= list_id
;
51 } // end of the functino
53 //=========================================================
54 // draw cube with normals turned on
55 // Note: have to use triangles, (dope!)
56 // - also no particular order when drawing triangles
57 //=========================================================
58 static void drawcube(void)
60 float v
[3][3] = { 0 };
63 // change the size here
64 // Note: starts from ground
66 glBegin(GL_TRIANGLES
);
81 glColor3f(1.0f
,0.0f
,0.0f
);
82 // Calc normal and draw
85 glVertex3fv(v
[2]); // triangle left bottom front
100 // Calc normal and draw
103 glVertex3fv(v
[2]); // triangle left bottom front
105 // Draw the back triangle
106 //-----------------------------
120 glColor3f(1.0f
,1.0f
,0.0f
);
121 // Calc normal and draw
124 glVertex3fv(v
[2]); // triangle left bottom bac
139 // Calc normal and draw
142 glVertex3fv(v
[2]); // triangle left bottom front
144 //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx?
145 // Draw the right side
161 glColor3f(0.0f
,0.5f
,1.0f
);
162 // Calc normal and draw
165 glVertex3fv(v
[2]); // triangle left bottom bac
167 // FINISh the right side of the box
180 // Calc normal and draw
183 glVertex3fv(v
[2]); // triangle left bottom bac
185 // FINISh the left side of the box
198 glColor3f(1.0f
,0.5f
,1.0f
);
199 // Calc normal and draw
202 glVertex3fv(v
[2]); // triangle left bottom bac
204 // Draw the left side
218 // Calc normal and draw
221 glVertex3fv(v
[2]); // triangle left side
223 // Draw the top and bottom
236 glColor3f(0.6f
,0.6f
,0.6f
);
237 // Calc normal and dra
240 glVertex3fv(v
[2]); // triangle left side
242 // Draw one of the bottom triangles
255 // Calc normal and draw
258 glVertex3fv(v
[2]); // triangle left side
260 // Lets finish the bottom with the second triangle
274 glColor3f(0.03f
,0.3f
,0.3f
);
275 // Calc normal and dra
278 glVertex3fv(v
[2]); // triangle left side
280 // Go back and finish the top
293 // Calc normal and dra
296 glVertex3fv(v
[2]); // triangle left side
300 } // end of the function
303 //=========================================================
304 // Now the function to actually draw it
305 //=========================================================
306 static void rendercube(void)
310 if (CURRENT_OBJECT
.visible
)
314 glRotatef(x
, 0.0f
, 1.0f
, 0.0f
);
315 glCallList(colorcube
.call_id
);
320 } // end of the function
323 //=========================================================
325 //=========================================================
326 static void compilecube(void)
329 // setup a spot for display list for background
330 //cubeobject = getcurrentobject();
331 cube_id
= colorcube
.call_id
;
334 glNewList(cube_id
, GL_COMPILE
);
336 // call drawing function
337 // we could use (drawcube)
338 // but this may method make it a little better
343 } // end of the function