X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FGraphic%2FText.cpp;h=6998c7a65557b5bad34dbbc386496c0c10e802fd;hb=b9a46d8e2b7e7e22c706e7dd3734f31015db4408;hp=ffc8b0a22db3154cc2427de4ab075ca39cacf020;hpb=eadd0bae922f47c50bc3450ecd43b521025e4b75;p=lugaru.git diff --git a/Source/Graphic/Text.cpp b/Source/Graphic/Text.cpp index ffc8b0a..6998c7a 100644 --- a/Source/Graphic/Text.cpp +++ b/Source/Graphic/Text.cpp @@ -58,28 +58,24 @@ void Text::BuildFont() // Build Our Font Display List cx = float((loop - 256) % 16) / 16.0f; // X Position Of Current Character cy = float((loop - 256) / 16) / 16.0f; // Y Position Of Current Character } - glNewList(base + loop, GL_COMPILE); // Start Building A List - glBegin(GL_QUADS); // Use A Quad For Each Character - glTexCoord2f(cx, 1 - cy - 0.0625f + .001); // Texture Coord (Bottom Left) - glVertex2i(0, 0); // Vertex Coord (Bottom Left) + glNewList(base + loop, GL_COMPILE); // Start Building A List + glBegin(GL_QUADS); // Use A Quad For Each Character + glTexCoord2f(cx, 1 - cy - 0.0625f + .001); // Texture Coord (Bottom Left) + glVertex2i(0, 0); // Vertex Coord (Bottom Left) glTexCoord2f(cx + 0.0625f, 1 - cy - 0.0625f + .001); // Texture Coord (Bottom Right) - glVertex2i(16, 0); // Vertex Coord (Bottom Right) - glTexCoord2f(cx + 0.0625f, 1 - cy - .001); // Texture Coord (Top Right) - glVertex2i(16, 16); // Vertex Coord (Top Right) - glTexCoord2f(cx, 1 - cy - +.001); // Texture Coord (Top Left) - glVertex2i(0, 16); // Vertex Coord (Top Left) - glEnd(); // Done Building Our Quad (Character) - if (loop < 256) + glVertex2i(16, 0); // Vertex Coord (Bottom Right) + glTexCoord2f(cx + 0.0625f, 1 - cy - .001); // Texture Coord (Top Right) + glVertex2i(16, 16); // Vertex Coord (Top Right) + glTexCoord2f(cx, 1 - cy - +.001); // Texture Coord (Top Left) + glVertex2i(0, 16); // Vertex Coord (Top Left) + glEnd(); // Done Building Our Quad (Character) + if (loop < 256) { glTranslated(10, 0, 0); // Move To The Right Of The Character - else + } else { glTranslated(8, 0, 0); // Move To The Right Of The Character + } glEndList(); // Done Building The Display List - } // Loop Until All 256 Are Built -} - -void Text::glPrint(float x, float y, const std::string& string, int set, float size, float width, float height) // Where The Printing Happens -{ - glPrint(x, y, string, set, size, width, height, 0, string.size()); + } // Loop Until All 256 Are Built } void Text::_glPrint(float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end, int offset) // Where The Printing Happens @@ -87,7 +83,7 @@ void Text::_glPrint(float x, float y, const std::string& string, int set, float if (set > 1) { set = 1; } - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); FontTexture.bind(); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); @@ -102,53 +98,54 @@ void Text::_glPrint(float x, float y, const std::string& string, int set, float glLoadIdentity(); glTranslated(x, y, 0); glScalef(size, size, 1); - glListBase(base - 32 + (128 * set) + offset); // Choose The Font Set (0 or 1) + glListBase(base - 32 + (128 * set) + offset); // Choose The Font Set (0 or 1) glCallLists(end - start, GL_BYTE, &string[start]); // Write The Text To The Screen glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glEnable(GL_DEPTH_TEST); - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } -void Text::glPrint(float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end) // Where The Printing Happens +void Text::glPrint(float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end) { + if (end < 0) { + end = string.size(); + } _glPrint(x, y, string, set, size, width, height, start, end, 0); } -void Text::glPrintOutline(float x, float y, const std::string& string, int set, float size, float width, float height) // Where The Printing Happens -{ - glPrintOutline(x, y, string, set, size, width, height, 0, string.size()); -} - -void Text::glPrintOutline(float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end) // Where The Printing Happens +void Text::glPrintOutline(float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end) { + if (end < 0) { + end = string.size(); + } _glPrint(x, y, string, set, size, width, height, start, end, 256); } -void Text::glPrintOutlined(float x, float y, const std::string& string, int set, float size, float width, float height) // Where The Printing Happens + +void Text::glPrintOutlined(float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end) { - glPrintOutlined(1, 1, 1, x, y, string, set, size, width, height); + glPrintOutlined(1, 1, 1, 1, x, y, string, set, size, width, height, start, end); } -void Text::glPrintOutlined(float r, float g, float b, float x, float y, const std::string& string, int set, float size, float width, float height) // Where The Printing Happens +void Text::glPrintOutlined(float r, float g, float b, float a, float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end) { - glColor4f(0, 0, 0, 1); - glPrintOutline( x - 2 * size, y - 2 * size, string, set, size * 2.5 / 2, width, height); - glColor4f(r, g, b, 1); - glPrint( x, y, string, set, size, width, height); + glColor4f(0, 0, 0, a); + glPrintOutline(x - 2 * size, y - 2 * size, string, set, size * 2.5 / 2, width, height, start, end); + glColor4f(r, g, b, a); + glPrint(x, y, string, set, size, width, height, start, end); } Text::Text() { base = 0; } + Text::~Text() { if (base) { glDeleteLists(base, 512); base = 0; } - FontTexture.destroy(); } -