Changeset 1588 for trunk/tools/neercs/video/render.cpp
- Timestamp:
- Jul 6, 2012, 4:24:38 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/neercs/video/render.cpp
r1585 r1588 48 48 49 49 int active = true; // window active flag 50 bool fullscreen = DEBUG?false:true; // fullscreen flag51 bool m_paused = false; // pause flag52 50 float nearplane = 0.1f; // nearplane 53 51 float farplane = 1000.0f; // farplane 54 bool polygon = true; // polygon mode55 52 int polygon_fillmode = GL_FILL; // fill mode 53 bool key_state = 0; // key state 56 54 /* window variable */ 57 55 ivec2 screen_size; // screen size 58 int window_color = 32; // color depth59 56 vec3 screen_color = CR * vec3(48, 56, 64); // screen color 60 57 /* object variable */ … … 62 59 float part_angle = 0.0f; // part angle 63 60 float fx_angle; // current angle 64 /* text variable */65 char const *name = "cacaShell";66 61 /* fs_quad variable */ 67 62 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}; … … 88 83 float beat_speed = 2.0f; // speed 89 84 /* corner variable */ 90 const int corner_n = 10; // polygon number85 const int corner_n = 10; // m_polygon number 91 86 int corner_w = 24; // radius 92 87 int corner_vtx[corner_n*6];// vertex array 93 /* dos variable */ 94 bool dos_flag = true; // flag 95 int dos_m; // margin 96 vec3 dos_color = CR * vec3(48, 56, 64); // color value 97 int dos_vtx[8]; // vertex array 88 /* window variable */ 89 int window_m; // margin 90 int window_vtx[8]; // vertex array 98 91 ivec2 ratio_2d(2,4); // 2d ratio 99 92 ivec2 map_size(256,256); // texture map size … … 102 95 int shell_vtx[8]; // vertex array 103 96 float shell_tex[] = {1.0f, 0.96875f, 1.0f, 1.0f, 0.78125f, 1.0f, 0.78125f, 0.96875f}; 104 /* keyboard variable */105 int key_code = 0; // keyboard code106 97 /* common variable */ 107 98 float value, angle, radius, scale, speed; 108 99 /* shader variable */ 109 bool m_shader = true; /* TO DELETE */110 bool shader_blur_flag = true;111 bool shader_glow_flag = true;112 bool shader_effect_flag = true;113 bool shader_postfx_flag = true;114 115 100 int glow_fbo_size = 2; // glow fbo size 116 101 float glow_smoothstep = 0.0f; // glow smoothstep value (try 0.025f) 117 102 float glow_mix_ratio1 = 0.5f; // glow mixing ratio 118 103 float glow_mix_ratio2 = 0.5f; // source mixing ratio 119 120 104 float radial_value1 = 2.0f; 121 105 float radial_value2 = 0.8f; 122 106 float radial_color = 0; // color 123 124 107 bool postfx_scanline = true; 125 108 float postfx_deform = 0.5f; // deformation ratio … … 215 198 } 216 199 217 int InitGL(void)200 int Render::InitDraw(void) 218 201 { 219 202 glDepthMask(GL_TRUE); // do not write z-buffer … … 278 261 } 279 262 280 int CreateGLWindow()263 int Render::CreateGLWindow() 281 264 { 282 265 screen_size = Video::GetSize(); 283 266 corner_w = 16*ratio_2d.x; 284 267 corner(); 285 dos_m=12*ratio_2d.x;286 dos_vtx[0]=font_size.x*ratio_2d.x/2.0f;287 dos_vtx[1]=font_size.y*ratio_2d.y/2.0f;288 dos_vtx[2]=font_size.x*ratio_2d.x/2.0f;289 dos_vtx[3]=-font_size.y*ratio_2d.y/2.0f;290 dos_vtx[4]=-font_size.x*ratio_2d.x/2.0f;291 dos_vtx[5]=-font_size.y*ratio_2d.y/2.0f;292 dos_vtx[6]=-font_size.x*ratio_2d.x/2.0f;293 dos_vtx[7]=font_size.y*ratio_2d.y/2.0f;294 shell_vtx[0]= dos_m+58*ratio_2d.x;295 shell_vtx[1]= dos_m+(font_size.y+1)*ratio_2d.y;296 shell_vtx[2]= dos_m+58*ratio_2d.x;297 shell_vtx[3]= dos_m+ratio_2d.y;298 shell_vtx[4]= dos_m+2*ratio_2d.x;299 shell_vtx[5]= dos_m+ratio_2d.y;300 shell_vtx[6]= dos_m+2*ratio_2d.x;301 shell_vtx[7]= dos_m+(font_size.y+1)*ratio_2d.y;302 Init GL();268 window_m=12*ratio_2d.x; 269 window_vtx[0]=font_size.x*ratio_2d.x/2.0f; 270 window_vtx[1]=font_size.y*ratio_2d.y/2.0f; 271 window_vtx[2]=font_size.x*ratio_2d.x/2.0f; 272 window_vtx[3]=-font_size.y*ratio_2d.y/2.0f; 273 window_vtx[4]=-font_size.x*ratio_2d.x/2.0f; 274 window_vtx[5]=-font_size.y*ratio_2d.y/2.0f; 275 window_vtx[6]=-font_size.x*ratio_2d.x/2.0f; 276 window_vtx[7]=font_size.y*ratio_2d.y/2.0f; 277 shell_vtx[0]=window_m+58*ratio_2d.x; 278 shell_vtx[1]=window_m+(font_size.y+1)*ratio_2d.y; 279 shell_vtx[2]=window_m+58*ratio_2d.x; 280 shell_vtx[3]=window_m+ratio_2d.y; 281 shell_vtx[4]=window_m+2*ratio_2d.x; 282 shell_vtx[5]=window_m+ratio_2d.y; 283 shell_vtx[6]=window_m+2*ratio_2d.x; 284 shell_vtx[7]=window_m+(font_size.y+1)*ratio_2d.y; 285 InitDraw(); 303 286 return true; 304 287 } … … 307 290 : m_caca(caca), 308 291 m_ready(false), 309 m_shader(true) 292 m_pause(false), 293 m_polygon(true), 294 m_shader(true), 295 m_shader_blur(true), 296 m_shader_glow(true), 297 m_shader_fx(true), 298 m_shader_postfx(true) 310 299 { 311 300 text_render = new TextRender(m_caca, font_size); … … 315 304 { 316 305 Entity::TickGame(seconds); 306 } 307 308 void Render::Pause() 309 { 310 m_pause=!m_pause; 317 311 } 318 312 … … 322 316 if (Input::GetButtonState(27/*SDLK_ESCAPE*/)) 323 317 Ticker::Shutdown(); 324 if (Input::GetButtonState(8 /*SDLK_BACKSPACE*/)) 325 m_paused=!m_paused; 326 if (Input::GetButtonState(112 /*SDLK_F1*/)) 318 //if (Input::GetButtonState(282/*SDLK_F1*/)) 319 // Pause(); 320 if (Input::GetButtonState(283/*SDLK_F2*/)) 321 { 322 m_polygon=!m_polygon; 323 polygon_fillmode=(m_polygon)?GL_FILL:GL_LINE; 324 glPolygonMode(GL_FRONT,polygon_fillmode); 325 } 326 if (Input::GetButtonState(284/*SDLK_F3*/)&&key_state!=284) 327 { 327 328 m_shader=!m_shader; 329 key_state=284; 330 } 331 if (Input::GetButtonState(285/*SDLK_F4*/)) 332 m_shader_postfx=!m_shader_postfx; 333 if (Input::GetButtonState(286/*SDLK_F5*/)) 334 Pause(); 328 335 329 336 Entity::TickDraw(seconds); … … 333 340 CreateGLWindow(); 334 341 text_render->Init(); 335 336 342 m_ready = true; 337 343 } 338 344 339 345 // timer 340 if(!m_pause d)346 if(!m_pause) 341 347 main_angle += seconds * 100.0f * PID; 342 348 if(sync_flag) … … 398 404 glEnable(GL_BLEND); 399 405 glBlendFunc(GL_SRC_COLOR,GL_DST_ALPHA); 400 glClearColor(screen_color.r, screen_color.g, screen_color.b, 0.5f);406 glClearColor(screen_color.r, screen_color.g, screen_color.b, 1.0f); 401 407 glClearDepth(1.0f); // set depth buffer 402 408 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 403 409 404 ivec2 border_top = ivec2( dos_m, dos_m + font_size.y * ratio_2d.y)410 ivec2 border_top = ivec2(window_m, window_m + font_size.y * ratio_2d.y) 405 411 + ratio_2d * 2; 406 ivec2 border_bottom = ivec2( dos_m * 2, dos_m * 2 + font_size.y * ratio_2d.y)412 ivec2 border_bottom = ivec2(window_m * 2, window_m * 2 + font_size.y * ratio_2d.y) 407 413 + ratio_2d * 2; 408 414 text_render->Blit(border_top, screen_size - border_bottom); 409 415 410 //if( polygon) glEnable(GL_LINE_SMOOTH); else glDisable(GL_LINE_SMOOTH);411 glLineWidth(( polygon)?2.0f:1.0f);416 //if(m_polygon) glEnable(GL_LINE_SMOOTH); else glDisable(GL_LINE_SMOOTH); 417 glLineWidth((m_polygon)?2.0f:1.0f); 412 418 fx_angle=main_angle-part_angle; 413 if( polygon) glEnable(GL_TEXTURE_2D);419 if(m_polygon) glEnable(GL_TEXTURE_2D); 414 420 415 421 glMatrixMode(GL_PROJECTION); … … 417 423 glLoadMatrixf(&m[0][0]); 418 424 glMatrixMode(GL_MODELVIEW); 419 // draw dos 420 if(dos_flag) 421 { 422 glDisable(GL_TEXTURE_2D); 423 glDisable(GL_BLEND); 424 glColor3f(1.0f,1.0f,1.0f); 425 rectangle(dos_m,dos_m,screen_size.x-53*ratio_2d.x-dos_m*2,(font_size.y+2)*ratio_2d.y); 426 rectangle(screen_size.x-51*ratio_2d.x-dos_m,dos_m,22*ratio_2d.x,(font_size.y+2)*ratio_2d.y); 427 rectangle(screen_size.x-27*ratio_2d.x-dos_m,dos_m,22*ratio_2d.x,(font_size.y+2)*ratio_2d.y); 428 rectangle(screen_size.x-3*ratio_2d.x-dos_m,dos_m,3*ratio_2d.x,(font_size.y+2)*ratio_2d.y); 429 rectangle(dos_m,dos_m+(font_size.y+2)*ratio_2d.y,2*ratio_2d.x,screen_size.y-(font_size.y+2)*ratio_2d.y-dos_m*2); 430 rectangle(screen_size.x-2*ratio_2d.x-dos_m,dos_m+(font_size.y+2)*ratio_2d.y,2*ratio_2d.x,screen_size.y-(font_size.y+2)*ratio_2d.y-dos_m*2); 431 rectangle(dos_m+2*ratio_2d.x,screen_size.y-ratio_2d.y-dos_m,screen_size.x-4*ratio_2d.x-dos_m*2,ratio_2d.y); 432 glColor3f(dos_color.x,dos_color.y,dos_color.z); 433 rectangle(dos_m+2*ratio_2d.x,dos_m+ratio_2d.y,56*ratio_2d.x,font_size.y*ratio_2d.y); 434 rectangle(dos_m+60*ratio_2d.x,dos_m+2*ratio_2d.y,screen_size.x-115*ratio_2d.x-dos_m*2,2*ratio_2d.y); 435 rectangle(dos_m+60*ratio_2d.x,dos_m+6*ratio_2d.y,screen_size.x-115*ratio_2d.x-dos_m*2,2*ratio_2d.y); 436 rectangle(screen_size.x-49*ratio_2d.x-dos_m,dos_m+ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y); 437 glColor3f(1.0f,1.0f,1.0f); 438 rectangle(screen_size.x-47*ratio_2d.x-dos_m,dos_m+2*ratio_2d.y,10*ratio_2d.x,4*ratio_2d.y); 439 glColor3f(0,0,0); 440 rectangle(screen_size.x-45*ratio_2d.x-dos_m,dos_m+3*ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y); 441 rectangle(screen_size.x-25*ratio_2d.x-dos_m,dos_m+1*ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y); 442 glColor3f(dos_color.x,dos_color.y,dos_color.z); 443 rectangle(screen_size.x-21*ratio_2d.x-dos_m,dos_m+2*ratio_2d.y,14*ratio_2d.x,7*ratio_2d.y); 444 glColor3f(1.0f,1.0f,1.0f); 445 rectangle(screen_size.x-19*ratio_2d.x-dos_m,dos_m+3*ratio_2d.y,10*ratio_2d.x,5*ratio_2d.y); 446 rectangle(screen_size.x-16*ratio_2d.x-dos_m,screen_size.y-9*ratio_2d.y-dos_m,14*ratio_2d.x,8*ratio_2d.y); 447 glColor3f(dos_color.x,dos_color.y,dos_color.z); 448 rectangle(screen_size.x-14*ratio_2d.x-dos_m,screen_size.y-8*ratio_2d.y-dos_m,12*ratio_2d.x,7*ratio_2d.y); 449 glColor3f(1.0f,1.0f,1.0f); 450 rectangle(screen_size.x-8*ratio_2d.x-dos_m,screen_size.y-8*ratio_2d.y-dos_m,8*ratio_2d.x,2*ratio_2d.y); 451 rectangle(screen_size.x-14*ratio_2d.x-dos_m,screen_size.y-5*ratio_2d.y-dos_m,4*ratio_2d.x,5*ratio_2d.y); 452 rectangle(screen_size.x-12*ratio_2d.x-dos_m,screen_size.y-7*ratio_2d.y-dos_m,2*ratio_2d.x,1*ratio_2d.y); 453 rectangle(screen_size.x-8*ratio_2d.x-dos_m,screen_size.y-5*ratio_2d.y-dos_m,4*ratio_2d.x,3*ratio_2d.y); 454 glEnable(GL_BLEND); 455 if(polygon) glEnable(GL_TEXTURE_2D); 456 glBlendFunc(GL_ONE, GL_ONE); 457 glVertexPointer(2, GL_INT, 0, shell_vtx); 458 glTexCoordPointer(2, GL_FLOAT, 0, shell_tex); 459 glDrawArrays(GL_QUADS, 0, 4); 460 } 425 // draw window 426 glDisable(GL_TEXTURE_2D); 427 glDisable(GL_BLEND); 428 glColor3f(1.0f,1.0f,1.0f); 429 rectangle(window_m,window_m,screen_size.x-53*ratio_2d.x-window_m*2,(font_size.y+2)*ratio_2d.y); 430 rectangle(screen_size.x-51*ratio_2d.x-window_m,window_m,22*ratio_2d.x,(font_size.y+2)*ratio_2d.y); 431 rectangle(screen_size.x-27*ratio_2d.x-window_m,window_m,22*ratio_2d.x,(font_size.y+2)*ratio_2d.y); 432 rectangle(screen_size.x-3*ratio_2d.x-window_m,window_m,3*ratio_2d.x,(font_size.y+2)*ratio_2d.y); 433 rectangle(window_m,window_m+(font_size.y+2)*ratio_2d.y,2*ratio_2d.x,screen_size.y-(font_size.y+2)*ratio_2d.y-window_m*2); 434 rectangle(screen_size.x-2*ratio_2d.x-window_m,window_m+(font_size.y+2)*ratio_2d.y,2*ratio_2d.x,screen_size.y-(font_size.y+2)*ratio_2d.y-window_m*2); 435 rectangle(window_m+2*ratio_2d.x,screen_size.y-ratio_2d.y-window_m,screen_size.x-4*ratio_2d.x-window_m*2,ratio_2d.y); 436 glColor3f(screen_color.x,screen_color.y,screen_color.z); 437 rectangle(window_m+2*ratio_2d.x,window_m+ratio_2d.y,56*ratio_2d.x,font_size.y*ratio_2d.y); 438 rectangle(window_m+60*ratio_2d.x,window_m+2*ratio_2d.y,screen_size.x-115*ratio_2d.x-window_m*2,2*ratio_2d.y); 439 rectangle(window_m+60*ratio_2d.x,window_m+6*ratio_2d.y,screen_size.x-115*ratio_2d.x-window_m*2,2*ratio_2d.y); 440 rectangle(screen_size.x-49*ratio_2d.x-window_m,window_m+ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y); 441 glColor3f(1.0f,1.0f,1.0f); 442 rectangle(screen_size.x-47*ratio_2d.x-window_m,window_m+2*ratio_2d.y,10*ratio_2d.x,4*ratio_2d.y); 443 glColor3f(0,0,0); 444 rectangle(screen_size.x-45*ratio_2d.x-window_m,window_m+3*ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y); 445 rectangle(screen_size.x-25*ratio_2d.x-window_m,window_m+1*ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y); 446 glColor3f(screen_color.x,screen_color.y,screen_color.z); 447 rectangle(screen_size.x-21*ratio_2d.x-window_m,window_m+2*ratio_2d.y,14*ratio_2d.x,7*ratio_2d.y); 448 glColor3f(1.0f,1.0f,1.0f); 449 rectangle(screen_size.x-19*ratio_2d.x-window_m,window_m+3*ratio_2d.y,10*ratio_2d.x,5*ratio_2d.y); 450 rectangle(screen_size.x-16*ratio_2d.x-window_m,screen_size.y-9*ratio_2d.y-window_m,14*ratio_2d.x,8*ratio_2d.y); 451 glColor3f(screen_color.x,screen_color.y,screen_color.z); 452 rectangle(screen_size.x-14*ratio_2d.x-window_m,screen_size.y-8*ratio_2d.y-window_m,12*ratio_2d.x,7*ratio_2d.y); 453 glColor3f(1.0f,1.0f,1.0f); 454 rectangle(screen_size.x-8*ratio_2d.x-window_m,screen_size.y-8*ratio_2d.y-window_m,8*ratio_2d.x,2*ratio_2d.y); 455 rectangle(screen_size.x-14*ratio_2d.x-window_m,screen_size.y-5*ratio_2d.y-window_m,4*ratio_2d.x,5*ratio_2d.y); 456 rectangle(screen_size.x-12*ratio_2d.x-window_m,screen_size.y-7*ratio_2d.y-window_m,2*ratio_2d.x,1*ratio_2d.y); 457 rectangle(screen_size.x-8*ratio_2d.x-window_m,screen_size.y-5*ratio_2d.y-window_m,4*ratio_2d.x,3*ratio_2d.y); 458 glEnable(GL_BLEND); 459 if(m_polygon) glEnable(GL_TEXTURE_2D); 460 glBlendFunc(GL_ONE, GL_ONE); 461 glVertexPointer(2, GL_INT, 0, shell_vtx); 462 glTexCoordPointer(2, GL_FLOAT, 0, shell_tex); 463 glDrawArrays(GL_QUADS, 0, 4); 461 464 // draw corner 462 465 glDisable(GL_TEXTURE_2D); 463 466 glDisable(GL_BLEND); 464 glColor3f(0, 1.0f, 0);465 467 glVertexPointer(2, GL_INT, 0, corner_vtx); 466 468 glLoadIdentity(); 467 glColor3f( 0, 0, 0);469 glColor3f(1.0f, 1.0f, 1.0f); 468 470 glDrawArrays(GL_TRIANGLES, 0, corner_n*3); 469 471 glTranslated(screen_size.x, 0, 0); … … 494 496 495 497 fbo_back->Unbind(); 496 if ( shader_effect_flag && shader_blur_flag)498 if (m_shader_fx && m_shader_blur) 497 499 { 498 500 // shader blur horizontal … … 524 526 fbo_front->Unbind(); 525 527 // shader glow 526 if( shader_effect_flag && shader_glow_flag)528 if(m_shader_fx && m_shader_glow) 527 529 { 528 530 // shader blur horizontal … … 579 581 shader_glow->Unbind(); 580 582 } 581 if(! shader_effect_flag)583 if(!m_shader_fx) 582 584 { 583 585 // shader simple … … 586 588 } 587 589 fbo_pong->Unbind(); 588 if( shader_postfx_flag)590 if(m_shader_postfx) 589 591 { 590 592 // shader postfx … … 614 616 { 615 617 } 616
Note: See TracChangeset
for help on using the changeset viewer.