From 8903941462e22349cf321f95b7dde8dad6b3dc21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Aug 2014 12:35:09 +0200 Subject: [PATCH] Text: updated and fixed Renderer docs. Thanks again, @wivlaro. --- src/Magnum/Text/Renderer.h | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Magnum/Text/Renderer.h b/src/Magnum/Text/Renderer.h index 94127c4e6..18a567922 100644 --- a/src/Magnum/Text/Renderer.h +++ b/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 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 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);