Changeset 1483


Ignore:
Timestamp:
Jun 16, 2012, 5:16:54 PM (7 years ago)
Author:
sam
Message:

neercs: font blitting is now pixel perfect.

Location:
trunk/neercs/video
Files:
2 edited

Legend:

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

    r1482 r1483  
    4141#define DEBUG 1            // debug flag //#if defined(_DEBUG)
    4242#define SHADER 1           // shader flag
    43 #define FUCK 1             // test flag
    4443#define PID M_PI/180.0f    // pi ratio
    4544#define CR 1.0f/256.0f     // color ratio
     
    165164              shader_postfx_sync;
    166165
    167 FrameBuffer *fbo_back, *fbo_front, *fbo_blur_h, *fbo_blur_v;
    168 FrameBuffer *fbo_ping, *fbo_pong;
     166FrameBuffer *fbo_text, *fbo_back, *fbo_front;
     167FrameBuffer *fbo_blur_h, *fbo_blur_v, *fbo_ping, *fbo_pong;
    169168#endif
    170169
     
    181180        for (int j = 0; j < m_height; j++)
    182181        for (int i = 0; i < m_width; i++)
    183             m_vertices << vec2(5.1 / 128.0 * i - 0.91, 0.75 - 0.0525 * j);
     182            m_vertices << vec2(i, j);
    184183    }
    185184
     
    194193                                             VertexUsage::Color, 1);
    195194        m_texture = m_shader->GetUniformLocation("in_Texture");
     195        m_transform = m_shader->GetUniformLocation("in_Transform");
    196196        m_vdecl
    197197          = new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position),
     
    208208    }
    209209
    210     void Blit()
    211     {
     210    void Blit(ivec2 screen_size, ivec2 font_size)
     211    {
     212        /* Transform matrix for the scene:
     213         *  - translate to the centre of the glyph
     214         *  - scale by 2.f * font_size / screen_size
     215         *  - translate to the upper left corner */
     216        mat4 xform = mat4::translate(-1.f, 1.f, 0.f)
     217                   * mat4::scale(vec3(2.f * font_size / (screen_size), 1.f)
     218                                  * vec3(1.f, -1.f, 1.f))
     219                   * mat4::translate(0.5f, 0.5f, 0.f);
     220
     221        /* Upload libcaca canvas contents to the vertex buffers */
    212222        uint32_t *colors = (uint32_t *)m_vbo2->Lock(0, 0);
    213223        for (int j = 0; j < m_height; j++)
     
    234244        //glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
    235245        glDisable(GL_POINT_SMOOTH);
    236         glPointSize(16.f);
     246        glPointSize((float)max(font_size.x, font_size.y));
    237247        m_shader->Bind();
    238248        tex_map->Bind();
    239249        m_shader->SetUniform(m_texture, 0);
     250        m_shader->SetUniform(m_transform, xform);
    240251        m_vdecl->SetStream(m_vbo1, m_coord);
    241252        m_vdecl->SetStream(m_vbo2, m_color);
     
    256267    Shader *m_shader;
    257268    ShaderAttrib m_coord, m_color, m_char;
    258     ShaderUniform m_texture;
     269    ShaderUniform m_texture, m_transform;
    259270    VertexDeclaration *m_vdecl;
    260271    VertexBuffer *m_vbo1, *m_vbo2, *m_vbo3;
     
    379390    if (shader_flag)
    380391    {
     392        fbo_text = new FrameBuffer(screen_size);
    381393        fbo_back = new FrameBuffer(screen_size);
    382394        fbo_front = new FrameBuffer(screen_size);
     
    533545{
    534546#if SHADER
     547    /* 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
     552
     553    /* Clear the back buffer */
     554#if SHADER
    535555    if(shader_flag)
    536556    {
     
    546566#endif
    547567
    548     text_render->Blit();
     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));
    549571
    550572    glEnableClientState(GL_VERTEX_ARRAY);
     
    558580
    559581    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
    560595
    561596    tex_map->Bind();
  • trunk/neercs/video/text.lolfx

    r1477 r1483  
    99varying vec4 pass_Background;
    1010varying vec2 pass_UV;
     11
     12uniform mat4 in_Transform;
    1113
    1214void main()
     
    3234    //gl_PointSize = 40;
    3335
    34     gl_Position = vec4(in_Position, 0.0, 1.0);
     36    gl_Position = in_Transform * vec4(in_Position, 0.0, 1.0);
    3537}
    3638
Note: See TracChangeset for help on using the changeset viewer.