1 
2 /*
3  * FILE:
4  * cone.c
5  *
6  * FUNCTION:
7  * Baisc demo illustrating how to write code to draw
8  * the most basic cone shape.
9  *
10  * HISTORY:
11  * Linas Vepstas March 1995
12  * Copyright (c) 1995 Linas Vepstas <linas@linas.org>
13  */
14 
15 /* required include files */
16 #include <GL/gl.h>
17 #include <GL/glut.h>
18 #include <GL/gle.h>
19 #include "main.h"
20 
21 /* the arrays in which we will store out polyline */
22 #define NPTS 6
23 double radii [NPTS];
24 double points [NPTS][3];
25 float colors [NPTS][3];
26 int idx = 0;
27 
28 /* some utilities for filling that array */
29 #define PNT(x,y,z) { 			\
30    points[idx][0] = x; 			\
31    points[idx][1] = y; 			\
32    points[idx][2] = z;			\
33    idx ++;				\
34 }
35 
36 #define COL(r,g,b) { 			\
37    colors[idx][0] = r; 			\
38    colors[idx][1] = g; 			\
39    colors[idx][2] = b;			\
40 }
41 
42 #define RAD(r) {			\
43    radii[idx] = r;			\
44 }
45 
46 /*
47  * Initialize a bent shape with three segments.
48  * The data format is a polyline.
49  *
50  * NOTE that neither the first, nor the last segment are drawn.
51  * The first & last segment serve only to determine that angle
52  * at which the endcaps are drawn.
53  */
54 
InitStuff(void)55 void InitStuff (void) {
56 
57    /* initialize the join style here */
58    gleSetJoinStyle (TUBE_NORM_EDGE | TUBE_JN_ANGLE | TUBE_JN_CAP);
59 
60    RAD (1.0);
61    COL (0.0, 0.0, 0.0);
62    PNT (-6.0, 6.0, 0.0);
63 
64    RAD (1.0);
65    COL (0.0, 0.8, 0.3);
66    PNT (6.0, 6.0, 0.0);
67 
68    RAD (3.0);
69    COL (0.8, 0.3, 0.0);
70    PNT (6.0, -6.0, 0.0);
71 
72    RAD (0.5);
73    COL (0.2, 0.3, 0.9);
74    PNT (-6.0, -6.0, 0.0);
75 
76    RAD (2.0);
77    COL (0.2, 0.8, 0.5);
78    PNT (-6.0, 6.0, 0.0);
79 
80    RAD (1.0);
81    COL (0.0, 0.0, 0.0);
82    PNT (6.0, 6.0, 0.0);
83 }
84 
85 /* draw the polycone shape */
DrawStuff(void)86 void DrawStuff (void) {
87 
88    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
89 
90    /* set up some matrices so that the object spins with the mouse */
91    glPushMatrix ();
92    glTranslatef (0.0, 0.0, -80.0);
93    glRotatef (lastx, 0.0, 1.0, 0.0);
94    glRotatef (lasty, 1.0, 0.0, 0.0);
95 
96    /* Phew. FINALLY, Draw the polycone  -- */
97    glePolyCone (idx, points, colors, radii);
98 
99    glPopMatrix ();
100 
101    glutSwapBuffers ();
102 }
103 
104 /* --------------------------- end of file ------------------- */
105