1 /* $Id: bounce.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
4 * Bouncing ball demo. Color index mode only!
6 * This program is in the public domain
11 /* Conversion to GLUT by Mark J. Kilgard */
15 * Revision 1.1 1999/08/19 00:55:40 jtg
18 * Revision 3.3 1999/03/18 08:16:14 joukj
20 * cmpstr needs string.h to included to avoid warnings
22 * Revision 3.2 1998/11/28 01:13:02 brianp
23 * now sets an initial window position and size
25 * Revision 3.1 1998/11/28 01:06:57 brianp
26 * now works in RGB mode by default
28 * Revision 3.0 1998/02/14 18:42:29 brianp
39 #define COS(X) cos( (X) * 3.14159/180.0 )
40 #define SIN(X) sin( (X) * 3.14159/180.0 )
46 GLboolean IndexMode
= GL_FALSE
;
49 GLfloat Zrot
= 0.0, Zstep
= 6.0;
50 GLfloat Xpos
= 0.0, Ypos
= 1.0;
51 GLfloat Xvel
= 0.2, Yvel
= 0.0;
52 GLfloat Xmin
= -4.0, Xmax
= 4.0;
53 GLfloat Ymin
= -3.8, Ymax
= 4.0;
61 GLfloat da
= 18.0, db
= 18.0;
68 glNewList(list
, GL_COMPILE
);
71 for (a
= -90.0; a
+ da
<= 90.0; a
+= da
) {
73 glBegin(GL_QUAD_STRIP
);
74 for (b
= 0.0; b
<= 360.0; b
+= db
) {
89 x
= radius
* COS(b
) * COS(a
+ da
);
90 y
= radius
* SIN(b
) * COS(a
+ da
);
91 z
= radius
* SIN(a
+ da
);
106 reshape(int width
, int height
)
108 float aspect
= (float) width
/ (float) height
;
109 glViewport(0, 0, (GLint
) width
, (GLint
) height
);
110 glMatrixMode(GL_PROJECTION
);
112 glOrtho(-6.0 * aspect
, 6.0 * aspect
, -6.0, 6.0, -6.0, 6.0);
113 glMatrixMode(GL_MODELVIEW
);
118 key(unsigned char k
, int x
, int y
)
121 case 27: /* Escape */
131 glClear(GL_COLOR_BUFFER_BIT
);
136 for (i
= -5; i
<= 5; i
++) {
140 for (i
= -5; i
<= 5; i
++) {
144 for (i
= -5; i
<= 5; i
++) {
146 glVertex2f(i
* 1.15, -5.9);
148 glVertex2f(-5.3, -5.35);
149 glVertex2f(5.3, -5.35);
150 glVertex2f(-5.75, -5.9);
151 glVertex2f(5.75, -5.9);
155 glTranslatef(Xpos
, Ypos
, 0.0);
156 glScalef(2.0, 2.0, 2.0);
157 glRotatef(8.0, 0.0, 0.0, 1.0);
158 glRotatef(90.0, 1.0, 0.0, 0.0);
159 glRotatef(Zrot
, 0.0, 0.0, 1.0);
172 static float vel0
= -100.0;
201 if (vis
== GLUT_VISIBLE
)
207 int main(int argc
, char *argv
[])
209 glutInit(&argc
, argv
);
210 glutInitWindowPosition(0, 0);
211 glutInitWindowSize(600, 450);
214 IndexMode
= argc
> 1 && strcmp(argv
[1], "-ci") == 0;
216 glutInitDisplayMode(GLUT_INDEX
| GLUT_DOUBLE
);
218 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
220 glutCreateWindow("Bounce");
223 glEnable(GL_CULL_FACE
);
224 glDisable(GL_DITHER
);
225 glShadeModel(GL_FLAT
);
227 glutDisplayFunc(draw
);
228 glutReshapeFunc(reshape
);
229 glutVisibilityFunc(visible
);
230 glutKeyboardFunc(key
);
233 glutSetColor(RED
, 1.0, 0.0, 0.0);
234 glutSetColor(WHITE
, 1.0, 1.0, 1.0);
235 glutSetColor(CYAN
, 0.0, 1.0, 1.0);
239 return 0; /* ANSI C requires main to return int. */