Browse Source

debug shortcuts added

master
parent
commit
7f932ecfb4
3 changed files with 117 additions and 103 deletions
  1. +104
    -103
      neercs/video/render.cpp
  2. +11
    -0
      neercs/video/render.h
  3. +2
    -0
      neercs/video/text.lolfx

+ 104
- 103
neercs/video/render.cpp View File

@@ -47,22 +47,17 @@ extern char const *lolfx_simple;
*/

int active = true; // window active flag
bool fullscreen = DEBUG?false:true; // fullscreen flag
bool m_paused = false; // pause flag
float nearplane = 0.1f; // nearplane
float farplane = 1000.0f; // farplane
bool polygon = true; // polygon mode
int polygon_fillmode = GL_FILL; // fill mode
bool key_state = 0; // key state
/* window variable */
ivec2 screen_size; // screen size
int window_color = 32; // color depth
vec3 screen_color = CR * vec3(48, 56, 64); // screen color
/* object variable */
float main_angle = 0.0f; // main angle
float part_angle = 0.0f; // part angle
float fx_angle; // current angle
/* text variable */
char const *name = "cacaShell";
/* fs_quad variable */
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};
float fs_quad_tex[] = {0, 1.0f, 0, 0, 1.0f, 0, 1.0f, 1.0f};
@@ -87,40 +82,28 @@ float beat_angle = 0; // angle
float beat_value = 0; // value
float beat_speed = 2.0f; // speed
/* corner variable */
const int corner_n = 10; // polygon number
const int corner_n = 10; // m_polygon number
int corner_w = 24; // radius
int corner_vtx[corner_n*6];// vertex array
/* dos variable */
bool dos_flag = true; // flag
int dos_m; // margin
vec3 dos_color = CR * vec3(48, 56, 64); // color value
int dos_vtx[8]; // vertex array
/* window variable */
int window_m; // margin
int window_vtx[8]; // vertex array
ivec2 ratio_2d(2,4); // 2d ratio
ivec2 map_size(256,256); // texture map size
ivec2 font_size(8,8); // font size
vec2 car_size(1.0f/map_size.x*font_size.x, 1.0f/map_size.y*font_size.y);
int shell_vtx[8]; // vertex array
float shell_tex[] = {1.0f, 0.96875f, 1.0f, 1.0f, 0.78125f, 1.0f, 0.78125f, 0.96875f};
/* keyboard variable */
int key_code = 0; // keyboard code
/* common variable */
float value, angle, radius, scale, speed;
/* shader variable */
bool m_shader = true; /* TO DELETE */
bool shader_blur_flag = true;
bool shader_glow_flag = true;
bool shader_effect_flag = true;
bool shader_postfx_flag = true;

int glow_fbo_size = 2; // glow fbo size
float glow_smoothstep = 0.0f; // glow smoothstep value (try 0.025f)
float glow_mix_ratio1 = 0.5f; // glow mixing ratio
float glow_mix_ratio2 = 0.5f; // source mixing ratio

float radial_value1 = 2.0f;
float radial_value2 = 0.8f;
float radial_color = 0; // color

bool postfx_scanline = true;
float postfx_deform = 0.5f; // deformation ratio

@@ -214,7 +197,7 @@ void corner()
}
}

int InitGL(void)
int Render::InitDraw(void)
{
glDepthMask(GL_TRUE); // do not write z-buffer
glEnable(GL_CULL_FACE); // disable cull face
@@ -277,36 +260,42 @@ int InitGL(void)
return true;
}

