Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OGL: Fix constant casing in RasterFont. #962

Merged
merged 2 commits into from Sep 4, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 30 additions & 30 deletions Source/Core/VideoBackends/OGL/RasterFont.cpp
Expand Up @@ -11,12 +11,12 @@
namespace OGL
{

static const int char_width = 8;
static const int char_height = 13;
static const int char_offset = 32;
static const int char_count = 95;
static const int CHAR_WIDTH = 8;
static const int CHAR_HEIGHT = 13;
static const int CHAR_OFFSET = 32;
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, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36},
Expand Down Expand Up @@ -141,28 +141,28 @@ RasterFont::RasterFont()
glGenTextures(1, &texture);
glActiveTexture(GL_TEXTURE0+8);
glBindTexture(GL_TEXTURE_2D, texture);
u32* texture_data = new u32[char_width*char_count*char_height];
for (int y = 0; y < char_height; y++)
u32* texture_data = new u32[CHAR_WIDTH * CHAR_COUNT * CHAR_HEIGHT];
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))));
texture_data[char_width*char_count*y+char_width*c+x] = pixel ? -1 : 0;
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;
}
}
}
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;

// generate shader
ProgramShaderCache::CompileShader(s_shader, s_vertexShaderSrc, s_fragmentShaderSrc);
s_shader.Bind();

// 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");
glUniform4f(uniform_color_id, 1.0f, 1.0f, 1.0f, 1.0f);
cached_color = -1;
Expand Down Expand Up @@ -191,10 +191,10 @@ void RasterFont::printMultilineText(const std::string& text, double start_x, dou
GLfloat* vertices = new GLfloat[text.length() * 6 * 4];

int usage = 0;
GLfloat delta_x = GLfloat(2*char_width)/GLfloat(bbWidth);
GLfloat delta_y = GLfloat(2*char_height)/GLfloat(bbHeight);
GLfloat border_x = 2.0f/GLfloat(bbWidth);
GLfloat border_y = 4.0f/GLfloat(bbHeight);
GLfloat delta_x = GLfloat(2 * CHAR_WIDTH) / GLfloat(bbWidth);
GLfloat delta_y = GLfloat(2 * CHAR_HEIGHT) / GLfloat(bbHeight);
GLfloat border_x = 2.0f / GLfloat(bbWidth);
GLfloat border_y = 4.0f / GLfloat(bbHeight);

GLfloat x = GLfloat(start_x);
GLfloat y = GLfloat(start_y);
Expand All @@ -215,37 +215,37 @@ void RasterFont::printMultilineText(const std::string& text, double start_x, dou
continue;
}

if ((u32) c < char_offset || (u32) c >= char_count+char_offset)
if ((u32) c < CHAR_OFFSET || (u32) c >= CHAR_COUNT + CHAR_OFFSET)
continue;

vertices[usage++] = x;
vertices[usage++] = y;
vertices[usage++] = GLfloat(c-char_offset);
vertices[usage++] = GLfloat(c - CHAR_OFFSET);
vertices[usage++] = 0.0f;

vertices[usage++] = x+delta_x;
vertices[usage++] = x + delta_x;
vertices[usage++] = y;
vertices[usage++] = GLfloat(c-char_offset+1);
vertices[usage++] = GLfloat(c - CHAR_OFFSET + 1);
vertices[usage++] = 0.0f;

vertices[usage++] = x+delta_x;
vertices[usage++] = y+delta_y;
vertices[usage++] = GLfloat(c-char_offset+1);
vertices[usage++] = x + delta_x;
vertices[usage++] = y + delta_y;
vertices[usage++] = GLfloat(c - CHAR_OFFSET + 1);
vertices[usage++] = 1.0f;

vertices[usage++] = x;
vertices[usage++] = y;
vertices[usage++] = GLfloat(c-char_offset);
vertices[usage++] = GLfloat(c - CHAR_OFFSET);
vertices[usage++] = 0.0f;

vertices[usage++] = x+delta_x;
vertices[usage++] = y+delta_y;
vertices[usage++] = GLfloat(c-char_offset+1);
vertices[usage++] = x + delta_x;
vertices[usage++] = y + delta_y;
vertices[usage++] = GLfloat(c - CHAR_OFFSET + 1);
vertices[usage++] = 1.0f;

vertices[usage++] = x;
vertices[usage++] = y+delta_y;
vertices[usage++] = GLfloat(c-char_offset);
vertices[usage++] = y + delta_y;
vertices[usage++] = GLfloat(c - CHAR_OFFSET);
vertices[usage++] = 1.0f;

x += delta_x + border_x;
Expand Down