conworlds

diff src/main.cc @ 0:b326d53321f7

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 25 Apr 2014 05:20:53 +0300
parents
children 879194e4b1f0
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/main.cc	Fri Apr 25 05:20:53 2014 +0300
     1.3 @@ -0,0 +1,111 @@
     1.4 +#include <stdio.h>
     1.5 +#include <stdlib.h>
     1.6 +#include "opengl.h"
     1.7 +#include "game.h"
     1.8 +
     1.9 +static bool init();
    1.10 +static void cleanup();
    1.11 +
    1.12 +static void display();
    1.13 +static void idle();
    1.14 +static void reshape(int x, int y);
    1.15 +static void keyb(unsigned char key, int x, int y);
    1.16 +static void keyb_up(unsigned char key, int x, int y);
    1.17 +static void mouse(int bn, int st, int x, int y);
    1.18 +static void motion(int x, int y);
    1.19 +static void sball_motion(int x, int y, int z);
    1.20 +static void sball_rotate(int x, int y, int z);
    1.21 +
    1.22 +int main(int argc, char **argv)
    1.23 +{
    1.24 +	glutInitWindowSize(1024, 600);
    1.25 +	glutInit(&argc, argv);
    1.26 +	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    1.27 +	glutCreateWindow("VR Chess");
    1.28 +
    1.29 +	glutDisplayFunc(display);
    1.30 +	glutIdleFunc(idle);
    1.31 +	glutReshapeFunc(reshape);
    1.32 +	glutKeyboardFunc(keyb);
    1.33 +	glutKeyboardUpFunc(keyb_up);
    1.34 +	glutMouseFunc(mouse);
    1.35 +	glutMotionFunc(motion);
    1.36 +	glutSpaceballMotionFunc(sball_motion);
    1.37 +	glutSpaceballRotateFunc(sball_rotate);
    1.38 +
    1.39 +	if(!init()) {
    1.40 +		return 1;
    1.41 +	}
    1.42 +	atexit(cleanup);
    1.43 +
    1.44 +	glutMainLoop();
    1.45 +	return 0;
    1.46 +}
    1.47 +
    1.48 +static bool init()
    1.49 +{
    1.50 +	glewInit();
    1.51 +
    1.52 +	if(!game_init()) {
    1.53 +		return false;
    1.54 +	}
    1.55 +	return true;
    1.56 +}
    1.57 +
    1.58 +static void cleanup()
    1.59 +{
    1.60 +	game_cleanup();
    1.61 +}
    1.62 +
    1.63 +static void display()
    1.64 +{
    1.65 +	unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
    1.66 +
    1.67 +	game_update(msec);
    1.68 +	game_render(0);
    1.69 +
    1.70 +	glutSwapBuffers();
    1.71 +}
    1.72 +
    1.73 +static void idle()
    1.74 +{
    1.75 +	glutPostRedisplay();
    1.76 +}
    1.77 +
    1.78 +static void reshape(int x, int y)
    1.79 +{
    1.80 +	game_reshape(x, y);
    1.81 +}
    1.82 +
    1.83 +static void keyb(unsigned char key, int x, int y)
    1.84 +{
    1.85 +	game_keyboard(key, true, x, y);
    1.86 +}
    1.87 +
    1.88 +static void keyb_up(unsigned char key, int x, int y)
    1.89 +{
    1.90 +	game_keyboard(key, false, x, y);
    1.91 +}
    1.92 +
    1.93 +static void mouse(int bn, int st, int x, int y)
    1.94 +{
    1.95 +	game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
    1.96 +}
    1.97 +
    1.98 +static void motion(int x, int y)
    1.99 +{
   1.100 +	game_motion(x, y);
   1.101 +}
   1.102 +
   1.103 +#define SBALL_MOVE_SCALE	0.00025
   1.104 +#define SBALL_ROT_SCALE		0.01
   1.105 +
   1.106 +static void sball_motion(int x, int y, int z)
   1.107 +{
   1.108 +	game_6dof_move(x * SBALL_MOVE_SCALE, y * SBALL_MOVE_SCALE, z * SBALL_MOVE_SCALE);
   1.109 +}
   1.110 +
   1.111 +static void sball_rotate(int x, int y, int z)
   1.112 +{
   1.113 +	game_6dof_rotate(x * SBALL_ROT_SCALE, y * SBALL_ROT_SCALE, z * SBALL_ROT_SCALE);
   1.114 +}
   1.115 \ No newline at end of file