Initial commit
[spatialaudio.git] / main.cpp
blobf66e2c8a5a695c1ce626e83bc518beb1781f503e
2 #include <iostream>
3 #include <GL/gl.h>
4 #include <GL/glu.h>
5 #include <GL/glut.h>
7 #define VERSION 20080804
9 static float angleX, angleY, cubeAngle;
10 static int mouseX, mouseY;
11 static bool rotate;
13 void init()
15 glClearColor (0.0, 0.0, 0.0, 0.0);
17 glEnable(GL_DEPTH_TEST);
19 // Setup lighting
20 glEnable(GL_LIGHTING);
21 glEnable(GL_LIGHT0);
23 // Setup shading
24 glShadeModel (GL_SMOOTH);
27 void lighting()
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);
40 void display()
42 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
45 glColor4f(0.0, 1.0, 0.0, 1.0);
46 glLoadIdentity();
47 gluLookAt (0.0, 2.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
49 lighting();
51 glPushMatrix();
52 glRotatef(angleX, 0.0, 1.0, 0.0);
53 glRotatef(angleY, 1.0, 0.0, 0.0);
54 glFrontFace(GL_CW);
55 glutSolidTeapot (1.0);
56 glFrontFace(GL_CCW);
57 glPopMatrix();
59 glPushMatrix();
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);
64 glutSolidCube(0.5);
65 glPopMatrix();
67 glutSwapBuffers();
71 void reshape (int w, int h)
73 glViewport (0, 0, (GLsizei) w, (GLsizei) h);
74 glMatrixMode (GL_PROJECTION);
75 glLoadIdentity();
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)
84 rotate = true;
86 if (button == GLUT_LEFT_BUTTON && state == GLUT_UP)
88 rotate = false;
90 mouseX = x;
91 mouseY = y;
94 void mousePos(int x, int y)
96 if (rotate)
98 angleX += 1 * (x - mouseX);
99 angleY += 1 * (y - mouseY);
100 glutPostRedisplay();
102 mouseX = x;
103 mouseY = y;
106 void update(int value)
108 cubeAngle++;
109 if (cubeAngle > 360) cubeAngle -= 360;
110 glutPostRedisplay();
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");
124 init();
125 glutDisplayFunc (display);
126 glutReshapeFunc (reshape);
127 glutTimerFunc(1, update, 1);
129 glutMouseFunc(mouse);
130 glutMotionFunc(mousePos);
132 glutMainLoop();
133 return 0;