tavli

annotate src/main.cc @ 24:0aadb519b5ee

correct highlighting
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 08 Jul 2015 15:11:58 +0300
parents e48b40a3c82a
children
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@17 11 #include "opt.h"
nuclear@0 12
nuclear@0 13 static void display();
nuclear@0 14 static void reshape(int x, int y);
nuclear@0 15 static void keypress(unsigned char key, int x, int y);
nuclear@0 16 static void keyrelease(unsigned char key, int x, int y);
nuclear@0 17 static void mouse(int bn, int st, int x, int y);
nuclear@0 18 static void motion(int x, int y);
nuclear@0 19
nuclear@0 20 int main(int argc, char **argv)
nuclear@0 21 {
nuclear@0 22 glutInit(&argc, argv);
nuclear@17 23
nuclear@17 24 if(!init_options(argc, argv)) {
nuclear@17 25 return 1;
nuclear@17 26 }
nuclear@17 27
nuclear@17 28 glutInitWindowSize(opt.xres, opt.yres);
nuclear@5 29 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_MULTISAMPLE);
nuclear@0 30 glutCreateWindow("Tavli");
nuclear@0 31
nuclear@17 32 if(opt.fullscreen) {
nuclear@17 33 glutFullScreen();
nuclear@17 34 }
nuclear@17 35
nuclear@0 36 glutDisplayFunc(display);
nuclear@0 37 glutReshapeFunc(reshape);
nuclear@0 38 glutKeyboardFunc(keypress);
nuclear@0 39 glutKeyboardUpFunc(keyrelease);
nuclear@0 40 glutMouseFunc(mouse);
nuclear@0 41 glutMotionFunc(motion);
nuclear@0 42 glutPassiveMotionFunc(motion);
nuclear@0 43
nuclear@0 44 glewInit();
nuclear@0 45
nuclear@0 46 if(!game_init()) {
nuclear@0 47 return 1;
nuclear@0 48 }
nuclear@0 49 atexit(game_cleanup);
nuclear@0 50
nuclear@0 51 glutMainLoop();
nuclear@0 52 return 0;
nuclear@0 53 }
nuclear@0 54
nuclear@0 55 void redisplay()
nuclear@0 56 {
nuclear@0 57 glutPostRedisplay();
nuclear@0 58 }
nuclear@0 59
nuclear@0 60 void quit()
nuclear@0 61 {
nuclear@0 62 exit(0);
nuclear@0 63 }
nuclear@0 64
nuclear@0 65 static void display()
nuclear@0 66 {
nuclear@0 67 unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
nuclear@0 68 game_update(msec);
nuclear@0 69 game_display();
nuclear@0 70
nuclear@0 71 assert(glGetError() == GL_NO_ERROR);
nuclear@0 72 glutSwapBuffers();
nuclear@0 73 }
nuclear@0 74
nuclear@0 75 static void reshape(int x, int y)
nuclear@0 76 {
nuclear@0 77 win_width = x;
nuclear@0 78 win_height = y;
nuclear@0 79
nuclear@0 80 game_reshape(x, y);
nuclear@0 81 }
nuclear@0 82
nuclear@0 83 static void keypress(unsigned char key, int x, int y)
nuclear@0 84 {
nuclear@0 85 game_keyboard(key, true);
nuclear@0 86 }
nuclear@0 87
nuclear@0 88 static void keyrelease(unsigned char key, int x, int y)
nuclear@0 89 {
nuclear@0 90 game_keyboard(key, false);
nuclear@0 91 }
nuclear@0 92
nuclear@0 93 static void mouse(int bn, int st, int x, int y)
nuclear@0 94 {
nuclear@0 95 game_mbutton(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
nuclear@0 96 }
nuclear@0 97
nuclear@0 98 static void motion(int x, int y)
nuclear@0 99 {
nuclear@0 100 game_mmotion(x, y);
nuclear@0 101 }