tavli
view src/main.cc @ 12:ae1c60726c41
better pieces
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 27 Jun 2015 13:53:43 +0300 |
parents | 52e0dd47753b |
children | 16a420432aa3 |
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"
12 static void display();
13 static void reshape(int x, int y);
14 static void keypress(unsigned char key, int x, int y);
15 static void keyrelease(unsigned char key, int x, int y);
16 static void mouse(int bn, int st, int x, int y);
17 static void motion(int x, int y);
19 int main(int argc, char **argv)
20 {
21 glutInit(&argc, argv);
22 glutInitWindowSize(1280, 800);
23 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_MULTISAMPLE);
24 glutCreateWindow("Tavli");
26 glutDisplayFunc(display);
27 glutReshapeFunc(reshape);
28 glutKeyboardFunc(keypress);
29 glutKeyboardUpFunc(keyrelease);
30 glutMouseFunc(mouse);
31 glutMotionFunc(motion);
32 glutPassiveMotionFunc(motion);
34 glewInit();
36 if(!game_init()) {
37 return 1;
38 }
39 atexit(game_cleanup);
41 glutMainLoop();
42 return 0;
43 }
45 void redisplay()
46 {
47 glutPostRedisplay();
48 }
50 void quit()
51 {
52 exit(0);
53 }
55 static void display()
56 {
57 unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
58 game_update(msec);
59 game_display();
61 assert(glGetError() == GL_NO_ERROR);
62 glutSwapBuffers();
63 }
65 static void reshape(int x, int y)
66 {
67 win_width = x;
68 win_height = y;
70 game_reshape(x, y);
71 }
73 static void keypress(unsigned char key, int x, int y)
74 {
75 game_keyboard(key, true);
76 }
78 static void keyrelease(unsigned char key, int x, int y)
79 {
80 game_keyboard(key, false);
81 }
83 static void mouse(int bn, int st, int x, int y)
84 {
85 game_mbutton(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
86 }
88 static void motion(int x, int y)
89 {
90 game_mmotion(x, y);
91 }