doodle
0.2
Intended to support teaching C++, doodle is a simple library that helps make a window and makes it easy to do some drawing.
|
Functions | |
void | doodle::draw_text (const std::wstring &str, double x, double y) noexcept |
Draws wide character based text to the screen. More... | |
void | doodle::draw_text (const std::string &str, double x, double y) noexcept |
Draws text to the screen. More... | |
int | doodle::create_distance_field_bitmap_font (const std::filesystem::path &fnt_filepath) noexcept |
Given a file path to a *.fnt file it will create a distance field bitmap font. More... | |
void | doodle::set_font (int font_id) noexcept |
Changes the font type to be used when drawing text. More... | |
void | doodle::set_font_size (double font_size) noexcept |
Sets the current font size. This size will be used in all subsequent calls to the draw_text() function. More... | |
void | doodle::set_font_fade_out_interval (double inside_distance, double outside_distance) noexcept |
Defines the distance interval to draw font characters and how to fade them out from opaque to translucent. More... | |
void | doodle::set_font_backdrop_fade_out_interval (double inside_distance, double outside_distance) noexcept |
Defines the distance interval to draw the backdrop of font characters and how to fade them out from opaque to translucent. More... | |
void | doodle::set_font_backdrop_offset (double texel_x, double texel_y) noexcept |
Repositions the backdrop of the font characters. Useful for creating a custom drop shadow effect. More... | |
Variables | |
constexpr int | doodle::DEFAULT_FONT_ID = 0 |
Holds the ID value for the provided font that comes with doodle. More... | |
|
noexcept |
Given a file path to a *.fnt file it will create a distance field bitmap font.
It will parse that file to get all of the Bitmap information and create GPU texture instances of all the image files listed. It assumes that the image files are in the same folder directory as the provided *.fnt file. It will return a positive value on success and a negative value if it failed to parse the *.fnt file for whatever reason.
The default font, provided with doodle has a font ID of \(0\) and is specified by doodle::DEFAULT_FONT_ID.
The original bitmap font file definition comes from AngleCode's BMFont. However BMFont does not generate distance field bitmap fonts, so the suggested tool to use is the Hiero tool. Hiero can create distance field bitmap fonts and save it in the AngelCode file format. Here is a video that explains Distance Field Text Rendering and how to generate the font with Hiero.
fnt_filepath | Path to a fnt file in the BMFont text file format. |
The following example built the distance field bitmap font with the Hiero tool. Here is the Hiero Setting File configured to build with the Gaegu Font. This generated the relevant Gaegu.fnt file and it's partner Gaegu.png file.
|
noexcept |
Draws text to the screen.
A default font will be used unless a font is set with the set_font() function and a default size will be used unless a font is set with set_font_size(). Change the color of the text with the set_fill_color() function. Change the color of the backdrop with the set_outline_color() function.
str | the text to be displayed |
x | x-coordinate of text |
y | y-coordinate of text |
|
noexcept |
Draws wide character based text to the screen.
Using wide characters allows us to draw characters not just for the English language but for other languages like Korean too.
A default font will be used unless a font is set with the set_font() function and a default size will be used unless a font is set with set_font_size(). Change the color of the text with the set_fill_color() function. Change the color of the backdrop with the set_outline_color() function.
str | the text to be displayed |
x | x-coordinate of text |
y | y-coordinate of text |
The following example built the distance field bitmap font with the Hiero tool. Here is the Hiero Setting File configured to build with the Gaegu Font. This generated the relevant Gaegu.fnt file and it's partner Gaegu.png file.
|
noexcept |
Changes the font type to be used when drawing text.
The default font provided with doodle is defined by doodle::DEFAULT_FONT_ID.
font_id | ID of a font that was previsouly created with create_distance_field_bitmap_font(). |
The following example built the distance field bitmap font with the Hiero tool. Here is the Hiero Setting File configured to build with the Gaegu Font. This generated the relevant Gaegu.fnt file and it's partner Gaegu.png file.
|
noexcept |
Defines the distance interval to draw the backdrop of font characters and how to fade them out from opaque to translucent.
The inside_distance defines the distance that is considered completely inside a font character. The outside_distance defines the distance that is considered completely outside a font character. The distance value that are in between theses two values will be smoothed out. It is the same logic as set_font_fade_out_interval(), however this will draw the character based off of the outline color and will be behind the fill colored part.
The distance is measured in a normalized space, so must be between [0,1]. Values outside of this will be clamped. If the given outside_distance is less than the inside_distance it will be replaced to match the inside_distance.
In this example the inside_distance is 0.5 and the outside_distance is 0.6. Anything inside 0.5 is considered completely inside the letter and will be colored opaquely. Anything outside 0.6 is considered completely outside and will be colored transparently.
inside_distance | The normalized distance the defines what is completely inside a character font for the backdrop. Clamped to [0,1]. |
outside_distance | The normalized distance the defines what is completely outside a character font for the backdrop. Clamped to [0,1]. |
|
noexcept |
Repositions the backdrop of the font characters. Useful for creating a custom drop shadow effect.
The distance to offset the backdrop is measured in texels relative to the image defining the Bitmap Font. The texel coordinate system is left handed where the origin is the very top left and positive y goes down.
texel_x | How far to horizontally offset the backdrop character in texels |
texel_y | How far to vertically offset the backdrop character in texels |
|
noexcept |
Defines the distance interval to draw font characters and how to fade them out from opaque to translucent.
The inside_distance defines the distance that is considered completely inside a font character. The outside_distance defines the distance that is considered completely outside a font character. The distance value that are in between theses two values will be smoothed out.
The distance is measured in a normalized space, so must be between [0,1]. Values outside of this will be clamped. If the given outside_distance is less than the inside_distance it will be replaced to match the inside_distance.
In this example the inside_distance is 0.5 and the outside_distance is 0.6. Anything inside 0.5 is considered completely inside the letter and will be colored opaquely. Anything outside 0.6 is considered completely outside and will be colored transparently.
inside_distance | The normalized distance the defines what is completely inside a character font. Clamped to [0,1]. |
outside_distance | The normalized distance the defines what is completely outside a character font. Clamped to [0,1]. |
|
noexcept |
Sets the current font size. This size will be used in all subsequent calls to the draw_text() function.
font_size | the desired font size |
|
constexpr |
Holds the ID value for the provided font that comes with doodle.
Definition at line 1257 of file drawing.hpp.