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
= 22.5, db
= 22.5;
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 glClearColor(0.6f
, 0.6f
, 0.6f
, 1.0f
);
111 glClear(GL_COLOR_BUFFER_BIT
);
114 glColor3f(0.7, 0.45, 0.7);
117 for (i
= -5; i
<= 5; i
++) {
121 for (i
= -5; i
<= 5; i
++) {
125 for (i
= -5; i
<= 5; i
++) {
127 glVertex2f(i
* 1.15, -5.9);
129 glVertex2f(-5.3, -5.35);
130 glVertex2f(5.3, -5.35);
131 glVertex2f(-5.75, -5.9);
132 glVertex2f(5.75, -5.9);
137 glTranslatef(Xpos
, Ypos
, 0.0);
138 glScalef(2.0, 2.0, 2.0);
139 glRotatef(-20.0, 0.0, 0.0, 1.0);
140 glRotatef(90.0, 1.0, 0.0, 0.0);
141 glRotatef(Zrot
, 0.0, 0.0, 1.0);
155 static float vel0
= -100.0;
156 static double t0
= -1.;
158 t
= glutGet(GLUT_ELAPSED_TIME
) / 1000.;
191 if (vis
== GLUT_VISIBLE
)
197 #include <proto/exec.h>
198 #include <proto/dos.h>
200 #define ARG_TEMPLATE "WINPOSX=X/N/K,WINPOSY=Y/N/K"
205 static IPTR args
[NUM_ARGS
];
206 WORD winx
= -1, winy
= -1;
210 static void correctpos(void)
212 if (winx
== -1) winx
= 100;
213 if (winy
== -1) winy
= 100;
216 static void getarguments(void)
218 struct RDArgs
*myargs
;
220 if ((myargs
= ReadArgs(ARG_TEMPLATE
, args
, NULL
)))
223 if (args
[ARG_X
]) winx
= *(IPTR
*)args
[ARG_X
];
224 if (args
[ARG_Y
]) winy
= *(IPTR
*)args
[ARG_Y
];
231 int main(int argc
, char *argv
[])
236 glutInit(&argc
, argv
);
237 glutInitWindowPosition(winx
, winy
);
238 glutInitWindowSize(W
, H
);
241 IndexMode
= argc
> 1 && strcmp(argv
[1], "-ci") == 0;
243 glutInitDisplayMode(GLUT_INDEX
| GLUT_DOUBLE
);
245 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
247 glutCreateWindow("Bounce");
250 glEnable(GL_CULL_FACE
);
251 glDisable(GL_DITHER
);
252 glShadeModel(GL_FLAT
);
254 glutDisplayFunc(draw
);
255 glutReshapeFunc(reshape
);
256 glutVisibilityFunc(visible
);
257 glutKeyboardFunc(key
);
260 glutSetColor(RED
, 1.0, 0.0, 0.0);
261 glutSetColor(WHITE
, 1.0, 1.0, 1.0);
262 glutSetColor(VIOLET
, 0.7, 0.45, 0.7);
266 return 0; /* ANSI C requires main to return int. */