CSD462 Library Documentation  1.0
15-462/15-662: Computer Graphics (Fall 2015)
Public Member Functions | List of all members
CSD462::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 ()
 Initializes resources required for rendering text. More...
 
void render ()
 Draw the text OSD. More...
 
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

CSD462::OSDText::OSDText ( )

Constructor.

Creates an empty text OSD.

CSD462::OSDText::~OSDText ( )

Destructor.

Destroys the textOSD instance and free resources.

Member Function Documentation

int CSD462::OSDText::init ( )

Initializes resources required for rendering text.

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

Returns
0 if successful, -1 on error.
void CSD462::OSDText::render ( )

Draw the text OSD.

Render all the lines.

void CSD462::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 CSD462::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
xHorizontal coordinate of the anchor.
yVertical coordinate of the anchor.
textThe text to add.
sizeThe font size of the text.
colorThe 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 CSD462::OSDText::del_line ( int  line_id)

Deletes a line.

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

Parameters
line_idIndex of the line to be removed.
void CSD462::OSDText::set_anchor ( int  line_id,
float  x,
float  y 
)

Set the anchor position of a given line.

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

Parameters
line_idIndex of the line to set the text.
xThe new x coordinate to set for the line.
yThe new y coordinate to set for the line.
void CSD462::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_idIndex of the line to set the text.
textThe new text to set for the line.
void CSD462::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_idIndex of the line to set the text.
sizeThe new size to set for the line.
void CSD462::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_idIndex of the line to set the text.
colorThe new color to set for the line.

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