rev |
line source |
nuclear@0
|
1 #include <stdio.h>
|
nuclear@0
|
2 #include <stdlib.h>
|
nuclear@0
|
3 #include <math.h>
|
nuclear@0
|
4 #include "opengl.h"
|
nuclear@0
|
5 #include "game.h"
|
nuclear@7
|
6 #include "camera.h"
|
nuclear@7
|
7
|
nuclear@7
|
8 static void draw_quad(float sz);
|
nuclear@0
|
9
|
nuclear@0
|
10 static int win_width, win_height;
|
nuclear@0
|
11
|
nuclear@0
|
12
|
nuclear@0
|
13 int game_init(void)
|
nuclear@0
|
14 {
|
nuclear@0
|
15 glEnable(GL_DEPTH_TEST);
|
nuclear@0
|
16 glEnable(GL_CULL_FACE);
|
nuclear@7
|
17 //glEnable(GL_LIGHTING);
|
nuclear@0
|
18
|
nuclear@0
|
19 glClearColor(0.4, 0.4, 0.4, 1);
|
nuclear@0
|
20 return 0;
|
nuclear@0
|
21 }
|
nuclear@0
|
22
|
nuclear@0
|
23 void game_shutdown(void)
|
nuclear@0
|
24 {
|
nuclear@0
|
25 }
|
nuclear@0
|
26
|
nuclear@0
|
27 void game_display(unsigned long msec)
|
nuclear@0
|
28 {
|
nuclear@7
|
29 unsigned int tex = cam_texture();
|
nuclear@7
|
30 //cam_update();
|
nuclear@7
|
31
|
nuclear@4
|
32 //float tsec = (float)msec / 1000.0f;
|
nuclear@0
|
33
|
nuclear@4
|
34 //glClearColor(sin(tsec * 10.0), cos(tsec * 10.0), -sin(tsec * 10.0), 1.0);
|
nuclear@0
|
35 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
nuclear@0
|
36
|
nuclear@0
|
37 glMatrixMode(GL_MODELVIEW);
|
nuclear@0
|
38 glLoadIdentity();
|
nuclear@7
|
39
|
nuclear@7
|
40 if(tex) {
|
nuclear@7
|
41 glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex);
|
nuclear@7
|
42 glEnable(GL_TEXTURE_EXTERNAL_OES);
|
nuclear@7
|
43
|
nuclear@7
|
44 draw_quad(0.5);
|
nuclear@7
|
45
|
nuclear@7
|
46 glDisable(GL_TEXTURE_EXTERNAL_OES);
|
nuclear@7
|
47 }
|
nuclear@7
|
48 }
|
nuclear@7
|
49
|
nuclear@7
|
50 static void draw_quad(float sz)
|
nuclear@7
|
51 {
|
nuclear@7
|
52 static const float varr[] = {-1, -1, 1, -1, 1, 1, -1, 1};
|
nuclear@7
|
53 static const float tcarr[] = {0, 0, 1, 0, 1, 1, 0, 1};
|
nuclear@7
|
54 static const float colarr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
nuclear@7
|
55
|
nuclear@7
|
56 glPushMatrix();
|
nuclear@7
|
57 glScalef(sz, sz, sz);
|
nuclear@7
|
58
|
nuclear@7
|
59 glEnableClientState(GL_VERTEX_ARRAY);
|
nuclear@7
|
60 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
nuclear@7
|
61 glEnableClientState(GL_COLOR_ARRAY);
|
nuclear@7
|
62
|
nuclear@7
|
63 glVertexPointer(2, GL_FLOAT, 0, varr);
|
nuclear@7
|
64 glTexCoordPointer(2, GL_FLOAT, 0, tcarr);
|
nuclear@7
|
65 glColorPointer(3, GL_FLOAT, 0, colarr);
|
nuclear@7
|
66
|
nuclear@7
|
67 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
nuclear@7
|
68
|
nuclear@7
|
69 glDisableClientState(GL_VERTEX_ARRAY);
|
nuclear@7
|
70 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
nuclear@7
|
71 glDisableClientState(GL_COLOR_ARRAY);
|
nuclear@7
|
72
|
nuclear@7
|
73 glPopMatrix();
|
nuclear@0
|
74 }
|
nuclear@0
|
75
|
nuclear@0
|
76 void game_reshape(int x, int y)
|
nuclear@0
|
77 {
|
nuclear@0
|
78 win_width = x;
|
nuclear@0
|
79 win_height = y;
|
nuclear@0
|
80 glViewport(0, 0, x, y);
|
nuclear@0
|
81
|
nuclear@0
|
82 glMatrixMode(GL_PROJECTION);
|
nuclear@0
|
83 glLoadIdentity();
|
nuclear@0
|
84 glScalef((float)win_height / (float)win_width, 1.0, 1.0);
|
nuclear@0
|
85 }
|
nuclear@0
|
86
|
nuclear@0
|
87 void game_keyboard(int key, int pressed)
|
nuclear@0
|
88 {
|
nuclear@0
|
89 if(!pressed) return;
|
nuclear@0
|
90
|
nuclear@0
|
91 switch(key) {
|
nuclear@0
|
92 case 27:
|
nuclear@0
|
93 exit(0);
|
nuclear@0
|
94
|
nuclear@0
|
95 default:
|
nuclear@0
|
96 break;
|
nuclear@0
|
97 }
|
nuclear@0
|
98 }
|
nuclear@0
|
99
|
nuclear@0
|
100 #define MAX_TOUCH_IDS 16
|
nuclear@0
|
101 static struct {
|
nuclear@0
|
102 int bnstate[8];
|
nuclear@0
|
103 int prev_x, prev_y;
|
nuclear@0
|
104 } mstate[MAX_TOUCH_IDS];
|
nuclear@0
|
105
|
nuclear@0
|
106 void game_mouse_button(int id, int bn, int pressed, int x, int y)
|
nuclear@0
|
107 {
|
nuclear@0
|
108 if(id >= MAX_TOUCH_IDS) return;
|
nuclear@0
|
109
|
nuclear@0
|
110 mstate[id].prev_x = x;
|
nuclear@0
|
111 mstate[id].prev_y = y;
|
nuclear@0
|
112 mstate[id].bnstate[bn] = pressed;
|
nuclear@0
|
113 }
|
nuclear@0
|
114
|
nuclear@0
|
115 void game_mouse_motion(int id, int x, int y)
|
nuclear@0
|
116 {
|
nuclear@0
|
117 /*
|
nuclear@0
|
118 int dx, dy, cx, cy;
|
nuclear@0
|
119
|
nuclear@0
|
120 if(id >= MAX_TOUCH_IDS) return;
|
nuclear@0
|
121
|
nuclear@0
|
122 cx = win_width / 2;
|
nuclear@0
|
123 cy = win_height / 2;
|
nuclear@0
|
124
|
nuclear@0
|
125 dx = x - mstate[id].prev_x;
|
nuclear@0
|
126 dy = y - mstate[id].prev_y;
|
nuclear@0
|
127 mstate[id].prev_x = x;
|
nuclear@0
|
128 mstate[id].prev_y = y;
|
nuclear@0
|
129
|
nuclear@0
|
130 if(!dx && !dy) return;
|
nuclear@0
|
131
|
nuclear@0
|
132 if(mouselook || mstate[id].bnstate[0]) {
|
nuclear@0
|
133 player_turn(&player, dx * 0.5, dy * 0.5);
|
nuclear@0
|
134 }
|
nuclear@0
|
135 if(mstate[id].bnstate[2]) {
|
nuclear@0
|
136 dbg_cam_dist += 0.1 * dy;
|
nuclear@0
|
137 if(dbg_cam_dist < 0.0) dbg_cam_dist = 0.0;
|
nuclear@0
|
138 }
|
nuclear@0
|
139
|
nuclear@0
|
140 if(mouselook) {
|
nuclear@0
|
141 warping_mouse = 1;
|
nuclear@0
|
142 set_mouse_pos(cx, cy);
|
nuclear@0
|
143 mstate[id].prev_x = cx;
|
nuclear@0
|
144 mstate[id].prev_y = cy;
|
nuclear@0
|
145 }
|
nuclear@0
|
146 */
|
nuclear@0
|
147 }
|
nuclear@0
|
148
|