7 #define VERSION 20080804
9 static float angleX
, angleY
, cubeAngle
;
10 static int mouseX
, mouseY
;
15 glClearColor (0.0, 0.0, 0.0, 0.0);
17 glEnable(GL_DEPTH_TEST
);
20 glEnable(GL_LIGHTING
);
24 glShadeModel (GL_SMOOTH
);
29 GLfloat position
[] = { 2.0, 3.0, -1.0, 1.0 };
30 GLfloat lightColor
[] = { 1.0, 1.0, 1.0 };
31 GLfloat ambientColor
[] = { 1.0, 1.0, 1.0 };
32 glLightfv(GL_LIGHT0
, GL_POSITION
, position
);
33 glLightfv(GL_LIGHT0
, GL_SPECULAR
, lightColor
);
34 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, lightColor
);
35 glLightfv(GL_LIGHT0
, GL_AMBIENT
, lightColor
);
42 glClear (GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
45 glColor4f(0.0, 1.0, 0.0, 1.0);
47 gluLookAt (0.0, 2.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
52 glRotatef(angleX
, 0.0, 1.0, 0.0);
53 glRotatef(angleY
, 1.0, 0.0, 0.0);
55 glutSolidTeapot (1.0);
60 glTranslatef(0.0, 2.0, 0.0);
61 glRotatef(cubeAngle
, 0.0, 1.0, 0.0);
62 glRotatef(30, 1.0, 0, 0);
63 glColor3f(0.0, 0.0, 1.0);
71 void reshape (int w
, int h
)
73 glViewport (0, 0, (GLsizei
) w
, (GLsizei
) h
);
74 glMatrixMode (GL_PROJECTION
);
76 gluPerspective(60.0, (float)w
/h
, 1.0, 20.0);
77 glMatrixMode (GL_MODELVIEW
);
80 void mouse (int button
, int state
, int x
, int y
)
82 if (button
== GLUT_LEFT_BUTTON
&& state
== GLUT_DOWN
)
86 if (button
== GLUT_LEFT_BUTTON
&& state
== GLUT_UP
)
94 void mousePos(int x
, int y
)
98 angleX
+= 1 * (x
- mouseX
);
99 angleY
+= 1 * (y
- mouseY
);
106 void update(int value
)
109 if (cubeAngle
> 360) cubeAngle
-= 360;
111 glutTimerFunc(20, update
, 1);
115 int main(int argc
, char** argv
)
117 std::cout
<< "Spatial Auditory Memory Experiment" << std::endl
;
119 glutInit(&argc
, argv
);
120 glutInitDisplayMode (GLUT_RGBA
| GLUT_DOUBLE
| GLUT_DEPTH
);
121 glutInitWindowSize (500, 500);
122 glutInitWindowPosition (100, 100);
123 glutCreateWindow ("Spatial Auditory Memory Experiment");
125 glutDisplayFunc (display
);
126 glutReshapeFunc (reshape
);
127 glutTimerFunc(1, update
, 1);
129 glutMouseFunc(mouse
);
130 glutMotionFunc(mousePos
);