labyrinth

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