13 GLfloat
RED[] = {1, 0, 0};
30 return 10 * cos(
theta);
38 return 10 * sin(
theta);
73 Ball(
double r, GLfloat *c,
double h,
double x,
double z)
92 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE,
color);
93 glTranslated(
x,
y,
z);
94 glutSolidSphere(
radius, 30, 30);
123 GLfloat lightPosition[] = {4, 3, 7, 1};
124 glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
128 for (
int x = 0; x <
width - 1; x++) {
129 for (
int z = 0; z <
depth - 1; z++) {
130 glMaterialfv(GL_FRONT,
131 GL_AMBIENT_AND_DIFFUSE,
135 glVertex3d(x + 1, 0, z);
136 glVertex3d(x + 1, 0, z + 1);
137 glVertex3d(x, 0, z + 1);
159 glEnable(GL_DEPTH_TEST);
160 glLightfv(GL_LIGHT0, GL_DIFFUSE,
WHITE);
161 glLightfv(GL_LIGHT0, GL_SPECULAR,
WHITE);
162 glMaterialfv(GL_FRONT, GL_SPECULAR,
WHITE);
163 glMaterialf(GL_FRONT, GL_SHININESS, 30);
164 glEnable(GL_LIGHTING);
172 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
184 for (
int i = 0; i <
sizeof balls /
sizeof(
Ball); i++) {
193 glViewport(0, 0, w, h);
194 glMatrixMode(GL_PROJECTION);
196 gluPerspective(40.0, GLfloat(w) / GLfloat(h), 1.0, 150.0);
197 glMatrixMode(GL_MODELVIEW);
203 glutTimerFunc(1000 / 60,
timer, v);
227 int main(
int argc,
char **argv) {
228 glutInit(&argc, argv);
229 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
230 glutInitWindowPosition(80, 80);
231 glutInitWindowSize(800, 600);
232 glutCreateWindow(
"Bouncing Balls");
236 glutTimerFunc(100,
timer, 0);
Ball(double r, GLfloat *c, double h, double x, double z)
Checkerboard(int width, int depth)
void reshape(GLint w, GLint h)
int main(int argc, char **argv)
void special(int key, int, int)
Checkerboard checkerboard(8, 8)