#include <FontRenderer.h>
Inheritance diagram for pge::FontRenderer:
Public Member Functions | |
~FontRenderer (void) | |
Destructor. | |
bool | init (void) |
void | render (void) |
Called when the object should render itself. | |
void | timer (unsigned int delay) |
Called when the timer event comes. | |
void | renderString (std::string str, int size, Vector2i position) |
void | renderString (std::string str, int size, int x, int y) |
void | renderChar (char c, int size, int x, int y) |
Static Public Member Functions | |
FontRenderer * | getInstance (void) |
Private Member Functions | |
FontRenderer () | |
Constructor. | |
Private Attributes | |
Texture * | m_fontTexture |
|
Destructor.
Definition at line 34 of file FontRenderer.cpp.
00034 { 00035 } |
|
Constructor.
Definition at line 24 of file FontRenderer.cpp. References DEFAULT_FONT_FILE, and m_fontTexture.
00024 { 00025 m_fontTexture = TextureDatabase::getInstance()->addTexture(DEFAULT_FONT_FILE, "defaultfont", false, true); 00026 } |
|
Definition at line 43 of file FontRenderer.cpp.
00043 { 00044 static FontRenderer instance; 00045 return &instance; 00046 } |
|
Implements pge::IRenderableObject. Definition at line 54 of file FontRenderer.cpp. References m_fontTexture.
00054 { 00055 if(m_fontTexture == NULL) { 00056 return false; 00057 } 00058 return true; 00059 } |
|
Called when the object should render itself.
Implements pge::IRenderableObject. Definition at line 67 of file FontRenderer.cpp.
00067 { 00068 } |
|
Definition at line 112 of file FontRenderer.cpp. References pge::convertToGLCoords(), and m_fontTexture. Referenced by renderString().
00112 { 00113 int ascii; 00114 int du; 00115 int dv; 00116 float uv[4][2]; 00117 float d; 00118 00119 00120 d = 1.0f / 16.0f; 00121 // Calculate position by ASCII value 00122 // Offset is the whitespace character (ASCII 32) 00123 ascii = (int) c - 32; 00124 du = ascii % 16; 00125 dv = (ascii / 16); 00126 00127 // Calculate offset in texture. 00128 uv[0][0] = du * d; 00129 uv[0][1] = d + (dv * d); 00130 uv[1][0] = /* du * d */uv[0][0]; 00131 uv[1][1] = dv * d; 00132 uv[2][0] = d + (du * d); 00133 uv[2][1] = /* dv * d */uv[1][1]; 00134 uv[3][0] = /* d + (du * d) */uv[2][0]; 00135 uv[3][1] = /* d + (dv * d) */uv[0][1]; 00136 00137 renderer::setTextureAlphaBlendEnabled(true); 00138 00139 if(m_fontTexture != NULL) { 00140 renderer::setTexture(m_fontTexture, GL_MODULATE); 00141 } 00142 00143 // TODO: font color 00144 renderer::color4f(1.0f, 1.0f, 1.0f, 1.0f); 00145 00146 glBegin(GL_QUADS); 00147 renderer::vertex2i(convertToGLCoords(x, y), uv[1]); 00148 renderer::vertex2i(convertToGLCoords(x + size, y), uv[2]); 00149 renderer::vertex2i(convertToGLCoords(x + size, y + size), uv[3]); 00150 renderer::vertex2i(convertToGLCoords(x, y + size), uv[0]); 00151 glEnd(); 00152 00153 renderer::setTextureAlphaBlendEnabled(false); 00154 } |
Here is the call graph for this function:
|
Definition at line 95 of file FontRenderer.cpp. References FONT_COMPACT_FACTOR, and renderChar().
00095 { 00096 unsigned int i; 00097 00098 for (i = 0; i < str.length(); i++) { 00099 // CompactFactor reduces the space between the single characters, 00100 // since 00101 // this is mostly too much when using normal generated fontmaps. 00102 renderChar(str[i], size, x + ((i * size) - i * (size / FONT_COMPACT_FACTOR)), y); 00103 } 00104 } |
Here is the call graph for this function:
|
Definition at line 85 of file FontRenderer.cpp. References pge::Vector2i::m_v.
00085 { 00086 renderString(str, size, position.m_v[0], position.m_v[1]); 00087 } |
|
Called when the timer event comes.
Implements pge::IRenderableObject. Definition at line 76 of file FontRenderer.cpp.
00076 { 00077 } |
|
Definition at line 64 of file FontRenderer.h. Referenced by FontRenderer(), init(), and renderChar(). |