1 | // |
---|
2 | // Neercs |
---|
3 | // |
---|
4 | |
---|
5 | #if defined HAVE_CONFIG_H |
---|
6 | # include "config.h" |
---|
7 | #endif |
---|
8 | |
---|
9 | #if defined _XBOX |
---|
10 | # define _USE_MATH_DEFINES /* for M_PI */ |
---|
11 | # include <xtl.h> |
---|
12 | #elif defined _WIN32 |
---|
13 | # define _USE_MATH_DEFINES /* for M_PI */ |
---|
14 | # define WIN32_LEAN_AND_MEAN |
---|
15 | # include <windows.h> |
---|
16 | #endif |
---|
17 | |
---|
18 | #include <cmath> |
---|
19 | #include <cstdio> |
---|
20 | #include <cstdlib> |
---|
21 | #include <ctime> |
---|
22 | #include <string> |
---|
23 | |
---|
24 | #include "core.h" |
---|
25 | #include "lolgl.h" |
---|
26 | |
---|
27 | using namespace std; |
---|
28 | using namespace lol; |
---|
29 | |
---|
30 | #include "../neercs.h" |
---|
31 | #include "render.h" |
---|
32 | |
---|
33 | extern char const *lolfx_blurh; |
---|
34 | extern char const *lolfx_blurv; |
---|
35 | extern char const *lolfx_glow; |
---|
36 | extern char const *lolfx_postfx; |
---|
37 | extern char const *lolfx_radial; |
---|
38 | extern char const *lolfx_simple; |
---|
39 | |
---|
40 | #define WIN32_LEAN_AND_MEAN |
---|
41 | #define DEBUG 1 // debug flag //#if defined(_DEBUG) |
---|
42 | #define SHADER 1 // shader flag |
---|
43 | #define PI 3.1415926535f // pi |
---|
44 | #define PID PI/180.0f // pi ratio |
---|
45 | #define CR 1.0f/256.0f // color ratio |
---|
46 | |
---|
47 | bool done = false; |
---|
48 | |
---|
49 | //char *param=GetCommandLine(); |
---|
50 | |
---|
51 | int keys[256]; // keyboard array |
---|
52 | int active = true; // window active flag |
---|
53 | bool fullscreen = DEBUG?false:true; // fullscreen flag |
---|
54 | bool pause = false; // pause flag |
---|
55 | float nearplane = 0.1f; // nearplane |
---|
56 | float farplane = 1000.0f; // farplane |
---|
57 | bool polygon = true; // polygon mode |
---|
58 | int polygon_fillmode = GL_FILL; // fill mode |
---|
59 | int ratio_2d = 4; // 2d ratio |
---|
60 | /* window variable */ |
---|
61 | int base_w = 800; // base width |
---|
62 | int base_h = 600; // base height |
---|
63 | int window_w = base_w; // width |
---|
64 | int window_h = base_h; // height |
---|
65 | ivec2 screen_size; // screen size |
---|
66 | int window_color = 32; // color depth |
---|
67 | vec3 screen_color; // screen color |
---|
68 | /* object variable */ |
---|
69 | float main_angle; // main angle |
---|
70 | float part_angle; // part angle |
---|
71 | float fx_angle; // current angle |
---|
72 | /* liner variable */ |
---|
73 | int car; // ascii code |
---|
74 | int car_cursor = 126; // cursor ascii code |
---|
75 | int liner_length; // text length |
---|
76 | int liner_line_n; // line number |
---|
77 | int liner_line; // line increment |
---|
78 | int liner_max; // line max length |
---|
79 | int liner_i; // char increment |
---|
80 | int liner_count; // counter |
---|
81 | /* text variable */ |
---|
82 | char const *name = "cacaShell"; |
---|
83 | std::string txt(""); |
---|
84 | /* fs_quad variable */ |
---|
85 | float fs_quad_vtx[] = {-1.0f, 1.0f, 0, 1.0f, -1.0f, -1.0f, 0, 1.0f, 1.0f, -1.0f, 0, 1.0f, 1.0f, 1.0f, 0, 1.0f}; |
---|
86 | float fs_quad_tex[] = {0, 1.0f, 0, 0, 1.0f, 0, 1.0f, 1.0f}; |
---|
87 | /* flash variable */ |
---|
88 | bool flash_flag = false; // flag |
---|
89 | float flash_angle = 0; // angle |
---|
90 | float flash_value = 0; // value |
---|
91 | float flash_speed; // speed |
---|
92 | /* fade variable */ |
---|
93 | bool fade_flag = false; // flag |
---|
94 | float fade_angle = 0; // angle |
---|
95 | float fade_value = 0; // value |
---|
96 | float fade_speed; // speed |
---|
97 | /* debug variable */ |
---|
98 | bool debug_flag = false; // flag |
---|
99 | int debug_x; // position x |
---|
100 | int debug_y; // position y |
---|
101 | int debug_w; // width |
---|
102 | int debug_h; // height |
---|
103 | int debug_vtx[8]; // vertex array |
---|
104 | /* sync variable */ |
---|
105 | bool sync_flag = false; // flag |
---|
106 | float sync_angle = 0; // angle |
---|
107 | float sync_value = 0; // value |
---|
108 | float sync_speed; // speed |
---|
109 | /* beat variable */ |
---|
110 | bool beat_flag = false; // flag |
---|
111 | float beat_angle = 0; // angle |
---|
112 | float beat_value = 0; // value |
---|
113 | float beat_speed; // speed |
---|
114 | /* corner variable */ |
---|
115 | const int corner_n = 10; // polygon number |
---|
116 | int corner_w = 24; // radius |
---|
117 | int corner_vtx[corner_n*6];// vertex array |
---|
118 | /* dos variable */ |
---|
119 | bool dos_flag = false; // flag |
---|
120 | int dos_w; // width |
---|
121 | int dos_h; // height |
---|
122 | int dos_m; // margin |
---|
123 | vec3 dos_color; // color value |
---|
124 | int dos_vtx[8]; // vertex array |
---|
125 | int shell_vtx[8]; // vertex array |
---|
126 | float shell_tex[] = {1.0f, 0.96875f, 1.0f, 1.0f, 0.78125f, 1.0f, 0.78125f, 0.96875f}; |
---|
127 | /* keyboard variable */ |
---|
128 | int key_code = 0; // keyboard code |
---|
129 | /* common variable */ |
---|
130 | int i, j, k, l; |
---|
131 | float x, y, z, w, h; |
---|
132 | float r, g, b, c; |
---|
133 | float value, angle, radius, scale, speed; |
---|
134 | TileSet *tex_map; |
---|
135 | /* shader variable */ |
---|
136 | bool shader_flag = SHADER?true:false; |
---|
137 | bool shader_blur_flag = SHADER?true:false; |
---|
138 | bool shader_effect_flag = SHADER?true:false; |
---|
139 | bool shader_glow_flag = true; |
---|
140 | int glow_fbo_size = 2; // glow fbo size |
---|
141 | int glow_color; // 0 = color/1 = alpha |
---|
142 | float glow_smoothstep; // glow smoothstep value |
---|
143 | float glow_mix_ratio1; // glow mixing ratio |
---|
144 | float glow_mix_ratio2; // source mixing ratio |
---|
145 | bool shader_radial_flag = false; |
---|
146 | float radial_value1; |
---|
147 | float radial_value2; |
---|
148 | float radial_color; // color |
---|
149 | bool shader_postfx_flag = SHADER?true:false; |
---|
150 | bool postfx_scanline = true; |
---|
151 | float postfx_deform; // deformation ratio |
---|
152 | #if SHADER |
---|
153 | Shader *shader_simple, *shader_blur_h, *shader_blur_v; |
---|
154 | Shader *shader_glow, *shader_radial, *shader_postfx; |
---|
155 | // shader variables |
---|
156 | ShaderUniform shader_simple_texture; |
---|
157 | ShaderUniform shader_blur_h_texture, |
---|
158 | shader_blur_h_screen_size, |
---|
159 | shader_blur_h_time, |
---|
160 | shader_blur_h_value; |
---|
161 | ShaderUniform shader_blur_v_texture, |
---|
162 | shader_blur_v_screen_size, |
---|
163 | shader_blur_v_time, |
---|
164 | shader_blur_v_value; |
---|
165 | ShaderUniform shader_glow_texture, |
---|
166 | shader_glow_texture_prv, |
---|
167 | shader_glow_screen_size, |
---|
168 | shader_glow_time, |
---|
169 | shader_glow_step, |
---|
170 | shader_glow_value1, |
---|
171 | shader_glow_value2; |
---|
172 | ShaderUniform shader_radial_texture, |
---|
173 | shader_radial_screen_size, |
---|
174 | shader_radial_time, |
---|
175 | shader_radial_value1, |
---|
176 | shader_radial_value2, |
---|
177 | shader_radial_color; |
---|
178 | ShaderUniform shader_postfx_texture, |
---|
179 | shader_postfx_texture_2d, |
---|
180 | shader_postfx_screen_size, |
---|
181 | shader_postfx_time, |
---|
182 | shader_postfx_flash, |
---|
183 | shader_postfx_value, |
---|
184 | shader_postfx_deform, |
---|
185 | shader_postfx_scanline, |
---|
186 | shader_postfx_sync; |
---|
187 | |
---|
188 | FrameBuffer *fbo_back, *fbo_front, *fbo_blur_h, *fbo_blur_v; |
---|
189 | FrameBuffer *fbo_ping, *fbo_pong; |
---|
190 | #endif |
---|
191 | |
---|
192 | void init_viewport(int type) |
---|
193 | { |
---|
194 | glViewport(0, 0, screen_size.x, screen_size.y); |
---|
195 | glMatrixMode(GL_PROJECTION); |
---|
196 | glLoadIdentity(); |
---|
197 | mat4 proj = (type == 0) ? mat4::perspective(70, (float)screen_size.x, (float)screen_size.y, nearplane, farplane) : mat4::ortho(0, screen_size.x, screen_size.y, 0); |
---|
198 | glLoadMatrixf(&proj[0][0]); |
---|
199 | glMatrixMode(GL_MODELVIEW); |
---|
200 | } |
---|
201 | |
---|
202 | #if SHADER |
---|
203 | void init_shader() |
---|
204 | { |
---|
205 | glDisable(GL_BLEND); |
---|
206 | glVertexPointer(4, GL_FLOAT, 0, fs_quad_vtx); |
---|
207 | glTexCoordPointer(2, GL_FLOAT, 0, fs_quad_tex); |
---|
208 | } |
---|
209 | |
---|
210 | void fs_quad() |
---|
211 | { |
---|
212 | glLoadIdentity(); |
---|
213 | glDrawArrays(GL_QUADS, 0, 4); |
---|
214 | } |
---|
215 | |
---|
216 | void draw_shader_simple(FrameBuffer *fbo_output, int n) |
---|
217 | { |
---|
218 | shader_simple->Bind(); |
---|
219 | shader_simple->SetTexture(shader_simple_texture, fbo_output->GetTexture(), n); |
---|
220 | fs_quad(); |
---|
221 | shader_simple->Unbind(); |
---|
222 | } |
---|
223 | #endif |
---|
224 | |
---|
225 | void calc_txt() |
---|
226 | { |
---|
227 | liner_length = txt.length(); |
---|
228 | liner_count = 0; |
---|
229 | liner_line_n = 0; |
---|
230 | liner_max = 0; |
---|
231 | liner_i = 0; |
---|
232 | for(i = 0;i<liner_length;i++) |
---|
233 | { |
---|
234 | if((unsigned char)txt[i] != 13) |
---|
235 | { |
---|
236 | liner_i++; |
---|
237 | } |
---|
238 | else |
---|
239 | { |
---|
240 | if(liner_i>liner_max) liner_max = liner_i; |
---|
241 | liner_line_n++; |
---|
242 | liner_i = 0; |
---|
243 | } |
---|
244 | } |
---|
245 | if(liner_i>liner_max) liner_max = liner_i; |
---|
246 | } |
---|
247 | |
---|
248 | void rectangle(int x, int y, int w, int h) |
---|
249 | { |
---|
250 | glLoadIdentity(); |
---|
251 | glBegin(GL_QUADS); |
---|
252 | glVertex2i(x+w, y ); |
---|
253 | glVertex2i(x , y ); |
---|
254 | glVertex2i(x , y+h); |
---|
255 | glVertex2i(x+w, y+h); |
---|
256 | glEnd(); |
---|
257 | } |
---|
258 | |
---|
259 | void corner() |
---|
260 | { |
---|
261 | float vertex[2+corner_n*2]; |
---|
262 | vertex[0] = 0; |
---|
263 | vertex[1] = 0; |
---|
264 | for(i = 1;i<corner_n+1;i++) |
---|
265 | { |
---|
266 | j = i*2; |
---|
267 | float a = PID*90.0f/(corner_n-1)*(i-1); |
---|
268 | vertex[j ] = corner_w-corner_w*cosf(a); |
---|
269 | vertex[j+1] = corner_w-corner_w*sinf(a); |
---|
270 | } |
---|
271 | for(i = 0;i<corner_n;i++) |
---|
272 | { |
---|
273 | j = i*6; |
---|
274 | k = i*2; |
---|
275 | corner_vtx[j ] = (int)vertex[0]; |
---|
276 | corner_vtx[j+1] = (int)vertex[1]; |
---|
277 | corner_vtx[j+2] = (int)vertex[2+k]; |
---|
278 | corner_vtx[j+3] = (int)vertex[3+k]; |
---|
279 | corner_vtx[j+4] = (int)vertex[4+k]; |
---|
280 | corner_vtx[j+5] = (int)vertex[5+k]; |
---|
281 | } |
---|
282 | } |
---|
283 | |
---|
284 | void screen() |
---|
285 | { |
---|
286 | part_angle = main_angle; |
---|
287 | dos_flag = true; |
---|
288 | dos_color = CR * vec3(48, 56, 64); |
---|
289 | screen_color = dos_color; |
---|
290 | txt = "\rCopyright \x05e 2012 cacaShell v0.1\r "; |
---|
291 | calc_txt(); |
---|
292 | /*-------------------------*/ |
---|
293 | shader_effect_flag = true; |
---|
294 | shader_glow_flag = true; |
---|
295 | glow_color = 1; |
---|
296 | glow_smoothstep = 0;//.025f; |
---|
297 | glow_mix_ratio1 = 0.5f; |
---|
298 | glow_mix_ratio2 = 0.5f; |
---|
299 | shader_radial_flag = false; |
---|
300 | radial_value1 = 2.0f; |
---|
301 | radial_value2 = 0.8f; |
---|
302 | radial_color = 0; |
---|
303 | postfx_deform = 0.5f; |
---|
304 | /*-------------------------*/ |
---|
305 | flash_speed = 1.5f; |
---|
306 | fade_speed = 0.2f; |
---|
307 | sync_flag = false; |
---|
308 | sync_value = 1.0f; |
---|
309 | sync_speed = 1.0f; |
---|
310 | beat_speed = 2.0f; |
---|
311 | /*-------------------------*/ |
---|
312 | glClearColor(screen_color.r, screen_color.g, screen_color.b, 1.0f); |
---|
313 | } |
---|
314 | |
---|
315 | int InitGL(void) |
---|
316 | { |
---|
317 | glClearDepth(1.0f); // set depth buffer |
---|
318 | glDepthMask(GL_TRUE); // do not write z-buffer |
---|
319 | glEnable(GL_CULL_FACE); // disable cull face |
---|
320 | glCullFace(GL_BACK); // don't draw front face |
---|
321 | glEnableClientState(GL_VERTEX_ARRAY); |
---|
322 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
---|
323 | // load texture |
---|
324 | tex_map = new TileSet("neercs/video/resource/map.png", ivec2(256, 256), ivec2(1)); |
---|
325 | // initialize some variable |
---|
326 | screen(); |
---|
327 | /*-PATACODE----------------------------------------------------------------*/ |
---|
328 | #if SHADER |
---|
329 | if (shader_flag) |
---|
330 | { |
---|
331 | fbo_back = new FrameBuffer(screen_size); |
---|
332 | fbo_front = new FrameBuffer(screen_size); |
---|
333 | fbo_blur_h = new FrameBuffer(screen_size / glow_fbo_size); |
---|
334 | fbo_blur_v = new FrameBuffer(screen_size / glow_fbo_size); |
---|
335 | fbo_ping = new FrameBuffer(screen_size); |
---|
336 | fbo_pong = new FrameBuffer(screen_size); |
---|
337 | // shader simple |
---|
338 | shader_simple = Shader::Create(lolfx_simple); |
---|
339 | shader_simple_texture = shader_simple->GetUniformLocation("texture"); |
---|
340 | // shader blur horizontal |
---|
341 | shader_blur_h = Shader::Create(lolfx_blurh); |
---|
342 | shader_blur_h_texture = shader_blur_h->GetUniformLocation("texture"); |
---|
343 | shader_blur_h_screen_size = shader_blur_h->GetUniformLocation("screen_size"); |
---|
344 | shader_blur_h_time = shader_blur_h->GetUniformLocation("time"); |
---|
345 | shader_blur_h_value = shader_blur_h->GetUniformLocation("value"); |
---|
346 | // shader blur vertical |
---|
347 | shader_blur_v = Shader::Create(lolfx_blurv); |
---|
348 | shader_blur_v_texture = shader_blur_v->GetUniformLocation("texture"); |
---|
349 | shader_blur_v_screen_size = shader_blur_v->GetUniformLocation("screen_size"); |
---|
350 | shader_blur_v_time = shader_blur_v->GetUniformLocation("time"); |
---|
351 | shader_blur_v_value = shader_blur_v->GetUniformLocation("value"); |
---|
352 | // shader glow |
---|
353 | shader_glow = Shader::Create(lolfx_glow); |
---|
354 | shader_glow_texture = shader_glow->GetUniformLocation("texture"); |
---|
355 | shader_glow_texture_prv = shader_glow->GetUniformLocation("texture_prv"); |
---|
356 | shader_glow_screen_size = shader_glow->GetUniformLocation("screen_size"); |
---|
357 | shader_glow_time = shader_glow->GetUniformLocation("time"); |
---|
358 | shader_glow_step = shader_glow->GetUniformLocation("step"); |
---|
359 | shader_glow_value1 = shader_glow->GetUniformLocation("value1"); |
---|
360 | shader_glow_value2 = shader_glow->GetUniformLocation("value2"); |
---|
361 | // shader radial |
---|
362 | shader_radial = Shader::Create(lolfx_radial); |
---|
363 | shader_radial_texture = shader_radial->GetUniformLocation("texture"); |
---|
364 | shader_radial_screen_size = shader_radial->GetUniformLocation("screen_size"); |
---|
365 | shader_radial_time = shader_radial->GetUniformLocation("time"); |
---|
366 | shader_radial_value1 = shader_radial->GetUniformLocation("value1"); |
---|
367 | shader_radial_value2 = shader_radial->GetUniformLocation("value2"); |
---|
368 | shader_radial_color = shader_radial->GetUniformLocation("color"); |
---|
369 | // shader postfx |
---|
370 | shader_postfx = Shader::Create(lolfx_postfx); |
---|
371 | shader_postfx_texture = shader_postfx->GetUniformLocation("texture"); |
---|
372 | shader_postfx_texture_2d = shader_postfx->GetUniformLocation("texture_2d"); |
---|
373 | shader_postfx_screen_size = shader_postfx->GetUniformLocation("screen_size"); |
---|
374 | shader_postfx_time = shader_postfx->GetUniformLocation("time"); |
---|
375 | shader_postfx_flash = shader_postfx->GetUniformLocation("flash"); |
---|
376 | shader_postfx_value = shader_postfx->GetUniformLocation("value"); |
---|
377 | shader_postfx_deform = shader_postfx->GetUniformLocation("deform"); |
---|
378 | shader_postfx_scanline = shader_postfx->GetUniformLocation("scanline"); |
---|
379 | shader_postfx_sync = shader_postfx->GetUniformLocation("sync"); |
---|
380 | } |
---|
381 | #endif |
---|
382 | /*-/PATACODE---------------------------------------------------------------*/ |
---|
383 | return true; |
---|
384 | } |
---|
385 | |
---|
386 | int CreateGLWindow(char const *title) |
---|
387 | { |
---|
388 | screen_size = Video::GetSize(); |
---|
389 | //ratio_2d = (int)(screen_size.x/400); if(ratio_2d<2) ratio_2d = 2; |
---|
390 | corner_w = 16*ratio_2d; |
---|
391 | corner(); |
---|
392 | dos_w = 2*ratio_2d; |
---|
393 | dos_h = 4*ratio_2d; |
---|
394 | dos_m = 12*ratio_2d; |
---|
395 | dos_vtx[0] = dos_w; |
---|
396 | dos_vtx[1] = dos_h; |
---|
397 | dos_vtx[2] = dos_w; |
---|
398 | dos_vtx[3] = -dos_h; |
---|
399 | dos_vtx[4] = -dos_w; |
---|
400 | dos_vtx[5] = -dos_h; |
---|
401 | dos_vtx[6] = -dos_w; |
---|
402 | dos_vtx[7] = dos_h; |
---|
403 | shell_vtx[0] = dos_m+29*ratio_2d; |
---|
404 | shell_vtx[1] = dos_m+9*ratio_2d; |
---|
405 | shell_vtx[2] = dos_m+29*ratio_2d; |
---|
406 | shell_vtx[3] = dos_m+1*ratio_2d; |
---|
407 | shell_vtx[4] = dos_m+1*ratio_2d; |
---|
408 | shell_vtx[5] = dos_m+1*ratio_2d; |
---|
409 | shell_vtx[6] = dos_m+1*ratio_2d; |
---|
410 | shell_vtx[7] = dos_m+9*ratio_2d; |
---|
411 | debug_w = 5*ratio_2d; |
---|
412 | debug_h = 5*ratio_2d; |
---|
413 | debug_x = 10*ratio_2d; |
---|
414 | debug_y = 28*ratio_2d; |
---|
415 | debug_vtx[0] = debug_w; |
---|
416 | debug_vtx[1] = debug_h; |
---|
417 | debug_vtx[2] = debug_w; |
---|
418 | debug_vtx[3] = -debug_h; |
---|
419 | debug_vtx[4] = -debug_w; |
---|
420 | debug_vtx[5] = -debug_h; |
---|
421 | debug_vtx[6] = -debug_w; |
---|
422 | debug_vtx[7] = debug_h; |
---|
423 | InitGL(); |
---|
424 | return true; |
---|
425 | } |
---|
426 | |
---|
427 | Render::Render() |
---|
428 | { |
---|
429 | } |
---|
430 | |
---|
431 | void Render::TickGame(float seconds) |
---|
432 | { |
---|
433 | Entity::TickGame(seconds); |
---|
434 | } |
---|
435 | |
---|
436 | void Render::TickDraw(float seconds) |
---|
437 | { |
---|
438 | Entity::TickDraw(seconds); |
---|
439 | |
---|
440 | static int todo = 1; |
---|
441 | if (todo) |
---|
442 | { |
---|
443 | CreateGLWindow("LOL"); |
---|
444 | todo = 0; |
---|
445 | } |
---|
446 | |
---|
447 | // timer |
---|
448 | if(!pause) |
---|
449 | main_angle += seconds * 100.0f * PID; |
---|
450 | if(sync_flag) |
---|
451 | { |
---|
452 | angle=(main_angle-sync_angle)*sync_speed; |
---|
453 | sync_value=1.0f-sinf(angle); |
---|
454 | if(angle>90.0f*PID) |
---|
455 | { |
---|
456 | sync_value=0; |
---|
457 | sync_flag=false; |
---|
458 | } |
---|
459 | } |
---|
460 | if(beat_flag) |
---|
461 | { |
---|
462 | angle=(main_angle-beat_angle)*beat_speed; |
---|
463 | beat_value=1.0f-sinf(angle); |
---|
464 | if(angle>90.0f*PID) |
---|
465 | { |
---|
466 | beat_value=0; |
---|
467 | beat_flag=false; |
---|
468 | } |
---|
469 | } |
---|
470 | if(flash_flag) |
---|
471 | { |
---|
472 | angle=(main_angle-flash_angle)*flash_speed; |
---|
473 | flash_value=1.0f-sinf(angle); |
---|
474 | if(angle>90.0f*PID) |
---|
475 | { |
---|
476 | flash_value=0; |
---|
477 | flash_flag=false; |
---|
478 | } |
---|
479 | } |
---|
480 | if(fade_flag) |
---|
481 | { |
---|
482 | angle=(main_angle-fade_angle)*fade_speed; |
---|
483 | fade_value=1.0f-sinf(angle); |
---|
484 | if(angle>90.0f*PID) |
---|
485 | { |
---|
486 | fade_value=0; |
---|
487 | fade_flag=false; |
---|
488 | } |
---|
489 | } |
---|
490 | /*-PATACODE----------------------------------------------------------------*/ |
---|
491 | #if SHADER |
---|
492 | if(shader_flag) |
---|
493 | { |
---|
494 | fbo_back->Bind(); |
---|
495 | fbo_back->Clear(vec4(screen_color, 0.0f), 1.0f); |
---|
496 | } |
---|
497 | else |
---|
498 | { |
---|
499 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
---|
500 | } |
---|
501 | #else |
---|
502 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
---|
503 | #endif |
---|
504 | /*-/PATACODE---------------------------------------------------------------*/ |
---|
505 | glEnable(GL_BLEND); |
---|
506 | //if(polygon) glEnable(GL_LINE_SMOOTH); else glDisable(GL_LINE_SMOOTH); |
---|
507 | glLineWidth((polygon)?2.0f:1.0f); |
---|
508 | fx_angle=main_angle-part_angle; |
---|
509 | if(polygon) glEnable(GL_TEXTURE_2D); |
---|
510 | /* .-------------------. */ |
---|
511 | /* | DRAW SOME 2D HERE | */ |
---|
512 | /* °-------------------° */ |
---|
513 | init_viewport(1); |
---|
514 | tex_map->Bind(); |
---|
515 | glEnable(GL_BLEND); |
---|
516 | // draw dos |
---|
517 | if(dos_flag) |
---|
518 | { |
---|
519 | glDisable(GL_TEXTURE_2D); |
---|
520 | glDisable(GL_BLEND); |
---|
521 | glColor3f(1.0f, 1.0f, 1.0f); |
---|
522 | rectangle(dos_m, dos_m, screen_size.x-(int)(26.5f*ratio_2d)-dos_m*2, 10*ratio_2d); |
---|
523 | rectangle(screen_size.x-(int)(25.5f*ratio_2d)-dos_m, dos_m, 11*ratio_2d, 10*ratio_2d); |
---|
524 | rectangle(screen_size.x-(int)(13.5f*ratio_2d)-dos_m, dos_m, 11*ratio_2d, 10*ratio_2d); |
---|
525 | rectangle(screen_size.x-(int)(1.5f*ratio_2d)-dos_m, dos_m, (int)(1.5f*ratio_2d), 10*ratio_2d); |
---|
526 | rectangle(dos_m, dos_m+10*ratio_2d, 1*ratio_2d, screen_size.y-10*ratio_2d-dos_m*2); |
---|
527 | rectangle(screen_size.x-1*ratio_2d-dos_m, dos_m+10*ratio_2d, 1*ratio_2d, screen_size.y-10*ratio_2d-dos_m*2); |
---|
528 | rectangle(dos_m+1*ratio_2d, screen_size.y-1*ratio_2d-dos_m, screen_size.x-2*ratio_2d-dos_m*2, 1*ratio_2d); |
---|
529 | glColor3f(dos_color.r, dos_color.g, dos_color.b); |
---|
530 | rectangle(dos_m+1*ratio_2d, dos_m+1*ratio_2d, 28*ratio_2d, 8*ratio_2d); |
---|
531 | rectangle(dos_m+(int)(30.5f*ratio_2d), dos_m+2*ratio_2d, screen_size.x-(int)(58.5f*ratio_2d)-dos_m*2, 2*ratio_2d); |
---|
532 | rectangle(dos_m+(int)(30.5f*ratio_2d), dos_m+6*ratio_2d, screen_size.x-(int)(58.5f*ratio_2d)-dos_m*2, 2*ratio_2d); |
---|
533 | rectangle(screen_size.x-(int)(24.5f*ratio_2d)-dos_m, dos_m+1*ratio_2d, 7*ratio_2d, 6*ratio_2d); |
---|
534 | glColor3f(1.0f, 1.0f, 1.0f); |
---|
535 | rectangle(screen_size.x-(int)(23.5f*ratio_2d)-dos_m, dos_m+2*ratio_2d, 5*ratio_2d, 4*ratio_2d); |
---|
536 | glColor3f(0, 0, 0); |
---|
537 | rectangle(screen_size.x-(int)(22.5f*ratio_2d)-dos_m, dos_m+3*ratio_2d, 7*ratio_2d, 6*ratio_2d); |
---|
538 | rectangle(screen_size.x-(int)(12.5f*ratio_2d)-dos_m, dos_m+1*ratio_2d, 7*ratio_2d, 6*ratio_2d); |
---|
539 | glColor3f(dos_color.r, dos_color.g, dos_color.b); |
---|
540 | rectangle(screen_size.x-(int)(10.5f*ratio_2d)-dos_m, dos_m+2*ratio_2d, 7*ratio_2d, 7*ratio_2d); |
---|
541 | glColor3f(1.0f, 1.0f, 1.0f); |
---|
542 | rectangle(screen_size.x-(int)(9.5f*ratio_2d)-dos_m, dos_m+3*ratio_2d, 5*ratio_2d, 5*ratio_2d); |
---|
543 | rectangle(screen_size.x-8*ratio_2d-dos_m, screen_size.y-9*ratio_2d-dos_m, 7*ratio_2d, 8*ratio_2d); |
---|
544 | glColor3f(dos_color.r, dos_color.g, dos_color.b); |
---|
545 | rectangle(screen_size.x-7*ratio_2d-dos_m, screen_size.y-8*ratio_2d-dos_m, 6*ratio_2d, 7*ratio_2d); |
---|
546 | glColor3f(1.0f, 1.0f, 1.0f); |
---|
547 | rectangle(screen_size.x-4*ratio_2d-dos_m, screen_size.y-8*ratio_2d-dos_m, 4*ratio_2d, 2*ratio_2d); |
---|
548 | rectangle(screen_size.x-7*ratio_2d-dos_m, screen_size.y-5*ratio_2d-dos_m, 2*ratio_2d, 5*ratio_2d); |
---|
549 | rectangle(screen_size.x-6*ratio_2d-dos_m, screen_size.y-7*ratio_2d-dos_m, 1*ratio_2d, 1*ratio_2d); |
---|
550 | rectangle(screen_size.x-4*ratio_2d-dos_m, screen_size.y-5*ratio_2d-dos_m, 2*ratio_2d, 3*ratio_2d); |
---|
551 | glEnable(GL_BLEND); |
---|
552 | if(polygon) glEnable(GL_TEXTURE_2D); |
---|
553 | glBlendFunc(GL_ONE, GL_ONE); |
---|
554 | glVertexPointer(2, GL_INT, 0, shell_vtx); |
---|
555 | glTexCoordPointer(2, GL_FLOAT, 0, shell_tex); |
---|
556 | glDrawArrays(GL_QUADS, 0, 4); |
---|
557 | // draw dos text |
---|
558 | glVertexPointer(2, GL_INT, 0, dos_vtx); |
---|
559 | j=0; |
---|
560 | liner_line=-1; |
---|
561 | for(i=1;i<liner_length+1;i++) |
---|
562 | { |
---|
563 | j++; |
---|
564 | car=(unsigned char)txt[i-1]; |
---|
565 | if(i==liner_length) car=car_cursor; |
---|
566 | if(car>32) |
---|
567 | { |
---|
568 | glLoadIdentity(); |
---|
569 | glTranslated(x+j*(dos_w+2*ratio_2d), y, 0); |
---|
570 | float l_w=(car%16)*0.03125f; |
---|
571 | float l_h=(car-car%16)*0.001953125f; |
---|
572 | float dos_tex[]={l_w+0.03125f, 0.5f-l_h-0.03125f, l_w+0.03125f, 0.5f-l_h, l_w, 0.5f-l_h, l_w, 0.5f-l_h-0.03125f}; |
---|
573 | glTexCoordPointer(2, GL_FLOAT, 0, dos_tex); |
---|
574 | if(car==car_cursor) glColor3f(CR*(dos_color.r+64), CR*(dos_color.g+48), CR*(dos_color.b+48)); |
---|
575 | glDrawArrays(GL_QUADS, 0, 4); |
---|
576 | if(car==car_cursor) glColor3f(1.0f, 1.0f, 1.0f); |
---|
577 | } |
---|
578 | if(car==13) |
---|
579 | { |
---|
580 | j=0; |
---|
581 | liner_line++; |
---|
582 | x=dos_m; |
---|
583 | y=dos_m+(float)(15*ratio_2d+liner_line*(dos_h+4*ratio_2d)); |
---|
584 | if(y+dos_h>screen_size.y-dos_m) break; |
---|
585 | } |
---|
586 | } |
---|
587 | } |
---|
588 | // draw debug |
---|
589 | //#if DEBUG |
---|
590 | if(debug_flag) |
---|
591 | { |
---|
592 | char debug[512]; |
---|
593 | sprintf(debug, "width=%d\rheight=%d\rratio=%dx\rbeat=%-02.1f\rsync=%-02.1f\rkey code=%03d\r", screen_size.x, screen_size.y, ratio_2d, beat_value, sync_value, key_code); |
---|
594 | float l_v=0.0390625f; |
---|
595 | float l_j=0.001953125f; |
---|
596 | glVertexPointer(2, GL_INT, 0, debug_vtx); |
---|
597 | glLoadIdentity(); |
---|
598 | glBlendFunc(GL_ONE, GL_ONE); |
---|
599 | glColor3f(0.625f, 0.25f, 0.0f); |
---|
600 | glTranslated(debug_x, debug_y, 0); |
---|
601 | j=0; |
---|
602 | for(i=0;i<(int)strlen(debug);i++) |
---|
603 | { |
---|
604 | j++; |
---|
605 | car=(unsigned char)debug[i]; |
---|
606 | if(car==13) |
---|
607 | { |
---|
608 | glTranslated(-j*(debug_w-ratio_2d)*2, (debug_h-ratio_2d)*2, 0); |
---|
609 | j=0; |
---|
610 | } |
---|
611 | glTranslated((debug_w-ratio_2d)*2, 0, 0); |
---|
612 | if(car>32) |
---|
613 | { |
---|
614 | float l_w=(car%16)*0.03515625f; |
---|
615 | float l_h=(car-car%16)*0.00244140625f; |
---|
616 | float debug_tex[]={l_w+l_v-l_j, 1.0f-l_h-l_v, l_w+l_v-l_j, 1.0f-l_h, l_w-l_j, 1.0f-l_h, l_w-l_j, 1.0f-l_h-l_v}; |
---|
617 | glTexCoordPointer(2, GL_FLOAT, 0, debug_tex); |
---|
618 | glDrawArrays(GL_QUADS, 0, 4); |
---|
619 | } |
---|
620 | } |
---|
621 | } |
---|
622 | //#endif |
---|
623 | // draw corner |
---|
624 | glDisable(GL_TEXTURE_2D); |
---|
625 | glDisable(GL_BLEND); |
---|
626 | glVertexPointer(2, GL_INT, 0, corner_vtx); |
---|
627 | glLoadIdentity(); |
---|
628 | glColor3f(0, 0, 0); |
---|
629 | glDrawArrays(GL_TRIANGLES, 0, corner_n*3); |
---|
630 | glTranslated(screen_size.x, 0, 0); |
---|
631 | glRotated(90.0f, 0, 0, 1.0f); |
---|
632 | glDrawArrays(GL_TRIANGLES, 0, corner_n*3); |
---|
633 | glTranslated(screen_size.y, 0, 0); |
---|
634 | glRotated(90.0f, 0, 0, 1.0f); |
---|
635 | glDrawArrays(GL_TRIANGLES, 0, corner_n*3); |
---|
636 | glTranslated(screen_size.x, 0, 0); |
---|
637 | glRotated(90.0f, 0, 0, 1.0f); |
---|
638 | glDrawArrays(GL_TRIANGLES, 0, corner_n*3); |
---|
639 | glEnable(GL_BLEND); |
---|
640 | /* .-------------------. */ |
---|
641 | /* | DRAW SOME 3D HERE | */ |
---|
642 | /* °-------------------° */ |
---|
643 | //init_viewport(0); |
---|
644 | /*-PATACODE----------------------------------------------------------------*/ |
---|
645 | #if SHADER |
---|
646 | if (shader_flag) |
---|
647 | { |
---|
648 | init_shader(); |
---|
649 | fbo_back->Unbind(); |
---|
650 | if (shader_effect_flag && shader_blur_flag) |
---|
651 | { |
---|
652 | // shader blur horizontal |
---|
653 | fbo_ping->Bind(); |
---|
654 | shader_blur_h->Bind(); |
---|
655 | shader_blur_h->SetTexture(shader_blur_h_texture, fbo_back->GetTexture(), 0); |
---|
656 | shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f)); |
---|
657 | shader_blur_h->SetUniform(shader_blur_h_time, fx_angle); |
---|
658 | shader_blur_h->SetUniform(shader_blur_h_value, 0.5f/screen_size.x); |
---|
659 | fs_quad(); |
---|
660 | shader_blur_h->Unbind(); |
---|
661 | fbo_ping->Unbind(); |
---|
662 | // shader blur vertical |
---|
663 | fbo_front->Bind(); |
---|
664 | shader_blur_v->Bind(); |
---|
665 | shader_blur_v->SetTexture(shader_blur_v_texture, fbo_ping->GetTexture(), 0); |
---|
666 | shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f)); |
---|
667 | shader_blur_v->SetUniform(shader_blur_v_time, fx_angle); |
---|
668 | shader_blur_v->SetUniform(shader_blur_v_value, 0.5f/screen_size.y); |
---|
669 | fs_quad(); |
---|
670 | shader_blur_v->Unbind(); |
---|
671 | } |
---|
672 | else |
---|
673 | { |
---|
674 | // shader simple |
---|
675 | fbo_front->Bind(); |
---|
676 | draw_shader_simple(fbo_back, 0); |
---|
677 | } |
---|
678 | fbo_front->Unbind(); |
---|
679 | // shader glow |
---|
680 | if(shader_effect_flag&&shader_glow_flag) |
---|
681 | { |
---|
682 | // shader blur horizontal |
---|
683 | fbo_blur_h->Bind(); |
---|
684 | shader_blur_h->Bind(); |
---|
685 | shader_blur_h->SetTexture(shader_blur_h_texture, fbo_ping->GetTexture(), 0); |
---|
686 | shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f / glow_fbo_size)); |
---|
687 | shader_blur_h->SetUniform(shader_blur_h_time, fx_angle); |
---|
688 | shader_blur_h->SetUniform(shader_blur_h_value, 2.5f/screen_size.x); |
---|
689 | fs_quad(); |
---|
690 | shader_blur_h->Unbind(); |
---|
691 | fbo_blur_h->Unbind(); |
---|
692 | // shader blur vertical |
---|
693 | fbo_blur_v->Bind(); |
---|
694 | shader_blur_v->Bind(); |
---|
695 | shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0); |
---|
696 | shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f / glow_fbo_size)); |
---|
697 | shader_blur_v->SetUniform(shader_blur_v_time, fx_angle); |
---|
698 | shader_blur_v->SetUniform(shader_blur_h_value, 2.5f/screen_size.y); |
---|
699 | fs_quad(); |
---|
700 | shader_blur_v->Unbind(); |
---|
701 | fbo_blur_v->Unbind(); |
---|
702 | // shader blur horizontal |
---|
703 | fbo_blur_h->Bind(); |
---|
704 | shader_blur_h->Bind(); |
---|
705 | shader_blur_h->SetTexture(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0); |
---|
706 | shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f / glow_fbo_size)); |
---|
707 | shader_blur_h->SetUniform(shader_blur_h_time, fx_angle); |
---|
708 | shader_blur_h->SetUniform(shader_blur_h_value, 1.0f/screen_size.x); |
---|
709 | fs_quad(); |
---|
710 | shader_blur_h->Unbind(); |
---|
711 | fbo_blur_h->Unbind(); |
---|
712 | // shader blur vertical |
---|
713 | fbo_blur_v->Bind(); |
---|
714 | shader_blur_v->Bind(); |
---|
715 | shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0); |
---|
716 | shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f / glow_fbo_size)); |
---|
717 | shader_blur_v->SetUniform(shader_blur_v_time, fx_angle); |
---|
718 | shader_blur_v->SetUniform(shader_blur_h_value, 1.0f/screen_size.y); |
---|
719 | fs_quad(); |
---|
720 | shader_blur_v->Unbind(); |
---|
721 | fbo_blur_v->Unbind(); |
---|
722 | // shader glow |
---|
723 | fbo_pong->Bind(); |
---|
724 | shader_glow->Bind(); |
---|
725 | shader_glow->SetTexture(shader_glow_texture, fbo_blur_v->GetTexture(), 0); |
---|
726 | shader_glow->SetTexture(shader_glow_texture_prv, fbo_front->GetTexture(), 1); |
---|
727 | shader_glow->SetUniform(shader_glow_screen_size, vec2(1.0f)); |
---|
728 | shader_glow->SetUniform(shader_glow_time, fx_angle); |
---|
729 | shader_glow->SetUniform(shader_glow_step, glow_smoothstep); |
---|
730 | shader_glow->SetUniform(shader_glow_value1, glow_mix_ratio1); |
---|
731 | shader_glow->SetUniform(shader_glow_value2, glow_mix_ratio2); |
---|
732 | fs_quad(); |
---|
733 | shader_glow->Unbind(); |
---|
734 | } |
---|
735 | if(!shader_effect_flag) |
---|
736 | { |
---|
737 | // shader simple |
---|
738 | fbo_pong->Bind(); |
---|
739 | draw_shader_simple(fbo_front, 0); |
---|
740 | } |
---|
741 | fbo_pong->Unbind(); |
---|
742 | if(shader_postfx_flag) |
---|
743 | { |
---|
744 | // shader postfx |
---|
745 | shader_postfx->Bind(); |
---|
746 | shader_postfx->SetTexture(shader_postfx_texture, fbo_pong->GetTexture(), 0); |
---|
747 | shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size); |
---|
748 | shader_postfx->SetUniform(shader_postfx_time, fx_angle); |
---|
749 | shader_postfx->SetUniform(shader_postfx_flash, flash_value); |
---|
750 | shader_postfx->SetUniform(shader_postfx_value, 4.0f); |
---|
751 | shader_postfx->SetUniform(shader_postfx_deform, postfx_deform); |
---|
752 | shader_postfx->SetUniform(shader_postfx_scanline, postfx_scanline); |
---|
753 | shader_postfx->SetUniform(shader_postfx_sync, (float)fabs(beat_value*cosf((main_angle-beat_angle)*8.0f))); |
---|
754 | fs_quad(); |
---|
755 | shader_postfx->Unbind(); |
---|
756 | } |
---|
757 | else |
---|
758 | { |
---|
759 | // shader simple |
---|
760 | draw_shader_simple(fbo_pong, 0); |
---|
761 | } |
---|
762 | } |
---|
763 | #endif |
---|
764 | /*-/PATACODE---------------------------------------------------------------*/ |
---|
765 | } |
---|
766 | |
---|
767 | Render::~Render() |
---|
768 | { |
---|
769 | } |
---|
770 | |
---|