int CreateGLWindow()
int Render::CreateGLWindow()
{
screen_size = Video::GetSize();
corner_w = 16*ratio_2d.x;
corner();
dos_m=12*ratio_2d.x;
dos_vtx[0]=font_size.x*ratio_2d.x/2.0f;
dos_vtx[1]=font_size.y*ratio_2d.y/2.0f;
dos_vtx[2]=font_size.x*ratio_2d.x/2.0f;
dos_vtx[3]=-font_size.y*ratio_2d.y/2.0f;
dos_vtx[4]=-font_size.x*ratio_2d.x/2.0f;
dos_vtx[5]=-font_size.y*ratio_2d.y/2.0f;
dos_vtx[6]=-font_size.x*ratio_2d.x/2.0f;
dos_vtx[7]=font_size.y*ratio_2d.y/2.0f;
shell_vtx[0]=dos_m+58*ratio_2d.x;
shell_vtx[1]=dos_m+(font_size.y+1)*ratio_2d.y;
shell_vtx[2]=dos_m+58*ratio_2d.x;
shell_vtx[3]=dos_m+ratio_2d.y;
shell_vtx[4]=dos_m+2*ratio_2d.x;
shell_vtx[5]=dos_m+ratio_2d.y;
shell_vtx[6]=dos_m+2*ratio_2d.x;
shell_vtx[7]=dos_m+(font_size.y+1)*ratio_2d.y;
InitGL();
window_m=12*ratio_2d.x;
window_vtx[0]=font_size.x*ratio_2d.x/2.0f;
window_vtx[1]=font_size.y*ratio_2d.y/2.0f;
window_vtx[2]=font_size.x*ratio_2d.x/2.0f;
window_vtx[3]=-font_size.y*ratio_2d.y/2.0f;
window_vtx[4]=-font_size.x*ratio_2d.x/2.0f;
window_vtx[5]=-font_size.y*ratio_2d.y/2.0f;
window_vtx[6]=-font_size.x*ratio_2d.x/2.0f;
window_vtx[7]=font_size.y*ratio_2d.y/2.0f;
shell_vtx[0]=window_m+58*ratio_2d.x;
shell_vtx[1]=window_m+(font_size.y+1)*ratio_2d.y;
shell_vtx[2]=window_m+58*ratio_2d.x;
shell_vtx[3]=window_m+ratio_2d.y;
shell_vtx[4]=window_m+2*ratio_2d.x;
shell_vtx[5]=window_m+ratio_2d.y;
shell_vtx[6]=window_m+2*ratio_2d.x;
shell_vtx[7]=window_m+(font_size.y+1)*ratio_2d.y;
InitDraw();
return true;
}

Render::Render(caca_canvas_t *caca)
: m_caca(caca),
m_ready(false),
m_shader(true)
m_pause(false),
m_polygon(true),
m_shader(true),
m_shader_blur(true),
m_shader_glow(true),
m_shader_fx(true),
m_shader_postfx(true)
{
text_render = new TextRender(m_caca, font_size);
}
@@ -316,15 +305,33 @@ void Render::TickGame(float seconds)
Entity::TickGame(seconds);
}

void Render::Pause()
{
m_pause=!m_pause;
}

