summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/OGL/RasterFont.cpp
diff options
context:
space:
mode:
authorPierre Bourdon <delroth@gmail.com>2014-03-15 00:57:56 +0100
committerPierre Bourdon <delroth@gmail.com>2014-03-15 00:57:56 +0100
commit8d679e76d299956a1521bc14502466be8d8b2df8 (patch)
tree97db9ad6a45a8e5d711d7763199579e400a65bc8 /Source/Core/VideoBackends/OGL/RasterFont.cpp
parent12c2e345a35a571aadc842e30c38b3b4d8f70dce (diff)
parenta82675b7d581421fa80d5d5c53253cf1d5c1a26d (diff)
Merge pull request #164 from lioncash/cstr-cull
Kill off some usages of c_str.
Diffstat (limited to 'Source/Core/VideoBackends/OGL/RasterFont.cpp')
-rw-r--r--Source/Core/VideoBackends/OGL/RasterFont.cpp34
1 files changed, 20 insertions, 14 deletions
diff --git a/Source/Core/VideoBackends/OGL/RasterFont.cpp b/Source/Core/VideoBackends/OGL/RasterFont.cpp
index 55b6f280b3..eb288d9414 100644
--- a/Source/Core/VideoBackends/OGL/RasterFont.cpp
+++ b/Source/Core/VideoBackends/OGL/RasterFont.cpp
@@ -141,9 +141,12 @@ RasterFont::RasterFont()
glActiveTexture(GL_TEXTURE0+8);
glBindTexture(GL_TEXTURE_2D, texture);
u32* texture_data = new u32[char_width*char_count*char_height];
- for (u32 y=0; y<char_height; y++) {
- for (u32 c=0; c<char_count; c++) {
- for (u32 x=0; x<char_width; x++) {
+ for (u32 y = 0; y < char_height; y++)
+ {
+ for (u32 c = 0; c < char_count; c++)
+ {
+ for (u32 x = 0; x < char_width; x++)
+ {
bool pixel = (0 != (rasters[c][y] & (1<<(char_width-x-1))));
texture_data[char_width*char_count*y+char_width*c+x] = pixel ? -1 : 0;
}
@@ -181,10 +184,9 @@ RasterFont::~RasterFont()
s_shader.Destroy();
}
-void RasterFont::printMultilineText(const char *text, double start_x, double start_y, double z, int bbWidth, int bbHeight, u32 color)
+void RasterFont::printMultilineText(const std::string& text, double start_x, double start_y, double z, int bbWidth, int bbHeight, u32 color)
{
- size_t length = strlen(text);
- GLfloat *vertices = new GLfloat[length*6*4];
+ GLfloat* vertices = new GLfloat[text.length() * 6 * 4];
int usage = 0;
GLfloat delta_x = GLfloat(2*char_width)/GLfloat(bbWidth);
@@ -195,22 +197,24 @@ void RasterFont::printMultilineText(const char *text, double start_x, double sta
GLfloat x = GLfloat(start_x);
GLfloat y = GLfloat(start_y);
- for (size_t i=0; i<length; i++) {
- u8 c = text[i];
-
- if (c == '\n') {
+ for (const char& c : text)
+ {
+ if (c == '\n')
+ {
x = GLfloat(start_x);
y -= delta_y + border_y;
continue;
}
// do not print spaces, they can be skipped easily
- if (c == ' ') {
+ if (c == ' ')
+ {
x += delta_x + border_x;
continue;
}
- if (c < char_offset || c >= char_count+char_offset) continue;
+ if (c < char_offset || c >= char_count+char_offset)
+ continue;
vertices[usage++] = x;
vertices[usage++] = y;
@@ -245,7 +249,8 @@ void RasterFont::printMultilineText(const char *text, double start_x, double sta
x += delta_x + border_x;
}
- if (!usage) {
+ if (!usage)
+ {
delete [] vertices;
return;
}
@@ -258,7 +263,8 @@ void RasterFont::printMultilineText(const char *text, double start_x, double sta
s_shader.Bind();
- if (color != cached_color) {
+ if (color != cached_color)
+ {
glUniform4f(uniform_color_id, GLfloat((color>>16)&0xff)/255.f,GLfloat((color>>8)&0xff)/255.f,GLfloat((color>>0)&0xff)/255.f,GLfloat((color>>24)&0xff)/255.f);
cached_color = color;
}