- asset loader (needed for android)
[andemo] / src / pc / main_glut.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <assert.h>
4 #include "miniglut.h"
5 #include "demo.h"
6
7 static void display(void);
8 static void keypress(unsigned char key, int x, int y);
9 static void mouse(int bn, int st, int x, int y);
10
11 static long start_time;
12
13
14 int main(int argc, char **argv)
15 {
16         glutInit(&argc, argv);
17         glutInitWindowSize(1280, 800);
18         glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
19         glutCreateWindow("Mindlapse");
20
21         glutDisplayFunc(display);
22         glutIdleFunc(glutPostRedisplay);
23         glutReshapeFunc(demo_reshape);
24         glutKeyboardFunc(keypress);
25         glutMouseFunc(mouse);
26         glutMotionFunc(demo_motion);
27
28         if(demo_init() == -1) {
29                 return 1;
30         }
31         atexit(demo_cleanup);
32
33         start_time = glutGet(GLUT_ELAPSED_TIME);
34         glutMainLoop();
35         return 0;
36 }
37
38 static void display(void)
39 {
40         demo_time_msec = glutGet(GLUT_ELAPSED_TIME) - start_time;
41
42         demo_display();
43
44         glutSwapBuffers();
45         assert(glGetError() == GL_NO_ERROR);
46 }
47
48 static void keypress(unsigned char key, int x, int y)
49 {
50         if(key == 27) exit(0);
51
52         demo_keyboard(key, 1);
53 }
54
55 static void mouse(int bn, int st, int x, int y)
56 {
57         int bidx = bn - GLUT_LEFT_BUTTON;
58         int press = st == GLUT_DOWN;
59
60         demo_mouse(bidx, press, x, y);
61 }