void Render::TickDraw(float seconds)
{
/* keyboard manager */
if (Input::GetButtonState(27/*SDLK_ESCAPE*/))
Ticker::Shutdown();
if (Input::GetButtonState(8 /*SDLK_BACKSPACE*/))
m_paused=!m_paused;
if (Input::GetButtonState(112 /*SDLK_F1*/))
//if (Input::GetButtonState(282/*SDLK_F1*/))
// Pause();
if (Input::GetButtonState(283/*SDLK_F2*/))
{
m_polygon=!m_polygon;
polygon_fillmode=(m_polygon)?GL_FILL:GL_LINE;
glPolygonMode(GL_FRONT,polygon_fillmode);
}
if (Input::GetButtonState(284/*SDLK_F3*/)&&key_state!=284)
{
m_shader=!m_shader;
key_state=284;
}
if (Input::GetButtonState(285/*SDLK_F4*/))
m_shader_postfx=!m_shader_postfx;
if (Input::GetButtonState(286/*SDLK_F5*/))
Pause();

Entity::TickDraw(seconds);

@@ -332,12 +339,11 @@ void Render::TickDraw(float seconds)
{
CreateGLWindow();
text_render->Init();

m_ready = true;
}

// timer
if(!m_paused)
if(!m_pause)
main_angle += seconds * 100.0f * PID;
if(sync_flag)
{
@@ -397,74 +403,70 @@ void Render::Draw2D()
/* Clear the back buffer */
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_COLOR,GL_DST_ALPHA);
glClearColor(screen_color.r, screen_color.g, screen_color.b, 0.5f);
glClearColor(screen_color.r, screen_color.g, screen_color.b, 1.0f);
glClearDepth(1.0f); // set depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

ivec2 border_top = ivec2(dos_m, dos_m + font_size.y * ratio_2d.y)
ivec2 border_top = ivec2(window_m, window_m + font_size.y * ratio_2d.y)
+ ratio_2d * 2;
ivec2 border_bottom = ivec2(dos_m * 2, dos_m * 2 + font_size.y * ratio_2d.y)
ivec2 border_bottom = ivec2(window_m * 2, window_m * 2 + font_size.y * ratio_2d.y)
+ ratio_2d * 2;
text_render->Blit(border_top, screen_size - border_bottom);

//if(polygon) glEnable(GL_LINE_SMOOTH); else glDisable(GL_LINE_SMOOTH);
glLineWidth((polygon)?2.0f:1.0f);
//if(m_polygon) glEnable(GL_LINE_SMOOTH); else glDisable(GL_LINE_SMOOTH);
glLineWidth((m_polygon)?2.0f:1.0f);
fx_angle=main_angle-part_angle;
if(polygon) glEnable(GL_TEXTURE_2D);
if(m_polygon) glEnable(GL_TEXTURE_2D);

glMatrixMode(GL_PROJECTION);
mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f);
glLoadMatrixf(&m[0][0]);
glMatrixMode(GL_MODELVIEW);
// draw dos
if(dos_flag)
{
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glColor3f(1.0f,1.0f,1.0f);
rectangle(dos_m,dos_m,screen_size.x-53*ratio_2d.x-dos_m*2,(font_size.y+2)*ratio_2d.y);
rectangle(screen_size.x-51*ratio_2d.x-dos_m,dos_m,22*ratio_2d.x,(font_size.y+2)*ratio_2d.y);
rectangle(screen_size.x-27*ratio_2d.x-dos_m,dos_m,22*ratio_2d.x,(font_size.y+2)*ratio_2d.y);
rectangle(screen_size.x-3*ratio_2d.x-dos_m,dos_m,3*ratio_2d.x,(font_size.y+2)*ratio_2d.y);
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);
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);
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);
glColor3f(dos_color.x,dos_color.y,dos_color.z);
rectangle(dos_m+2*ratio_2d.x,dos_m+ratio_2d.y,56*ratio_2d.x,font_size.y*ratio_2d.y);
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);
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);
rectangle(screen_size.x-49*ratio_2d.x-dos_m,dos_m+ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y);
glColor3f(1.0f,1.0f,1.0f);
rectangle(screen_size.x-47*ratio_2d.x-dos_m,dos_m+2*ratio_2d.y,10*ratio_2d.x,4*ratio_2d.y);
glColor3f(0,0,0);
rectangle(screen_size.x-45*ratio_2d.x-dos_m,dos_m+3*ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y);
rectangle(screen_size.x-25*ratio_2d.x-dos_m,dos_m+1*ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y);
glColor3f(dos_color.x,dos_color.y,dos_color.z);
rectangle(screen_size.x-21*ratio_2d.x-dos_m,dos_m+2*ratio_2d.y,14*ratio_2d.x,7*ratio_2d.y);
glColor3f(1.0f,1.0f,1.0f);
rectangle(screen_size.x-19*ratio_2d.x-dos_m,dos_m+3*ratio_2d.y,10*ratio_2d.x,5*ratio_2d.y);
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);
glColor3f(dos_color.x,dos_color.y,dos_color.z);
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);
glColor3f(1.0f,1.0f,1.0f);
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);
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);
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);
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);
glEnable(GL_BLEND);
if(polygon) glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_ONE, GL_ONE);
glVertexPointer(2, GL_INT, 0, shell_vtx);
glTexCoordPointer(2, GL_FLOAT, 0, shell_tex);
glDrawArrays(GL_QUADS, 0, 4);
}
// draw window
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glColor3f(1.0f,1.0f,1.0f);
rectangle(window_m,window_m,screen_size.x-53*ratio_2d.x-window_m*2,(font_size.y+2)*ratio_2d.y);
rectangle(screen_size.x-51*ratio_2d.x-window_m,window_m,22*ratio_2d.x,(font_size.y+2)*ratio_2d.y);
rectangle(screen_size.x-27*ratio_2d.x-window_m,window_m,22*ratio_2d.x,(font_size.y+2)*ratio_2d.y);
rectangle(screen_size.x-3*ratio_2d.x-window_m,window_m,3*ratio_2d.x,(font_size.y+2)*ratio_2d.y);
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);
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);
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);
glColor3f(screen_color.x,screen_color.y,screen_color.z);
rectangle(window_m+2*ratio_2d.x,window_m+ratio_2d.y,56*ratio_2d.x,font_size.y*ratio_2d.y);
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);
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);
rectangle(screen_size.x-49*ratio_2d.x-window_m,window_m+ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y);
glColor3f(1.0f,1.0f,1.0f);
rectangle(screen_size.x-47*ratio_2d.x-window_m,window_m+2*ratio_2d.y,10*ratio_2d.x,4*ratio_2d.y);
glColor3f(0,0,0);
rectangle(screen_size.x-45*ratio_2d.x-window_m,window_m+3*ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y);
rectangle(screen_size.x-25*ratio_2d.x-window_m,window_m+1*ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y);
glColor3f(screen_color.x,screen_color.y,screen_color.z);
rectangle(screen_size.x-21*ratio_2d.x-window_m,window_m+2*ratio_2d.y,14*ratio_2d.x,7*ratio_2d.y);
glColor3f(1.0f,1.0f,1.0f);
rectangle(screen_size.x-19*ratio_2d.x-window_m,window_m+3*ratio_2d.y,10*ratio_2d.x,5*ratio_2d.y);
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);
glColor3f(screen_color.x,screen_color.y,screen_color.z);
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);
glColor3f(1.0f,1.0f,1.0f);
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);
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);
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);
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);
glEnable(GL_BLEND);
if(m_polygon) glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_ONE, GL_ONE);
glVertexPointer(2, GL_INT, 0, shell_vtx);
glTexCoordPointer(2, GL_FLOAT, 0, shell_tex);
glDrawArrays(GL_QUADS, 0, 4);
// draw corner
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glColor3f(0, 1.0f, 0);
glVertexPointer(2, GL_INT, 0, corner_vtx);
glLoadIdentity();
glColor3f(0, 0, 0);
glColor3f(1.0f, 1.0f, 1.0f);
glDrawArrays(GL_TRIANGLES, 0, corner_n*3);
glTranslated(screen_size.x, 0, 0);
glRotated(90.0f, 0, 0, 1.0f);
@@ -493,7 +495,7 @@ void Render::Draw3D()
glTexCoordPointer(2, GL_FLOAT, 0, fs_quad_tex);

