DrawText
Syntax
- void DrawText(const std::string& text, int x, int y, float kerning=1.0)
Parameters
- text: the text to draw.
- x: the x position on screen to draw the text at.
- y: the y position on screen to draw the text at.
- kerning: a value to multiply the text spacing by.
Example
#include "Leadwerks.h"
using namespace Leadwerks;
int main(int argc, const char *argv[])
{
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
while (true)
{
if (window->Closed() || window->KeyHit(Key::Escape)) break;
context->SetColor(0.0, 0.0, 1.0);
context->Clear();
//Draw some text centered on the screen
std::string text = "Hello!";
Font* font = context->GetFont();
int x = context->GetWidth() / 2;
int y = context->GetHeight() / 2;
x -= font->GetTextWidth(text) / 2;
y -= font->GetHeight() / 2;
context->SetBlendMode(Blend::Alpha);
context->SetColor(1.0, 1.0, 1.0);
context->DrawText(text, x, y);
context->SetBlendMode(Blend::Solid);
context->Sync();
}
return 0;
}