5 * This program is in the public domain
9 * Conversion to GLUT by Mark J. Kilgard
18 #define COS(X) cos( (X) * 3.14159/180.0 )
19 #define SIN(X) sin( (X) * 3.14159/180.0 )
25 GLboolean IndexMode
= GL_FALSE
;
28 GLfloat Zrot
= 0.0, Zstep
= 180.0;
29 GLfloat Xpos
= 0.0, Ypos
= 1.0;
30 GLfloat Xvel
= 2.0, Yvel
= 0.0;
31 GLfloat Xmin
= -4.0, Xmax
= 4.0;
32 GLfloat Ymin
= -3.8, Ymax
= 4.0;
40 GLfloat da
= 18.0, db
= 18.0;
47 glNewList(list
, GL_COMPILE
);
50 for (a
= -90.0; a
+ da
<= 90.0; a
+= da
) {
52 glBegin(GL_QUAD_STRIP
);
53 for (b
= 0.0; b
<= 360.0; b
+= db
) {
63 x
= radius
* COS(b
) * COS(a
);
64 y
= radius
* SIN(b
) * COS(a
);
68 x
= radius
* COS(b
) * COS(a
+ da
);
69 y
= radius
* SIN(b
) * COS(a
+ da
);
70 z
= radius
* SIN(a
+ da
);
85 reshape(int width
, int height
)
87 float aspect
= (float) width
/ (float) height
;
88 glViewport(0, 0, (GLint
) width
, (GLint
) height
);
89 glMatrixMode(GL_PROJECTION
);
91 glOrtho(-6.0 * aspect
, 6.0 * aspect
, -6.0, 6.0, -6.0, 6.0);
92 glMatrixMode(GL_MODELVIEW
);
97 key(unsigned char k
, int x
, int y
)
100 case 27: /* Escape */
110 glClear(GL_COLOR_BUFFER_BIT
);
115 for (i
= -5; i
<= 5; i
++) {
119 for (i
= -5; i
<= 5; i
++) {
123 for (i
= -5; i
<= 5; i
++) {
125 glVertex2f(i
* 1.15, -5.9);
127 glVertex2f(-5.3, -5.35);
128 glVertex2f(5.3, -5.35);
129 glVertex2f(-5.75, -5.9);
130 glVertex2f(5.75, -5.9);
134 glTranslatef(Xpos
, Ypos
, 0.0);
135 glScalef(2.0, 2.0, 2.0);
136 glRotatef(8.0, 0.0, 0.0, 1.0);
137 glRotatef(90.0, 1.0, 0.0, 0.0);
138 glRotatef(Zrot
, 0.0, 0.0, 1.0);
151 static float vel0
= -100.0;
152 static double t0
= -1.;
154 t
= glutGet(GLUT_ELAPSED_TIME
) / 1000.;
187 if (vis
== GLUT_VISIBLE
)
193 int main(int argc
, char *argv
[])
195 glutInit(&argc
, argv
);
196 glutInitWindowPosition(0, 0);
197 glutInitWindowSize(600, 450);
200 IndexMode
= argc
> 1 && strcmp(argv
[1], "-ci") == 0;
202 glutInitDisplayMode(GLUT_INDEX
| GLUT_DOUBLE
);
204 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
206 glutCreateWindow("Bounce");
209 glEnable(GL_CULL_FACE
);
210 glDisable(GL_DITHER
);
211 glShadeModel(GL_FLAT
);
213 glutDisplayFunc(draw
);
214 glutReshapeFunc(reshape
);
215 glutVisibilityFunc(visible
);
216 glutKeyboardFunc(key
);
219 glutSetColor(RED
, 1.0, 0.0, 0.0);
220 glutSetColor(WHITE
, 1.0, 1.0, 1.0);
221 glutSetColor(CYAN
, 0.0, 1.0, 1.0);
225 return 0; /* ANSI C requires main to return int. */