labyrinth

view src/glut/main.c @ 3:45b91185b298

android port
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 01 May 2015 04:36:50 +0300
parents
children
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include <assert.h>
5 #include "opengl.h"
7 #ifdef __APPLE__
8 #include <GLUT/glut.h>
9 #else
10 #include <GL/glut.h>
11 #endif
13 #include "game.h"
15 static void display(void);
16 static void idle(void);
17 static void reshape(int x, int y);
18 static void key_down(unsigned char key, int x, int y);
19 static void key_up(unsigned char key, int x, int y);
20 static void mouse(int bn, int state, int x, int y);
21 static void motion(int x, int y);
23 int main(int argc, char **argv)
24 {
25 glutInit(&argc, argv);
26 glutInitWindowSize(1280, 800);
27 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
28 glutCreateWindow("labyrinth game example");
30 glutDisplayFunc(display);
31 glutIdleFunc(idle);
32 glutReshapeFunc(reshape);
33 glutKeyboardFunc(key_down);
34 glutKeyboardUpFunc(key_up);
35 glutMouseFunc(mouse);
36 glutMotionFunc(motion);
37 glutPassiveMotionFunc(motion);
39 glewInit();
41 if(game_init() == -1) {
42 return 1;
43 }
44 glutMainLoop();
45 return 0;
46 }
48 void set_mouse_pos(int x, int y)
49 {
50 glutWarpPointer(x, y);
51 }
53 void set_mouse_cursor(int enable)
54 {
55 glutSetCursor(enable ? GLUT_CURSOR_INHERIT : GLUT_CURSOR_NONE);
56 }
58 static void display(void)
59 {
60 game_display(glutGet(GLUT_ELAPSED_TIME));
62 glutSwapBuffers();
63 assert(glGetError() == GL_NO_ERROR);
64 }
66 static void idle(void)
67 {
68 glutPostRedisplay();
69 }
71 static void reshape(int x, int y)
72 {
73 game_reshape(x, y);
74 }
76 static void key_down(unsigned char key, int x, int y)
77 {
78 game_keyboard(key, 1);
79 }
81 static void key_up(unsigned char key, int x, int y)
82 {
83 game_keyboard(key, 0);
84 }
86 static void mouse(int bn, int state, int x, int y)
87 {
88 game_mouse_button(0, bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN ? 1 : 0, x, y);
89 }
91 static void motion(int x, int y)
92 {
93 game_mouse_motion(0, x, y);
94 }