CSCI441 OpenGL Library 6.0.1.1
CS@Mines CSCI441 Computer Graphics Course Library
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
CSCI441::Font Class Reference

Stores character glyphs corresponding to a ttf file and draws text to the screen. More...

#include <Font.hpp>

Public Member Functions

 Font ()=delete
 do not allow default Font objects to be constructed
 
 Font (const char *filename)
 Create a Font object containing the glyphs from a given ttf file.
 
 ~Font ()
 cleanup CPU and GPU memory
 
GLboolean isLoaded () const
 tracks if font file was loaded successfully
 
void setScale (GLfloat scaleX, GLfloat scaleY)
 set the amount to scale each glyph when drawing
 
void bind () const
 make this font active, binding its VAO, VBO, and 2D texture to GL_TEXTURE0
 
void draw (const char *str, GLfloat x, GLfloat y) const
 draws a text string at a given (x,y) window coordinate with the currently set scale
 

Detailed Description

Stores character glyphs corresponding to a ttf file and draws text to the screen.

Constructor & Destructor Documentation

◆ Font() [1/2]

CSCI441::Font::Font ( )
delete

do not allow default Font objects to be constructed

Note
see CSCI441::Font::Font(const char*) for proper creation

◆ Font() [2/2]

CSCI441::Font::Font ( const char *  filename)
inlineexplicit

Create a Font object containing the glyphs from a given ttf file.

Parameters
filenamettf file to load glyphs from

Member Function Documentation

◆ bind()

void CSCI441::Font::bind ( ) const
inline

make this font active, binding its VAO, VBO, and 2D texture to GL_TEXTURE0

Note
must be called immediately before CSCI441::Font::draw()

◆ draw()

void CSCI441::Font::draw ( const char *  str,
GLfloat  x,
GLfloat  y 
) const
inline

draws a text string at a given (x,y) window coordinate with the currently set scale

Parameters
strstring to display
xwindow X-coordinate to draw text at
ywindow Y-coordinate to draw text at
Precondition
MUST call CSCI441::Font::bind() prior to this call
Note
see CSCI441::Font::setScale()

◆ isLoaded()

GLboolean CSCI441::Font::isLoaded ( ) const
inline

tracks if font file was loaded successfully

Returns
true iff font file was successfully loaded

◆ setScale()

void CSCI441::Font::setScale ( GLfloat  scaleX,
GLfloat  scaleY 
)
inline

set the amount to scale each glyph when drawing

Parameters
scaleXamount to scale glyph horizontally
scaleYamount to scale glyph vertically
Note
values typically refer to inverse screen size, e.g. the size of each pixel

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