3dphotoshoot

diff src/pc/main.c @ 26:a460b1e5af4a

added GLUT frontend
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 18 Jun 2015 03:55:05 +0300
parents
children 3d082c566b53
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/pc/main.c	Thu Jun 18 03:55:05 2015 +0300
     1.3 @@ -0,0 +1,113 @@
     1.4 +#include <stdio.h>
     1.5 +#include <stdlib.h>
     1.6 +#include "opengl.h"
     1.7 +#include <GL/glut.h>
     1.8 +#include "game.h"
     1.9 +#include "camera.h"
    1.10 +#include "timer.h"
    1.11 +
    1.12 +static int init(void);
    1.13 +static void cleanup(void);
    1.14 +static void display(void);
    1.15 +static void idle(void);
    1.16 +static void reshape(int x, int y);
    1.17 +static void keyb(unsigned char key, int x, int y);
    1.18 +static void keyb_release(unsigned char key, int x, int y);
    1.19 +static void mouse(int bn, int state, int x, int y);
    1.20 +static void motion(int x, int y);
    1.21 +static void sball_motion(int x, int y, int z);
    1.22 +static void sball_rotate(int x, int y, int z);
    1.23 +
    1.24 +int main(int argc, char **argv)
    1.25 +{
    1.26 +	glutInit(&argc, argv);
    1.27 +	glutInitWindowSize(800, 600);
    1.28 +	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    1.29 +	glutCreateWindow("3dphotoshoot (PC)");
    1.30 +
    1.31 +	glutDisplayFunc(display);
    1.32 +	glutIdleFunc(idle);
    1.33 +	glutReshapeFunc(reshape);
    1.34 +	glutKeyboardFunc(keyb);
    1.35 +	glutKeyboardUpFunc(keyb_release);
    1.36 +	glutMouseFunc(mouse);
    1.37 +	glutMotionFunc(motion);
    1.38 +	glutSpaceballMotionFunc(sball_motion);
    1.39 +	glutSpaceballRotateFunc(sball_rotate);
    1.40 +
    1.41 +	if(init() == -1) {
    1.42 +		return 1;
    1.43 +	}
    1.44 +	atexit(cleanup);
    1.45 +
    1.46 +	glutMainLoop();
    1.47 +	return 0;
    1.48 +}
    1.49 +
    1.50 +static int init(void)
    1.51 +{
    1.52 +	glewInit();
    1.53 +
    1.54 +	if(cam_init(0) == -1) {
    1.55 +		return -1;
    1.56 +	}
    1.57 +
    1.58 +	if(game_init() == -1) {
    1.59 +		return -1;
    1.60 +	}
    1.61 +	return 0;
    1.62 +}
    1.63 +
    1.64 +static void cleanup(void)
    1.65 +{
    1.66 +	game_shutdown();
    1.67 +}
    1.68 +
    1.69 +static void display(void)
    1.70 +{
    1.71 +	game_display(get_time_msec());
    1.72 +	glutSwapBuffers();
    1.73 +}
    1.74 +
    1.75 +static void idle(void)
    1.76 +{
    1.77 +	glutPostRedisplay();
    1.78 +}
    1.79 +
    1.80 +static void reshape(int x, int y)
    1.81 +{
    1.82 +	game_reshape(x, y);
    1.83 +}
    1.84 +
    1.85 +static void keyb(unsigned char key, int x, int y)
    1.86 +{
    1.87 +	switch(key) {
    1.88 +	case 27:
    1.89 +		exit(0);
    1.90 +	}
    1.91 +
    1.92 +	game_keyboard(key, 1);
    1.93 +}
    1.94 +
    1.95 +static void keyb_release(unsigned char key, int x, int y)
    1.96 +{
    1.97 +	game_keyboard(key, 0);
    1.98 +}
    1.99 +
   1.100 +static void mouse(int bn, int state, int x, int y)
   1.101 +{
   1.102 +	game_mouse_button(0, bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN ? 1 : 0, x, y);
   1.103 +}
   1.104 +
   1.105 +static void motion(int x, int y)
   1.106 +{
   1.107 +	game_mouse_motion(0, x, y);
   1.108 +}
   1.109 +
   1.110 +static void sball_motion(int x, int y, int z)
   1.111 +{
   1.112 +}
   1.113 +
   1.114 +static void sball_rotate(int x, int y, int z)
   1.115 +{
   1.116 +}