labyrinth
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/glut/main.c Fri May 01 04:36:50 2015 +0300 1.3 @@ -0,0 +1,94 @@ 1.4 +#include <stdio.h> 1.5 +#include <stdlib.h> 1.6 +#include <math.h> 1.7 +#include <assert.h> 1.8 +#include "opengl.h" 1.9 + 1.10 +#ifdef __APPLE__ 1.11 +#include <GLUT/glut.h> 1.12 +#else 1.13 +#include <GL/glut.h> 1.14 +#endif 1.15 + 1.16 +#include "game.h" 1.17 + 1.18 +static void display(void); 1.19 +static void idle(void); 1.20 +static void reshape(int x, int y); 1.21 +static void key_down(unsigned char key, int x, int y); 1.22 +static void key_up(unsigned char key, int x, int y); 1.23 +static void mouse(int bn, int state, int x, int y); 1.24 +static void motion(int x, int y); 1.25 + 1.26 +int main(int argc, char **argv) 1.27 +{ 1.28 + glutInit(&argc, argv); 1.29 + glutInitWindowSize(1280, 800); 1.30 + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); 1.31 + glutCreateWindow("labyrinth game example"); 1.32 + 1.33 + glutDisplayFunc(display); 1.34 + glutIdleFunc(idle); 1.35 + glutReshapeFunc(reshape); 1.36 + glutKeyboardFunc(key_down); 1.37 + glutKeyboardUpFunc(key_up); 1.38 + glutMouseFunc(mouse); 1.39 + glutMotionFunc(motion); 1.40 + glutPassiveMotionFunc(motion); 1.41 + 1.42 + glewInit(); 1.43 + 1.44 + if(game_init() == -1) { 1.45 + return 1; 1.46 + } 1.47 + glutMainLoop(); 1.48 + return 0; 1.49 +} 1.50 + 1.51 +void set_mouse_pos(int x, int y) 1.52 +{ 1.53 + glutWarpPointer(x, y); 1.54 +} 1.55 + 1.56 +void set_mouse_cursor(int enable) 1.57 +{ 1.58 + glutSetCursor(enable ? GLUT_CURSOR_INHERIT : GLUT_CURSOR_NONE); 1.59 +} 1.60 + 1.61 +static void display(void) 1.62 +{ 1.63 + game_display(glutGet(GLUT_ELAPSED_TIME)); 1.64 + 1.65 + glutSwapBuffers(); 1.66 + assert(glGetError() == GL_NO_ERROR); 1.67 +} 1.68 + 1.69 +static void idle(void) 1.70 +{ 1.71 + glutPostRedisplay(); 1.72 +} 1.73 + 1.74 +static void reshape(int x, int y) 1.75 +{ 1.76 + game_reshape(x, y); 1.77 +} 1.78 + 1.79 +static void key_down(unsigned char key, int x, int y) 1.80 +{ 1.81 + game_keyboard(key, 1); 1.82 +} 1.83 + 1.84 +static void key_up(unsigned char key, int x, int y) 1.85 +{ 1.86 + game_keyboard(key, 0); 1.87 +} 1.88 + 1.89 +static void mouse(int bn, int state, int x, int y) 1.90 +{ 1.91 + game_mouse_button(0, bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN ? 1 : 0, x, y); 1.92 +} 1.93 + 1.94 +static void motion(int x, int y) 1.95 +{ 1.96 + game_mouse_motion(0, x, y); 1.97 +}