tavli

view 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
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <assert.h>
4 #include <GL/glew.h>
5 #ifdef __APPLE__
6 #include <GLUT/glut.h>
7 #else
8 #include <GL/glut.h>
9 #endif
10 #include "game.h"
11 #include "opt.h"
13 static void display();
14 static void reshape(int x, int y);
15 static void keypress(unsigned char key, int x, int y);
16 static void keyrelease(unsigned char key, int x, int y);
17 static void mouse(int bn, int st, int x, int y);
18 static void motion(int x, int y);
20 int main(int argc, char **argv)
21 {
22 glutInit(&argc, argv);
24 if(!init_options(argc, argv)) {
25 return 1;
26 }
28 glutInitWindowSize(opt.xres, opt.yres);
29 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_MULTISAMPLE);
30 glutCreateWindow("Tavli");
32 if(opt.fullscreen) {
33 glutFullScreen();
34 }
36 glutDisplayFunc(display);
37 glutReshapeFunc(reshape);
38 glutKeyboardFunc(keypress);
39 glutKeyboardUpFunc(keyrelease);
40 glutMouseFunc(mouse);
41 glutMotionFunc(motion);
42 glutPassiveMotionFunc(motion);
44 glewInit();
46 if(!game_init()) {
47 return 1;
48 }
49 atexit(game_cleanup);
51 glutMainLoop();
52 return 0;
53 }
55 void redisplay()
56 {
57 glutPostRedisplay();
58 }
60 void quit()
61 {
62 exit(0);
63 }
65 static void display()
66 {
67 unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
68 game_update(msec);
69 game_display();
71 assert(glGetError() == GL_NO_ERROR);
72 glutSwapBuffers();
73 }
75 static void reshape(int x, int y)
76 {
77 win_width = x;
78 win_height = y;
80 game_reshape(x, y);
81 }
83 static void keypress(unsigned char key, int x, int y)
84 {
85 game_keyboard(key, true);
86 }
88 static void keyrelease(unsigned char key, int x, int y)
89 {
90 game_keyboard(key, false);
91 }
93 static void mouse(int bn, int st, int x, int y)
94 {
95 game_mbutton(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
96 }
98 static void motion(int x, int y)
99 {
100 game_mmotion(x, y);
101 }