-
Notifications
You must be signed in to change notification settings - Fork 5
Rendering text
Vlod edited this page Nov 23, 2023
·
9 revisions
In order to render text you need a font file (.ttf file). Loading is easy, you can just load it from a file.
gl2d::Font f(RESOURCES_PATH "roboto_black.ttf");
//or
f.createFromFile(filePath);
Or you can read the file yourself and give it to your font.
gl2d::Font f;
f.createFromTTF(data, sizeOfData);
Now you can render text!
The origin will be the bottom left corner since it represents the line for the text to be drawn / the center of the text, as specified by the showInCenter parameter Pacing and lineSpace are influenced by size
- renderText: renders text.
- getTextSize: gets the size of the rendered text.
- determineTextRescaleFitSmaller: determines the text size so that it fits in the given box, the x and y components of the transform are ignored.
- determineTextRescaleFit: determines the text size so that it fits in the given box, the x and y components of the transform are ignored
- determineTextRescaleFitBigger: determines the text size so that it fits in the given box, the x and y components of the transform are ignored
- wrap: calculates warped text (new line when exceeded max width), returns the number of lines, out rez is optional
- renderTextWrapped: renders text wrapped.
- position: the position of the bottom left corner of the text.
- showInCenter: if this is true, the position will mean the center of the text. It is true by default.
- text: the text :D
- font: the font.
- color: the color of the text.
- size: size of the text.
- spacing: spacing of letters.
- line_space: spacing of lines.
- ShadowColor: the shadow is rendered behind the text, you can leave it blank if you don't want (opacity == 0).
- LightColor: the light is rendered on top of the text, you can leave it blank if you don't want (opacity == 0).
renderer.renderText({300,100}, "Hello world", f, Colors_White);