CMU462::OSDText Class Reference

Provides an interface for text on-screen display. More...

`#include <osdtext.h>`

## Public Member Functions

| OSDText ()
| Constructor. More...
| ~OSDText ()
| Destructor. More...
int | init (bool use_hdpi)
| Initializes resources required for rendering text. More...
void | render ()
| Draw the text OSD. More...
void | clear ()
| Clear all the lines.
void | resize (size_t w, size_t h)
| Resize internal scales when context size has changed. More...
int | add_line (float x, float y, std::string text="", size_t size=16, Color color=Color::White)
| Add a line of text to the OSD. More...
void | del_line (int line_id)
| Deletes a line. More...
void | set_anchor (int line_id, float x, float y)
| Set the anchor position of a given line. More...
void | set_text (int line_id, std::string text)
| Set the text of a given line. More...
void | set_size (int line_id, size_t size)
| Set the font size of a given line. More...
void | set_color (int line_id, Color color)
| Set the font color of a given line. More...

## Detailed Description

Provides an interface for text on-screen display.

Note that this requires GL_BLEND enabled to work. Do note this is a very basic implementation and the cost of all operations increases linearly with respect to the number of lines and the length of the lines.

## Constructor & Destructor Documentation

CMU462::OSDText::OSDText | ( |  | ) |

Constructor.

Creates an empty text OSD.

CMU462::OSDText::~OSDText | ( |  | ) |

Destructor.

Destroys the textOSD instance and free resources.

## Member Function Documentation

int CMU462::OSDText::init | ( | bool | use_hdpi | ) |

Initializes resources required for rendering text.

This will load a freetype font and compile shaders, etc.

Parameters

  use_hdpi | if text is renderer on HDPI displays

Returns
  0 if successful, -1 on error.

void CMU462::OSDText::render | ( |  | ) |

Draw the text OSD.

Render all the lines.

void CMU462::OSDText::resize | ( | size_t | w,
|  | size_t | h
| ) |  |

Resize internal scales when context size has changed.

This should be called on a window resize, etc.

int CMU462::OSDText::add_line | ( | float | x,
|  | float | y,
|  | std::string | text = `""`,
|  | size_t | size = `16`,
|  | Color | color = `Color::White`
| ) |  |

Add a line of text to the OSD.

This uses GL's screen space standard and maps the horizontal space to [-1, 1] from left to right and the vertical space to [-1, 1] from bottom to top.

Parameters

  x | Horizontal coordinate of the anchor.
  y | Vertical coordinate of the anchor.
  text | The text to add.
  size | The font size of the text.
  color | The color of the text.

Returns
  the line index if successfully added. A valid line index is non-negative. If the line was not successfully added, -1 is returned.

void CMU462::OSDText::del_line | ( | int | line_id | ) |

Deletes a line.

If the given id is not valid, the call has no effect.

Parameters

  line_id | Index of the line to be removed.

void CMU462::OSDText::set_anchor | ( | int | line_id,
|  | float | x,
|  | float | y
| ) |  |

Set the anchor position of a given line.

Lines are anchored at the bottom left corner If the given id is not valid, the call has no effect.

Parameters

  line_id | Index of the line to set the text.
  x | The new x coordinate to set for the line.
  y | The new y coordinate to set for the line.

void CMU462::OSDText::set_text | ( | int | line_id,
|  | std::string | text
| ) |  |

Set the text of a given line.

If the given id is not valid, the call has no effect.

Parameters

  line_id | Index of the line to set the text.
  text | The new text to set for the line.

void CMU462::OSDText::set_size | ( | int | line_id,
|  | size_t | size
| ) |  |

Set the font size of a given line.

If the given id is not valid, the call has no effect.

Parameters

  line_id | Index of the line to set the text.
  size | The new size to set for the line.

void CMU462::OSDText::set_color | ( | int | line_id,
|  | Color | color
| ) |  |

Set the font color of a given line.

If the given id is not valid, the call has no effect.

Parameters

  line_id | Index of the line to set the text.
  color | The new color to set for the line.

The documentation for this class was generated from the following files:

- /Users/Sky/Dropbox/Projects/CMU462/private/p3/CMU462/include/CMU462/osdtext.h
- /Users/Sky/Dropbox/Projects/CMU462/private/p3/CMU462/src/osdtext.cpp