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