Added idle func animation
[ludumice] / src / main.cc
1 #include <GL/glew.h>
2 #include <GL/glut.h>
3 #include <stdio.h>
4
5 #include "tentacle.h"
6
7 static bool init();
8 static void cleanup();
9
10 static void display();
11 static void keyboard(unsigned char key, int x, int y);
12 static void idle();
13
14 /* XXX FIXME */
15 static Tentacle tentacle;
16
17 int main(int argc, char **argv)
18 {
19         glutInit(&argc, argv);
20         glutInitWindowSize(800, 600);
21         glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
22
23         glutCreateWindow("ludu mice");
24         glutDisplayFunc(display);
25         glutKeyboardFunc(keyboard);
26         glutIdleFunc(idle);
27
28         if (!init())
29                 exit(1);
30
31         atexit(cleanup);
32
33         glutMainLoop();
34 }
35
36 static bool init()
37 {
38         glewInit();
39         glClearColor(1.0, 1.0, 0.0, 1.0);
40
41         if (!tentacle.init()) {
42                 fprintf(stderr, "Failed to initialize tentacle control points.\n");
43                 return false;
44         }
45
46         return true;
47 }
48
49 static void cleanup()
50 {
51 }
52
53 static void display()
54 {
55         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
56
57         //XXX FIXME
58         glMatrixMode(GL_MODELVIEW);
59         glLoadIdentity();
60
61         tentacle.draw(glutGet(GLUT_ELAPSED_TIME));
62
63         glutSwapBuffers();
64 }
65
66 static void keyboard(unsigned char key, int x, int y)
67 {
68         switch(key) {
69         case 27:
70                 exit(0);
71         default:
72                 break;
73         }
74 }
75
76 static void idle()
77 {
78         glutPostRedisplay();
79 }