]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/text.cpp
Bind the font texture in Text::render
[libs/gltk.git] / source / text.cpp
index c8c6f55ea3d6597ca348b7dbc911672d93d0ed6e..d80bd177126cbca14752ad65b262d3ac36bc340c 100644 (file)
@@ -1,12 +1,6 @@
-/* $Id$
-
-This file is part of libmspgltk
-Copyright © 2009-2010  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <msp/gl/immediate.h>
 #include <msp/gl/matrix.h>
+#include <msp/gl/texture2d.h>
 #include "style.h"
 #include "text.h"
 
@@ -115,7 +109,7 @@ void Text::insert(unsigned pos, const string &s)
 unsigned Text::get_line_length(unsigned i) const
 {
        if(i>=lines.size())
-               throw InvalidParameterValue("Invalid line number");
+               throw out_of_range("Text::get_line_length");
        return lines[i].length;
 }
 
@@ -167,6 +161,7 @@ void Text::render(const Part &part, const Geometry &parent, unsigned first_row)
        if(!style || lines.empty())
                return;
 
+       const GL::Font *font = style->get_font();
        const GL::Color &color = style->get_font_color();
        GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
        imm.color(color.r, color.g, color.b);
@@ -174,6 +169,8 @@ void Text::render(const Part &part, const Geometry &parent, unsigned first_row)
        RenderData data;
        data.bld = &imm;
 
+       GL::Bind bind_tex(font->get_texture());
+
        process_lines<RenderData, &Text::render_line>(part, parent, first_row, data);
 }
 
@@ -249,7 +246,7 @@ void Text::render_line(unsigned i, const Geometry &rgeom, RenderData &data) cons
        GL::translate(rgeom.x, rgeom.y, 0);
        GL::scale_uniform(font->get_default_size());
 
-       font->draw_string(text.substr(line.start, line.length), *data.bld);
+       font->build_string(text.substr(line.start, line.length), *data.bld);
 }
 
 void Text::coords_to_geom_line(unsigned i, const Geometry &rgeom, CoordsToGeomData &data) const