tavli

annotate src/main.cc @ 10:fc5c68da7906

added readme and license
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 26 Jun 2015 05:41:18 +0300
parents 52e0dd47753b
children 16a420432aa3
rev   line source
nuclear@0 1 #include <stdio.h>
nuclear@0 2 #include <stdlib.h>
nuclear@0 3 #include <assert.h>
nuclear@0 4 #include <GL/glew.h>
nuclear@0 5 #ifdef __APPLE__
nuclear@0 6 #include <GLUT/glut.h>
nuclear@0 7 #else
nuclear@0 8 #include <GL/glut.h>
nuclear@0 9 #endif
nuclear@0 10 #include "game.h"
nuclear@0 11
nuclear@0 12 static void display();
nuclear@0 13 static void reshape(int x, int y);
nuclear@0 14 static void keypress(unsigned char key, int x, int y);
nuclear@0 15 static void keyrelease(unsigned char key, int x, int y);
nuclear@0 16 static void mouse(int bn, int st, int x, int y);
nuclear@0 17 static void motion(int x, int y);
nuclear@0 18
nuclear@0 19 int main(int argc, char **argv)
nuclear@0 20 {
nuclear@0 21 glutInit(&argc, argv);
nuclear@0 22 glutInitWindowSize(1280, 800);
nuclear@5 23 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_MULTISAMPLE);
nuclear@0 24 glutCreateWindow("Tavli");
nuclear@0 25
nuclear@0 26 glutDisplayFunc(display);
nuclear@0 27 glutReshapeFunc(reshape);
nuclear@0 28 glutKeyboardFunc(keypress);
nuclear@0 29 glutKeyboardUpFunc(keyrelease);
nuclear@0 30 glutMouseFunc(mouse);
nuclear@0 31 glutMotionFunc(motion);
nuclear@0 32 glutPassiveMotionFunc(motion);
nuclear@0 33
nuclear@0 34 glewInit();
nuclear@0 35
nuclear@0 36 if(!game_init()) {
nuclear@0 37 return 1;
nuclear@0 38 }
nuclear@0 39 atexit(game_cleanup);
nuclear@0 40
nuclear@0 41 glutMainLoop();
nuclear@0 42 return 0;
nuclear@0 43 }
nuclear@0 44
nuclear@0 45 void redisplay()
nuclear@0 46 {
nuclear@0 47 glutPostRedisplay();
nuclear@0 48 }
nuclear@0 49
nuclear@0 50 void quit()
nuclear@0 51 {
nuclear@0 52 exit(0);
nuclear@0 53 }
nuclear@0 54
nuclear@0 55 static void display()
nuclear@0 56 {
nuclear@0 57 unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
nuclear@0 58 game_update(msec);
nuclear@0 59 game_display();
nuclear@0 60
nuclear@0 61 assert(glGetError() == GL_NO_ERROR);
nuclear@0 62 glutSwapBuffers();
nuclear@0 63 }
nuclear@0 64
nuclear@0 65 static void reshape(int x, int y)
nuclear@0 66 {
nuclear@0 67 win_width = x;
nuclear@0 68 win_height = y;
nuclear@0 69
nuclear@0 70 game_reshape(x, y);
nuclear@0 71 }
nuclear@0 72
nuclear@0 73 static void keypress(unsigned char key, int x, int y)
nuclear@0 74 {
nuclear@0 75 game_keyboard(key, true);
nuclear@0 76 }
nuclear@0 77
nuclear@0 78 static void keyrelease(unsigned char key, int x, int y)
nuclear@0 79 {
nuclear@0 80 game_keyboard(key, false);
nuclear@0 81 }
nuclear@0 82
nuclear@0 83 static void mouse(int bn, int st, int x, int y)
nuclear@0 84 {
nuclear@0 85 game_mbutton(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
nuclear@0 86 }
nuclear@0 87
nuclear@0 88 static void motion(int x, int y)
nuclear@0 89 {
nuclear@0 90 game_mmotion(x, y);
nuclear@0 91 }