1 #ifndef NTA_SPRITEFONT_H_INCLUDED
2 #define NTA_SPRITEFONT_H_INCLUDED
6 #include <SDL2/SDL_ttf.h>
8 #include "nta/SpriteBatch.h"
10 #define FIRST_PRINTABLE_CHAR ((char)32) //space
11 #define LAST_PRINTABLE_CHAR ((char)126) //~
12 #define NUM_PRINTABLE_CHARS (LAST_PRINTABLE_CHAR-FIRST_PRINTABLE_CHAR+1)
13 #define SPRITE_FONT_TAB_SIZE 4
31 CharRect(glm::vec2 tl, glm::vec2 d,
bool a) : topLeft(tl), dimensions(d), addedToMap(a) {
48 void addRect(
char c, crvec2 dimensions);
60 void init(TTF_Font* font);
72 glm::vec2
measure(crstring text)
const;
79 crvec4 color = glm::vec4(1),
float depth = NTA_DEFAULT_DEPTH)
const;
80 void drawText(
SpriteBatch& batch, crstring text, crvec4 posRect, crvec4 color = glm::vec4(1),
81 float depth = NTA_DEFAULT_DEPTH)
const;
83 crvec4 color = glm::vec4(1),
float depth = NTA_DEFAULT_DEPTH)
const;
92 #endif // NTA_SPRITEFONT_H_INCLUDED
GLuint getTexture() const
Returns the (id of) the texture used for rendering font.
a rectangle representing the location of a char in the FontMap
int font_height() const
returns m_fontHeight
glm::vec2 size
the size of the rendered glyph
GLuint m_texId
the idea of the generated texture
void position()
positions map so that the topleft is at (0,0)
glm::vec4 uvRect
the rectangle containing this glyph in the texture
bool isOverlapping(const CharRect &rect) const
returns whether or not rect is overlapping with any existing CharRect
CharGlyph * m_charGlyphs
a collection of glyphs for each char
void destroy()
Destroys this SpriteFont.
void addRect(char c, crvec2 dimensions)
adds a rectangle and associates it with c (replacing any preexisting rectangle)
FontMap()
constructor and destructor
int m_fontHeight
the height of the font
glm::vec2 measure(crstring text) const
returns the dimensions of the rectangle containing the text
CharRect * m_rects
the rectangles making up the FontMap
void drawText(SpriteBatch &batch, crstring text, crvec2 topLeft, crvec2 scale, crvec4 color=glm::vec4(1), float depth=NTA_DEFAULT_DEPTH) const
renders text with specified location, color, scale, etc.
represents a single char in the texture
represents the organization of a texture containing the characters
void init(TTF_Font *font)
Loads in a .ttf file, creates a font texture from it which is then used to render text.
glm::vec2 getBoundingDimensions() const
returns the dimensions of the rectangle that contains the FontMap
void drawTexture(SpriteBatch &batch, crvec4 posRect=glm::vec4(-100, 100, 200, 200)) const
renders texture