Browse Source

Text: updated and fixed Renderer docs.

Thanks again, @wivlaro.
pull/68/head
Vladimír Vondruš 12 years ago
parent
commit
8903941462
  1. 28
      src/Magnum/Text/Renderer.h

28
src/Magnum/Text/Renderer.h

@ -176,20 +176,22 @@ methods, returning result either as data arrays or as fully configured mesh.
The text can be then drawn as usual by configuring the shader and drawing the
mesh:
@code
Text::AbstractFont* font;
// Font instance, received from plugin manager
std::unique_ptr<Text::AbstractFont> font;
// Configured glyph cache
Text::GlyphCache cache;
Shaders::VectorShader2D shader;
Shaders::Vector2D shader;
Buffer vertexBuffer, indexBuffer;
Mesh mesh;
// Render the text
Range2D rectangle;
std::tie(mesh, rectangle) = Text::Renderer2D::render(*font, cache, 0.15f,
"Hello World!", vertexBuffer, indexBuffer, BufferUsage::StaticDraw);
// Render the text, centered
std::tie(mesh, std::ignore) = Text::Renderer2D::render(*font, cache, 0.15f,
"Hello World!", vertexBuffer, indexBuffer, BufferUsage::StaticDraw, Text::Alignment::LineCenter);
// Draw white text centered on the screen
shader.setTransformationProjectionMatrix(projection*Matrix3::translation(-rectangle.width()/2.0f))
// Draw the text on the screen
shader.setTransformationProjectionMatrix(projection)
.setColor(Color3(1.0f))
.setVectorTexture(glyphCache->texture());
mesh.draw(shader);
@ -202,19 +204,19 @@ While this method is sufficient for one-shot rendering of static texts, for
mutable texts (e.g. FPS counters, chat messages) there is another approach
that doesn't recreate everything on each text change:
@code
Text::AbstractFont* font;
std::unique_ptr<Text::AbstractFont> font;
Text::GlyphCache cache;
Shaders::VectorShader2D shader;
Shaders::Vector2D shader;
// Initialize renderer and reserve memory for enough glyphs
Text::Renderer2D renderer(*font, cache, 0.15f);
renderer.reserve(32, BufferUsage::DynamicDraw, BufferUsage::StaticDraw);
renderer.reserve(32, BufferUsage::DynamicDraw, BufferUsage::StaticDraw, Text::Alignment::LineCenter);
// Update the text occasionally
renderer.render("Hello World Countdown: 10");
// Draw the text centered on the screen
shader.setTransformationProjectionMatrix(projection*Matrix3::translation(-renderer.rectangle().width()/2.0f))
// Draw the text on the screen
shader.setTransformationProjectionMatrix(projection)
.setColor(Color3(1.0f))
.setVectorTexture(glyphCache->texture());
renderer.mesh().draw(shader);

Loading…
Cancel
Save