diff --git a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp index da53fae6d5..a5467c6e6a 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp @@ -22,7 +22,13 @@ #include "RasterFont.h" // globals -const GLubyte rasters[][13] = { + +static const u32 char_width = 8; +static const u32 char_height = 13; +static const u32 char_offset = 32; +static const u32 char_count = 95; + +const u8 rasters[char_count][char_height] = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36}, @@ -122,102 +128,122 @@ const GLubyte rasters[][13] = { RasterFont::RasterFont() { - // set GL modes - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - // create the raster font - fontOffset = glGenLists(128); - for (int i = 32; i < 127; i++) { - glNewList(i + fontOffset, GL_COMPILE); - glBitmap(8, 13, 0.0f, 2.0f, 10.0f, 0.0f, rasters[i - 32]); - glEndList(); + // generate the texture + glEnable(GL_TEXTURE_RECTANGLE); + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_RECTANGLE, texture); + u32* texture_data = new u32[char_width*char_count*char_height]; + for(u32 y=0; y= TEMP_BUFFER_SIZE) - length = TEMP_BUFFER_SIZE - 1; - - // Sanitize string to avoid GL errors. - char *s2 = temp_buffer; - memcpy(s2, s, length); - s2[length] = 0; - for (int i = 0; i < length; i++) { - if (s2[i] < 32 || s2[i] > 126) - s2[i] = '!'; - } - - // go to the right spot - glRasterPos3d(x, y, z); - GL_REPORT_ERRORD(); - - glPushAttrib (GL_LIST_BIT); - glListBase(fontOffset); - glCallLists((GLsizei)strlen(s2), GL_UNSIGNED_BYTE, (GLubyte *) s2); - GL_REPORT_ERRORD(); - glPopAttrib(); - GL_REPORT_ERRORD(); -} - -void RasterFont::printCenteredString(const char *s, double y, int screen_width, double z) -{ - int length = (int)strlen(s); - int x = (int)(screen_width/2.0 - (length/2.0)*char_width); - printString(s, x, y, z); -} - -void RasterFont::printMultilineText(const char *text, double start_x, double start_y, double z, int bbWidth, int bbHeight) -{ - double x = start_x; - double y = start_y; - char temp[1024]; - char *t = temp; - while (*text) - { - if (*text == '\n') - { - *t = 0; - printString(temp, x, y, z); - y -= char_height * 2.0f / bbHeight; + return; // nothing to do + + glBindVertexArray(VAO); + glBindBuffer(GL_ARRAY_BUFFER, VBO); + glBufferData(GL_ARRAY_BUFFER, length*4*6*sizeof(GLfloat), NULL, GL_STREAM_DRAW); + GLfloat *vertices = (GLfloat*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); + + int usage = 0; + GLfloat delta_x = 2*char_width/GLfloat(bbWidth); + GLfloat delta_y = 2*char_height/GLfloat(bbHeight); + GLfloat border_x = 1*2/GLfloat(bbWidth); + GLfloat border_y = 2*2/GLfloat(bbHeight); + + GLfloat x = start_x; + GLfloat y = start_y; + + for(int i=0; i= char_count+char_offset) continue; + + vertices[usage++] = x; + vertices[usage++] = y; + vertices[usage++] = (c-char_offset)*char_width; + vertices[usage++] = 0; + + vertices[usage++] = x+delta_x; + vertices[usage++] = y; + vertices[usage++] = (c-char_offset+1)*char_width; + vertices[usage++] = 0; + + vertices[usage++] = x+delta_x; + vertices[usage++] = y+delta_y; + vertices[usage++] = (c-char_offset+1)*char_width; + vertices[usage++] = char_height; + + vertices[usage++] = x; + vertices[usage++] = y; + vertices[usage++] = (c-char_offset)*char_width; + vertices[usage++] = 0; + + vertices[usage++] = x+delta_x; + vertices[usage++] = y+delta_y; + vertices[usage++] = (c-char_offset+1)*char_width; + vertices[usage++] = char_height; + + vertices[usage++] = x; + vertices[usage++] = y+delta_y; + vertices[usage++] = (c-char_offset)*char_width; + vertices[usage++] = char_height; + + x += delta_x + border_x; } + glUnmapBuffer(GL_ARRAY_BUFFER); + + // no printable char, so also nothing to do + if(!usage) return; - // ???? - if (t != text) - { - *t = 0; - printString(temp, x, y, z); - } + glEnable(GL_BLEND); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_RECTANGLE, texture); + glEnable(GL_TEXTURE_RECTANGLE); + glDrawArrays(GL_TRIANGLES, 0, usage/4); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.h b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.h index 3ebc684dd0..e1cd8b87b9 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.h @@ -23,20 +23,13 @@ public: RasterFont(); ~RasterFont(void); static int debug; - - // some useful constants - enum {char_width = 10}; - enum {char_height = 15}; - - // and the happy helper functions - void printString(const char *s, double x, double y, double z=0.0); - void printCenteredString(const char *s, double y, int screen_width, double z=0.0); - void printMultilineText(const char *text, double x, double y, double z, int bbWidth, int bbHeight); + void printMultilineText(const char *text, double x, double y, double z, int bbWidth, int bbHeight, u32 color); private: - int fontOffset; - char *temp_buffer; - enum {TEMP_BUFFER_SIZE = 64 * 1024}; + + u32 VBO; + u32 VAO; + u32 texture; }; #endif // _RASTERFONT_H_ diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index d19cdfd41e..b1191e383c 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -722,14 +722,11 @@ void Renderer::RenderText(const char *text, int left, int top, u32 color) { const int nBackbufferWidth = (int)OpenGL_GetBackbufferWidth(); const int nBackbufferHeight = (int)OpenGL_GetBackbufferHeight(); - - glColor4f(((color>>16) & 0xff)/255.0f, ((color>> 8) & 0xff)/255.0f, - ((color>> 0) & 0xff)/255.0f, ((color>>24) & 0xFF)/255.0f); - + s_pfont->printMultilineText(text, left * 2.0f / (float)nBackbufferWidth - 1, 1 - top * 2.0f / (float)nBackbufferHeight, - 0, nBackbufferWidth, nBackbufferHeight); + 0, nBackbufferWidth, nBackbufferHeight, color); GL_REPORT_ERRORD(); } diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp index 3923ed0840..0fefa16a93 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp @@ -101,12 +101,11 @@ void SWRenderer::RenderText(const char* pstr, int left, int top, u32 color) { int nBackbufferWidth = (int)OpenGL_GetBackbufferWidth(); int nBackbufferHeight = (int)OpenGL_GetBackbufferHeight(); - glColor4f(((color>>16) & 0xff)/255.0f, ((color>> 8) & 0xff)/255.0f, - ((color>> 0) & 0xff)/255.0f, ((color>>24) & 0xFF)/255.0f); + s_pfont->printMultilineText(pstr, left * 2.0f / (float)nBackbufferWidth - 1, 1 - top * 2.0f / (float)nBackbufferHeight, - 0, nBackbufferWidth, nBackbufferHeight); + 0, nBackbufferWidth, nBackbufferHeight, color); } void SWRenderer::DrawDebugText()