tavli

diff src/main.cc @ 0:52e0dd47753b

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 21 Jun 2015 06:30:39 +0300
parents
children e48b40a3c82a
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/main.cc	Sun Jun 21 06:30:39 2015 +0300
     1.3 @@ -0,0 +1,91 @@
     1.4 +#include <stdio.h>
     1.5 +#include <stdlib.h>
     1.6 +#include <assert.h>
     1.7 +#include <GL/glew.h>
     1.8 +#ifdef __APPLE__
     1.9 +#include <GLUT/glut.h>
    1.10 +#else
    1.11 +#include <GL/glut.h>
    1.12 +#endif
    1.13 +#include "game.h"
    1.14 +
    1.15 +static void display();
    1.16 +static void reshape(int x, int y);
    1.17 +static void keypress(unsigned char key, int x, int y);
    1.18 +static void keyrelease(unsigned char key, int x, int y);
    1.19 +static void mouse(int bn, int st, int x, int y);
    1.20 +static void motion(int x, int y);
    1.21 +
    1.22 +int main(int argc, char **argv)
    1.23 +{
    1.24 +	glutInit(&argc, argv);
    1.25 +	glutInitWindowSize(1280, 800);
    1.26 +	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    1.27 +	glutCreateWindow("Tavli");
    1.28 +
    1.29 +	glutDisplayFunc(display);
    1.30 +	glutReshapeFunc(reshape);
    1.31 +	glutKeyboardFunc(keypress);
    1.32 +	glutKeyboardUpFunc(keyrelease);
    1.33 +	glutMouseFunc(mouse);
    1.34 +	glutMotionFunc(motion);
    1.35 +	glutPassiveMotionFunc(motion);
    1.36 +
    1.37 +	glewInit();
    1.38 +
    1.39 +	if(!game_init()) {
    1.40 +		return 1;
    1.41 +	}
    1.42 +	atexit(game_cleanup);
    1.43 +
    1.44 +	glutMainLoop();
    1.45 +	return 0;
    1.46 +}
    1.47 +
    1.48 +void redisplay()
    1.49 +{
    1.50 +	glutPostRedisplay();
    1.51 +}
    1.52 +
    1.53 +void quit()
    1.54 +{
    1.55 +	exit(0);
    1.56 +}
    1.57 +
    1.58 +static void display()
    1.59 +{
    1.60 +	unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
    1.61 +	game_update(msec);
    1.62 +	game_display();
    1.63 +
    1.64 +	assert(glGetError() == GL_NO_ERROR);
    1.65 +	glutSwapBuffers();
    1.66 +}
    1.67 +
    1.68 +static void reshape(int x, int y)
    1.69 +{
    1.70 +	win_width = x;
    1.71 +	win_height = y;
    1.72 +
    1.73 +	game_reshape(x, y);
    1.74 +}
    1.75 +
    1.76 +static void keypress(unsigned char key, int x, int y)
    1.77 +{
    1.78 +	game_keyboard(key, true);
    1.79 +}
    1.80 +
    1.81 +static void keyrelease(unsigned char key, int x, int y)
    1.82 +{
    1.83 +	game_keyboard(key, false);
    1.84 +}
    1.85 +
    1.86 +static void mouse(int bn, int st, int x, int y)
    1.87 +{
    1.88 +	game_mbutton(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
    1.89 +}
    1.90 +
    1.91 +static void motion(int x, int y)
    1.92 +{
    1.93 +	game_mmotion(x, y);
    1.94 +}