Load

Loads a font from a True-Type Font (.ttf) file.

Syntax

Parameters

Returns

Returns the loaded Font. If the Font cannot be loaded, NULL is returned.

Remarks

Fonts can be loaded with either the Font::Smooth or Font::Pixel settings.

At this time, only the Font::English character set is supported. Additional character sets may be supported in the future.

If the flags parameter includes value Asset::Unmanaged, a unique asset will be loaded from the file. Otherwise, an instance of the Asset will be returned, if it is already in system memory.

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);
//Load a font
Font* font = Font::Load("Fonts/arial.ttf", 36);

context->SetFont(font);
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;

context->SetColor(0, 0, 0, 0);
context->Clear();
context->SetColor(1, 1, 1, 0);
//Display some centered text
std::string text = "Leadwerks";
int screenwidth = context->GetWidth();
int screenheight = context->GetHeight();
int x = (screenwidth - font->GetTextWidth(text)) / 2;
int y = (screenheight - font->GetHeight()) / 2;

context->SetBlendMode(Blend::Alpha);
context->DrawText(text, x, y);

context->SetBlendMode(Blend::Solid);
context->Sync();
}
return 0;
}