Changeset 1484


Ignore:
Timestamp:
Jun 16, 2012, 7:19:17 PM (8 years ago)
Author:
sam
Message:

neercs: the text rendering object now owns its rendering buffer.

Location:
trunk/neercs/video
Files:
2 edited

Legend:

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

    r1483 r1484  
    164164              shader_postfx_sync;
    165165
    166 FrameBuffer *fbo_text, *fbo_back, *fbo_front;
     166FrameBuffer *fbo_back, *fbo_front;
    167167FrameBuffer *fbo_blur_h, *fbo_blur_v, *fbo_ping, *fbo_pong;
    168168#endif
     
    183183    }
    184184
    185     void Init()
     185    void Init(ivec2 screen_size, ivec2 font_size)
    186186    {
    187187        m_shader = Shader::Create(lolfx_text);
     
    206206        m_vbo2 = new VertexBuffer(m_width * m_height * sizeof(int32_t));
    207207        m_vbo3 = new VertexBuffer(m_width * m_height * sizeof(int32_t));
    208     }
    209 
    210     void Blit(ivec2 screen_size, ivec2 font_size)
     208
     209        m_fbo = new FrameBuffer(screen_size);
     210    }
     211
     212    void Render(ivec2 screen_size, ivec2 font_size)
    211213    {
    212214        /* Transform matrix for the scene:
     
    241243        m_vbo3->Unlock();
    242244
     245        m_fbo->Bind();
    243246        glEnable(GL_POINT_SPRITE);
    244247        //glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
     
    258261        m_shader->Unbind();
    259262        glDisable(GL_POINT_SPRITE);
     263        m_fbo->Unbind();
     264    }
     265
     266    void Blit()
     267    {
     268        /* FIXME: scaling is wrong */
     269        glDisable(GL_BLEND);
     270        glEnable(GL_TEXTURE_2D);
     271        glBindTexture(GL_TEXTURE_2D, m_fbo->GetTexture());
     272        glColor3f(1.0f,1.0f,1.0f);
     273
     274        int x = dos_m;
     275        int y = dos_m + (font_size.y + 2) * ratio_2d.y;
     276        int w = screen_size.x - dos_m * 2;
     277        int h = screen_size.y - dos_m * 2 - (font_size.y + 2) * ratio_2d.y;
     278
     279        glLoadIdentity();
     280        glBegin(GL_QUADS);
     281            glTexCoord2f(1.0f, 1.0f);
     282            glVertex2i(x+w, y  );
     283            glTexCoord2f(0.0f, 1.0f);
     284            glVertex2i(x  , y  );
     285            glTexCoord2f(0.0f, 0.0f);
     286            glVertex2i(x  , y+h);
     287            glTexCoord2f(1.0f, 0.0f);
     288            glVertex2i(x+w, y+h);
     289        glEnd();
    260290    }
    261291
     
    270300    VertexDeclaration *m_vdecl;
    271301    VertexBuffer *m_vbo1, *m_vbo2, *m_vbo3;
     302    FrameBuffer *m_fbo;
    272303};
    273304
     
    387418    // initialize some variable
    388419    screen();
     420
    389421#if SHADER
    390422    if (shader_flag)
    391423    {
    392         fbo_text = new FrameBuffer(screen_size);
     424        /* Initialise framebuffer objects */
    393425        fbo_back = new FrameBuffer(screen_size);
    394426        fbo_front = new FrameBuffer(screen_size);
     
    472504
    473505Render::Render(caca_canvas_t *caca)
    474   : m_caca(caca)
     506  : m_caca(caca),
     507    m_ready(false)
    475508{
    476509    text_render = new TextRender(m_caca);
     
    486519    Entity::TickDraw(seconds);
    487520
    488     static int todo = 1;
    489     if (todo)
     521    if (!m_ready)
    490522    {
    491523        CreateGLWindow("LOL");
    492         todo = 0;
    493         text_render->Init();
     524        text_render->Init(screen_size, ivec2(8, 8));
     525
     526        m_ready = true;
    494527    }
    495528
     
    544577void Render::Draw2D()
    545578{
    546 #if SHADER
    547579    /* Draw text in an offline buffer */
    548     fbo_text->Bind();
    549     text_render->Blit(screen_size, ivec2(8, 8));
    550     fbo_text->Unbind();
    551 #endif
     580    text_render->Render(screen_size, ivec2(8, 8));
    552581
    553582    /* Clear the back buffer */
     
    566595#endif
    567596
    568     /* FIXME: when SHADER is true, we should blit the offline
    569      * buffer instead, but for some reason it doesn't work yet. */
    570     text_render->Blit(screen_size, ivec2(8, 8));
     597    text_render->Blit();
    571598
    572599    glEnableClientState(GL_VERTEX_ARRAY);
     
    580607
    581608    init_viewport(1);
    582 
    583 #if 0
    584     /* Render text buffer to the current buffer */
    585     glEnable(GL_BLEND);
    586     glEnable(GL_TEXTURE_2D);
    587     glBlendFunc(GL_ONE, GL_ONE);
    588     glVertexPointer(2, GL_INT, 0, shell_vtx);
    589     glTexCoordPointer(2, GL_FLOAT, 0, shell_tex);
    590     shader_simple->Bind();
    591     shader_simple->SetTexture(shader_simple_texture, fbo_text->GetTexture(), 0);
    592     fs_quad();
    593     shader_simple->Unbind();
    594 #endif
    595609
    596610    tex_map->Bind();
  • trunk/neercs/video/render.h

    r1462 r1484  
    2222private:
    2323    caca_canvas_t *m_caca;
     24    bool m_ready;
    2425};
    2526
Note: See TracChangeset for help on using the changeset viewer.