3dphotoshoot
view 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 source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "opengl.h"
4 #include <GL/glut.h>
5 #include "game.h"
6 #include "camera.h"
7 #include "timer.h"
9 static int init(void);
10 static void cleanup(void);
11 static void display(void);
12 static void idle(void);
13 static void reshape(int x, int y);
14 static void keyb(unsigned char key, int x, int y);
15 static void keyb_release(unsigned char key, int x, int y);
16 static void mouse(int bn, int state, int x, int y);
17 static void motion(int x, int y);
18 static void sball_motion(int x, int y, int z);
19 static void sball_rotate(int x, int y, int z);
21 int main(int argc, char **argv)
22 {
23 glutInit(&argc, argv);
24 glutInitWindowSize(800, 600);
25 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
26 glutCreateWindow("3dphotoshoot (PC)");
28 glutDisplayFunc(display);
29 glutIdleFunc(idle);
30 glutReshapeFunc(reshape);
31 glutKeyboardFunc(keyb);
32 glutKeyboardUpFunc(keyb_release);
33 glutMouseFunc(mouse);
34 glutMotionFunc(motion);
35 glutSpaceballMotionFunc(sball_motion);
36 glutSpaceballRotateFunc(sball_rotate);
38 if(init() == -1) {
39 return 1;
40 }
41 atexit(cleanup);
43 glutMainLoop();
44 return 0;
45 }
47 static int init(void)
48 {
49 glewInit();
51 if(cam_init(0) == -1) {
52 return -1;
53 }
55 if(game_init() == -1) {
56 return -1;
57 }
58 return 0;
59 }
61 static void cleanup(void)
62 {
63 game_shutdown();
64 }
66 static void display(void)
67 {
68 game_display(get_time_msec());
69 glutSwapBuffers();
70 }
72 static void idle(void)
73 {
74 glutPostRedisplay();
75 }
77 static void reshape(int x, int y)
78 {
79 game_reshape(x, y);
80 }
82 static void keyb(unsigned char key, int x, int y)
83 {
84 switch(key) {
85 case 27:
86 exit(0);
87 }
89 game_keyboard(key, 1);
90 }
92 static void keyb_release(unsigned char key, int x, int y)
93 {
94 game_keyboard(key, 0);
95 }
97 static void mouse(int bn, int state, int x, int y)
98 {
99 game_mouse_button(0, bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN ? 1 : 0, x, y);
100 }
102 static void motion(int x, int y)
103 {
104 game_mouse_motion(0, x, y);
105 }
107 static void sball_motion(int x, int y, int z)
108 {
109 }
111 static void sball_rotate(int x, int y, int z)
112 {
113 }