Changeset 1503


Ignore:
Timestamp:
Jun 20, 2012, 7:13:35 PM (8 years ago)
Author:
sam
Message:

neercs: the text rendering FBO is now exactly the required size.

Location:
trunk/neercs/video
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/neercs/video/render.cpp

    r1499 r1503  
    324324    {
    325325        CreateGLWindow("LOL");
    326         text_render->Init(screen_size);
     326        text_render->Init();
    327327
    328328        m_ready = true;
     
    380380{
    381381    /* Draw text in an offline buffer */
    382     text_render->Render(screen_size);
     382    text_render->Render();
    383383
    384384    if(shader_flag)
    385385        fbo_back->Bind();
     386
     387    glViewport(0, 0, screen_size.x, screen_size.y);
    386388
    387389    /* Clear the back buffer */
     
    394396    ivec2 border_bottom = ivec2(dos_m * 2, dos_m * 2 + font_size.y * ratio_2d.y)
    395397                        + ratio_2d * 2;
    396     text_render->Blit(screen_size, border_top, screen_size - border_bottom);
     398    text_render->Blit(border_top, screen_size - border_bottom);
    397399
    398400    glEnable(GL_BLEND);
     
    402404    if(polygon) glEnable(GL_TEXTURE_2D);
    403405
    404     glViewport(0, 0, screen_size.x, screen_size.y);
    405406    glMatrixMode(GL_PROJECTION);
    406407    mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f);
  • trunk/neercs/video/text-render.cpp

    r1499 r1503  
    3434    m_canvas_size(caca_get_canvas_width(m_caca),
    3535                  caca_get_canvas_height(m_caca)),
     36    m_fbo_size(m_font_size * m_canvas_size),
    3637    m_cells(m_canvas_size.x * m_canvas_size.y)
    3738{
     
    4142}
    4243
    43 void TextRender::Init(ivec2 screen_size)
     44void TextRender::Init()
    4445{
    4546    m_font = new TileSet("neercs/video/resource/map.png",
     
    6869    m_vbo3 = new VertexBuffer(m_cells * sizeof(int32_t));
    6970
    70     m_fbo = new FrameBuffer(screen_size);
     71    m_fbo = new FrameBuffer(m_fbo_size);
    7172}
    7273
    73 void TextRender::Render(ivec2 fbo_size)
     74void TextRender::Render()
    7475{
    7576    /* Transform matrix for the scene:
    7677     *  - translate to the centre of the glyph
    7778     *  - scale by 2.f * font_size / fbo_size
    78      *  - translate to the upper left corner */
    79     mat4 xform = mat4::translate(-1.f, 1.f, 0.f)
    80                * mat4::scale(vec3(2.f * m_font_size / (fbo_size), 1.f)
     79     *  - translate to the lower left corner */
     80    mat4 xform = mat4::translate(-1.f, -1.f + 2.0f * m_font_size.y
     81                                        * m_canvas_size.y / m_fbo_size.y, 0.f)
     82               * mat4::scale(vec3(2.f * m_font_size / m_fbo_size, 1.f)
    8183                              * vec3(1.f, -1.f, 1.f))
    8284               * mat4::translate(0.5f, 0.5f, 0.f);
     
    104106
    105107    m_fbo->Bind();
     108    glViewport(0, 0, m_fbo_size.x, m_fbo_size.y);
    106109    glDisable(GL_DEPTH_TEST);
    107110    glEnable(GL_POINT_SPRITE);
     
    125128}
    126129
    127 void TextRender::Blit(ivec2 fbo_size, ivec2 pos, ivec2 size)
     130void TextRender::Blit(ivec2 pos, ivec2 size)
    128131{
    129132    glDisable(GL_BLEND);
     
    132135    glColor3f(1.0f, 1.0f, 1.0f);
    133136
    134     vec2 tc = (vec2)m_canvas_size * m_font_size / fbo_size;
     137    vec2 tc = (vec2)m_canvas_size * m_font_size / m_fbo_size;
    135138
    136139    glLoadIdentity();
    137140    glBegin(GL_QUADS);
    138         glTexCoord2f(tc.x, 1.0f);
     141        glTexCoord2f(tc.x, tc.y);
    139142        glVertex2i(pos.x + size.x, pos.y);
    140         glTexCoord2f(0.0f, 1.0f);
     143        glTexCoord2f(0.0f, tc.y);
    141144        glVertex2i(pos.x, pos.y);
    142         glTexCoord2f(0.0f, 1.0f - tc.y);
     145        glTexCoord2f(0.0f, 0.0f);
    143146        glVertex2i(pos.x, pos.y + size.y);
    144         glTexCoord2f(tc.x, 1.0f - tc.y);
     147        glTexCoord2f(tc.x, 0.0f);
    145148        glVertex2i(pos.x + size.x, pos.y + size.y);
    146149    glEnd();
  • trunk/neercs/video/text-render.h

    r1499 r1503  
    99{
    1010    TextRender(caca_canvas_t *caca, ivec2 font_size);
    11     void Init(ivec2 screen_size);
    12     void Render(ivec2 fbo_size);
    13     void Blit(ivec2 fbo_size, ivec2 pos, ivec2 size);
     11    void Init();
     12    void Render();
     13    void Blit(ivec2 pos, ivec2 size);
    1414
    1515private:
    1616    caca_canvas_t *m_caca;
    17     ivec2 m_font_size, m_canvas_size;
     17    ivec2 m_font_size, m_canvas_size, m_fbo_size;
    1818    int m_cells;
    1919
Note: See TracChangeset for help on using the changeset viewer.