The ability to draw text
Wroted semi-workable version of classes to render short one line text. It needs for some kind labels. For example for axis labels.
I render text in one complex fragement shader. I hope to know is it affective solution for one line text or not.
Example of text label creation:
#include "glRender.h"
using namespace glRender;
// data/myfont.fnt <- descriptions of font
std::shared_ptr<Font::Font> font = Font::createFromFile("data/myfont.fnt");
auto label = std::make_shared<Label>(utf8_to_wstring("@"), font);
label->setOrigin(0.0f, 0.0f, 1.0f);
// Text to render
std::wstring text = utf8_to_wstring(patch::to_string(42) + "@");
label->setText(text);
Camera * camera = new PerspectiveCamera(35.0f, 16.0f / 9.0f, 1.0f, 400.0f);
camera->lookAt(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 0.0f, -1.0f), Vec3::AXE_Y());
// Draw label
label->draw(camera)
The file data/myfont.fnt content should looks like this:
textures: data/myfont.png
Arial 37pt
97 399 190 25 27 1 20 27 56
98 219 84 23 36 3 11 27 56
99 0 190 24 27 1 20 25 56
100 243 84 23 36 1 11 27 56
101 23 56 25 27 1 20 27 56
102 202 84 16 36 0 10 14 56
Yes, it is raw and ugly but it just first try.
Written on October 12, 2017