Browse Source

neercs: handle caca canvas size changes automatically.

master
Sam Hocevar 12 years ago
parent
commit
24a2117c17
2 changed files with 29 additions and 7 deletions
  1. +27
    -6
      neercs/video/text-render.cpp
  2. +2
    -1
      neercs/video/text-render.h

+ 27
- 6
neercs/video/text-render.cpp View File

@@ -36,9 +36,6 @@ TextRender::TextRender(caca_canvas_t *caca, ivec2 font_size)
m_fbo_size(m_font_size * m_canvas_size),
m_cells(m_canvas_size.x * m_canvas_size.y)
{
for (int j = 0; j < m_canvas_size.y; j++)
for (int i = 0; i < m_canvas_size.x; i++)
m_vertices << vec2(i, j);
}

void TextRender::Init()
@@ -60,9 +57,16 @@ void TextRender::Init()
VertexStream<uint32_t>(VertexUsage::Color),
VertexStream<uint32_t>(VertexUsage::Color));

m_vbo1 = new VertexBuffer(m_vertices.Bytes());
void *vertices = m_vbo1->Lock(0, 0);
memcpy(vertices, &m_vertices[0], m_vertices.Bytes());
CreateBuffers();
}

void TextRender::CreateBuffers()
{
m_vbo1 = new VertexBuffer(m_cells * sizeof(vec2));
vec2 *vertices = (vec2 *)m_vbo1->Lock(0, 0);
for (int j = 0; j < m_canvas_size.y; j++)
for (int i = 0; i < m_canvas_size.x; i++)
vertices[j * m_canvas_size.x + i] = vec2(i, j);
m_vbo1->Unlock();

m_vbo2 = new VertexBuffer(m_cells * sizeof(int32_t));
@@ -73,6 +77,23 @@ void TextRender::Init()

void TextRender::Render()
{
/* Handle canvas size changes */
ivec2 current_size(caca_get_canvas_width(m_caca),
caca_get_canvas_height(m_caca));
if (current_size != m_canvas_size)
{
delete m_vbo1;
delete m_vbo2;
delete m_vbo3;
delete m_fbo;

m_canvas_size = current_size;
m_fbo_size = m_font_size * m_canvas_size;
m_cells = m_canvas_size.x * m_canvas_size.y;

CreateBuffers();
}

/* Transform matrix for the scene:
* - translate to the centre of the glyph
* - scale by 2.f * font_size / fbo_size


+ 2
- 1
neercs/video/text-render.h View File

@@ -13,11 +13,12 @@ struct TextRender
void Blit(ivec2 pos, ivec2 size);

private:
void CreateBuffers();

caca_canvas_t *m_caca;
ivec2 m_font_size, m_canvas_size, m_fbo_size;
int m_cells;

Array<vec2> m_vertices;
TileSet *m_font;
Shader *m_shader;
ShaderAttrib m_coord, m_color, m_char;


Loading…
Cancel
Save