3dphotoshoot

view src/game.c @ 4:38377f54527a

having a whack at the camera api... at least the java crap compiles, we'll try calling it later
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 19 May 2015 06:05:51 +0300
parents a4bf2687e406
children 7f6e6eb3d20e
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include "opengl.h"
5 #include "game.h"
7 static int win_width, win_height;
10 int game_init(void)
11 {
12 glEnable(GL_DEPTH_TEST);
13 glEnable(GL_CULL_FACE);
14 glEnable(GL_LIGHTING);
16 glClearColor(0.4, 0.4, 0.4, 1);
17 return 0;
18 }
20 void game_shutdown(void)
21 {
22 }
24 void game_display(unsigned long msec)
25 {
26 //float tsec = (float)msec / 1000.0f;
28 //glClearColor(sin(tsec * 10.0), cos(tsec * 10.0), -sin(tsec * 10.0), 1.0);
29 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
31 glMatrixMode(GL_MODELVIEW);
32 glLoadIdentity();
33 }
35 void game_reshape(int x, int y)
36 {
37 win_width = x;
38 win_height = y;
39 glViewport(0, 0, x, y);
41 glMatrixMode(GL_PROJECTION);
42 glLoadIdentity();
43 glScalef((float)win_height / (float)win_width, 1.0, 1.0);
44 }
46 void game_keyboard(int key, int pressed)
47 {
48 if(!pressed) return;
50 switch(key) {
51 case 27:
52 exit(0);
54 default:
55 break;
56 }
57 }
59 #define MAX_TOUCH_IDS 16
60 static struct {
61 int bnstate[8];
62 int prev_x, prev_y;
63 } mstate[MAX_TOUCH_IDS];
65 void game_mouse_button(int id, int bn, int pressed, int x, int y)
66 {
67 if(id >= MAX_TOUCH_IDS) return;
69 mstate[id].prev_x = x;
70 mstate[id].prev_y = y;
71 mstate[id].bnstate[bn] = pressed;
72 }
74 void game_mouse_motion(int id, int x, int y)
75 {
76 /*
77 int dx, dy, cx, cy;
79 if(id >= MAX_TOUCH_IDS) return;
81 cx = win_width / 2;
82 cy = win_height / 2;
84 dx = x - mstate[id].prev_x;
85 dy = y - mstate[id].prev_y;
86 mstate[id].prev_x = x;
87 mstate[id].prev_y = y;
89 if(!dx && !dy) return;
91 if(mouselook || mstate[id].bnstate[0]) {
92 player_turn(&player, dx * 0.5, dy * 0.5);
93 }
94 if(mstate[id].bnstate[2]) {
95 dbg_cam_dist += 0.1 * dy;
96 if(dbg_cam_dist < 0.0) dbg_cam_dist = 0.0;
97 }
99 if(mouselook) {
100 warping_mouse = 1;
101 set_mouse_pos(cx, cy);
102 mstate[id].prev_x = cx;
103 mstate[id].prev_y = cy;
104 }
105 */
106 }