fbo_back->Unbind();
if (shader_effect_flag && shader_blur_flag)
if (m_shader_fx && m_shader_blur)
{
// shader blur horizontal
fbo_ping->Bind();
@@ -523,7 +525,7 @@ void Render::Draw3D()
}
fbo_front->Unbind();
// shader glow
if(shader_effect_flag && shader_glow_flag)
if(m_shader_fx && m_shader_glow)
{
// shader blur horizontal
fbo_blur_h->Bind();
@@ -578,14 +580,14 @@ void Render::Draw3D()
fs_quad();
shader_glow->Unbind();
}
if(!shader_effect_flag)
if(!m_shader_fx)
{
// shader simple
fbo_pong->Bind();
draw_shader_simple(fbo_front, 0);
}
fbo_pong->Unbind();
if(shader_postfx_flag)
if(m_shader_postfx)
{
// shader postfx
shader_postfx->Bind();
@@ -613,4 +615,3 @@ void Render::Draw3D()
Render::~Render()
{
}


+ 11
- 0
neercs/video/render.h View File

@@ -20,9 +20,20 @@ protected:
void Draw3D();

private:
int CreateGLWindow();
int InitDraw();
void Pause();
void Shader();

caca_canvas_t *m_caca;
bool m_ready;
bool m_pause;
bool m_polygon;
bool m_shader;
bool m_shader_blur;
bool m_shader_glow;
bool m_shader_fx;
bool m_shader_postfx;
};

#endif // __VIDEO_RENDER_H__


+ 2
- 0
neercs/video/text.lolfx View File

@@ -29,6 +29,8 @@ void main()

pass_Background = vec4(B, C, D, 1.0 - A);
pass_Foreground = vec4(F, G, H, 1.0 - E);
if (B + C + D < 0.01) A = 1.0;
if (F + G + H < 0.01) E = 1.0;

// This only works with glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
//gl_PointSize = 40;


Loading…
Cancel
Save