Merge pull request #962 from lioncash/casing

OGL: Fix constant casing in RasterFont.
This commit is contained in:
shuffle2 2014-09-03 21:03:29 -07:00
commit 329410074c
1 changed files with 30 additions and 30 deletions

View File

@ -11,12 +11,12 @@
namespace OGL namespace OGL
{ {
static const int char_width = 8; static const int CHAR_WIDTH = 8;
static const int char_height = 13; static const int CHAR_HEIGHT = 13;
static const int char_offset = 32; static const int CHAR_OFFSET = 32;
static const int char_count = 95; static const int CHAR_COUNT = 95;
const u8 rasters[char_count][char_height] = { static const u8 rasters[CHAR_COUNT][CHAR_HEIGHT] = {
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {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, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36},
@ -141,20 +141,20 @@ RasterFont::RasterFont()
glGenTextures(1, &texture); glGenTextures(1, &texture);
glActiveTexture(GL_TEXTURE0+8); glActiveTexture(GL_TEXTURE0+8);
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
u32* texture_data = new u32[char_width*char_count*char_height]; u32* texture_data = new u32[CHAR_WIDTH * CHAR_COUNT * CHAR_HEIGHT];
for (int y = 0; y < char_height; y++) for (int y = 0; y < CHAR_HEIGHT; y++)
{ {
for (int c = 0; c < char_count; c++) for (int c = 0; c < CHAR_COUNT; c++)
{ {
for (int x = 0; x < char_width; x++) for (int x = 0; x < CHAR_WIDTH; x++)
{ {
bool pixel = (0 != (rasters[c][y] & (1<<(char_width-x-1)))); 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; texture_data[CHAR_WIDTH * CHAR_COUNT * y + CHAR_WIDTH * c + x] = pixel ? -1 : 0;
} }
} }
} }
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, char_width*char_count, char_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture_data); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, CHAR_WIDTH * CHAR_COUNT, CHAR_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture_data);
delete [] texture_data; delete [] texture_data;
// generate shader // generate shader
@ -162,7 +162,7 @@ RasterFont::RasterFont()
s_shader.Bind(); s_shader.Bind();
// bound uniforms // bound uniforms
glUniform2f(glGetUniformLocation(s_shader.glprogid,"charSize"), 1.0f / GLfloat(char_count), 1.0f); glUniform2f(glGetUniformLocation(s_shader.glprogid,"charSize"), 1.0f / GLfloat(CHAR_COUNT), 1.0f);
uniform_color_id = glGetUniformLocation(s_shader.glprogid,"color"); uniform_color_id = glGetUniformLocation(s_shader.glprogid,"color");
glUniform4f(uniform_color_id, 1.0f, 1.0f, 1.0f, 1.0f); glUniform4f(uniform_color_id, 1.0f, 1.0f, 1.0f, 1.0f);
cached_color = -1; cached_color = -1;
@ -191,10 +191,10 @@ void RasterFont::printMultilineText(const std::string& text, double start_x, dou
GLfloat* vertices = new GLfloat[text.length() * 6 * 4]; GLfloat* vertices = new GLfloat[text.length() * 6 * 4];
int usage = 0; int usage = 0;
GLfloat delta_x = GLfloat(2*char_width)/GLfloat(bbWidth); GLfloat delta_x = GLfloat(2 * CHAR_WIDTH) / GLfloat(bbWidth);
GLfloat delta_y = GLfloat(2*char_height)/GLfloat(bbHeight); GLfloat delta_y = GLfloat(2 * CHAR_HEIGHT) / GLfloat(bbHeight);
GLfloat border_x = 2.0f/GLfloat(bbWidth); GLfloat border_x = 2.0f / GLfloat(bbWidth);
GLfloat border_y = 4.0f/GLfloat(bbHeight); GLfloat border_y = 4.0f / GLfloat(bbHeight);
GLfloat x = GLfloat(start_x); GLfloat x = GLfloat(start_x);
GLfloat y = GLfloat(start_y); GLfloat y = GLfloat(start_y);
@ -215,37 +215,37 @@ void RasterFont::printMultilineText(const std::string& text, double start_x, dou
continue; continue;
} }
if ((u32) c < char_offset || (u32) c >= char_count+char_offset) if ((u32) c < CHAR_OFFSET || (u32) c >= CHAR_COUNT + CHAR_OFFSET)
continue; continue;
vertices[usage++] = x; vertices[usage++] = x;
vertices[usage++] = y; vertices[usage++] = y;
vertices[usage++] = GLfloat(c-char_offset); vertices[usage++] = GLfloat(c - CHAR_OFFSET);
vertices[usage++] = 0.0f; vertices[usage++] = 0.0f;
vertices[usage++] = x+delta_x; vertices[usage++] = x + delta_x;
vertices[usage++] = y; vertices[usage++] = y;
vertices[usage++] = GLfloat(c-char_offset+1); vertices[usage++] = GLfloat(c - CHAR_OFFSET + 1);
vertices[usage++] = 0.0f; vertices[usage++] = 0.0f;
vertices[usage++] = x+delta_x; vertices[usage++] = x + delta_x;
vertices[usage++] = y+delta_y; vertices[usage++] = y + delta_y;
vertices[usage++] = GLfloat(c-char_offset+1); vertices[usage++] = GLfloat(c - CHAR_OFFSET + 1);
vertices[usage++] = 1.0f; vertices[usage++] = 1.0f;
vertices[usage++] = x; vertices[usage++] = x;
vertices[usage++] = y; vertices[usage++] = y;
vertices[usage++] = GLfloat(c-char_offset); vertices[usage++] = GLfloat(c - CHAR_OFFSET);
vertices[usage++] = 0.0f; vertices[usage++] = 0.0f;
vertices[usage++] = x+delta_x; vertices[usage++] = x + delta_x;
vertices[usage++] = y+delta_y; vertices[usage++] = y + delta_y;
vertices[usage++] = GLfloat(c-char_offset+1); vertices[usage++] = GLfloat(c - CHAR_OFFSET + 1);
vertices[usage++] = 1.0f; vertices[usage++] = 1.0f;
vertices[usage++] = x; vertices[usage++] = x;
vertices[usage++] = y+delta_y; vertices[usage++] = y + delta_y;
vertices[usage++] = GLfloat(c-char_offset); vertices[usage++] = GLfloat(c - CHAR_OFFSET);
vertices[usage++] = 1.0f; vertices[usage++] = 1.0f;
x += delta_x + border_x; x += delta_x + border_x;