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 The text can be then drawn as usual by configuring the shader and drawing the
mesh: mesh:
@code @code
Text::AbstractFont* font; // Font instance, received from plugin manager
std::unique_ptr<Text::AbstractFont> font;
// Configured glyph cache
Text::GlyphCache cache; Text::GlyphCache cache;
Shaders::VectorShader2D shader; Shaders::Vector2D shader;
Buffer vertexBuffer, indexBuffer; Buffer vertexBuffer, indexBuffer;
Mesh mesh; Mesh mesh;
// Render the text // Render the text, centered
Range2D rectangle; std::tie(mesh, std::ignore) = Text::Renderer2D::render(*font, cache, 0.15f,
std::tie(mesh, rectangle) = Text::Renderer2D::render(*font, cache, 0.15f, "Hello World!", vertexBuffer, indexBuffer, BufferUsage::StaticDraw, Text::Alignment::LineCenter);
"Hello World!", vertexBuffer, indexBuffer, BufferUsage::StaticDraw);
// Draw white text centered on the screen // Draw the text on the screen
shader.setTransformationProjectionMatrix(projection*Matrix3::translation(-rectangle.width()/2.0f)) shader.setTransformationProjectionMatrix(projection)
.setColor(Color3(1.0f)) .setColor(Color3(1.0f))
.setVectorTexture(glyphCache->texture()); .setVectorTexture(glyphCache->texture());
mesh.draw(shader); 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 mutable texts (e.g. FPS counters, chat messages) there is another approach
that doesn't recreate everything on each text change: that doesn't recreate everything on each text change:
@code @code
Text::AbstractFont* font; std::unique_ptr<Text::AbstractFont> font;
Text::GlyphCache cache; Text::GlyphCache cache;
Shaders::VectorShader2D shader; Shaders::Vector2D shader;
// Initialize renderer and reserve memory for enough glyphs // Initialize renderer and reserve memory for enough glyphs
Text::Renderer2D renderer(*font, cache, 0.15f); 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 // Update the text occasionally
renderer.render("Hello World Countdown: 10"); renderer.render("Hello World Countdown: 10");
// Draw the text centered on the screen // Draw the text on the screen
shader.setTransformationProjectionMatrix(projection*Matrix3::translation(-renderer.rectangle().width()/2.0f)) shader.setTransformationProjectionMatrix(projection)
.setColor(Color3(1.0f)) .setColor(Color3(1.0f))
.setVectorTexture(glyphCache->texture()); .setVectorTexture(glyphCache->texture());
renderer.mesh().draw(shader); renderer.mesh().draw(shader);

Loading…
Cancel
Save