Bitmap font glyph offset and x axis?
I have a bitmapfont, created with the angel'scode bitmap generator. I have
a png with the texture and a .fnt with the information of the font
(texture coordinates, char width and height, offsets, advance, etc...).
That information is stored inside a struct called 'glyph'
I am rendering those glyphs with this code:
float x_cursor = 0.0f;
// Record each char of my string
for(int i=0; i < [mystring length];i++)
{
// Get the char id
int mychar = (int)[mystring characterAtIndex:i];
// Get the glyph information of the char to render
GlyphChar glyph;
if([GlpyhCharBuffer count] < (mychar-first_char)+1)
continue;
NSValue * valuegly = [GlpyhCharBuffer objectAtIndex:(mychar-first_char)];
if(valuegly == nil)
{
continue;
}
[valuegly getValue:&glyph];
// Start with the OpenGL Drawing
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
// Where to draw our char
float y_offsetpos = screen_point[1] + TOGLUNIT(glyph.y_offset) * -1.0f;
float x_glyphpos = screen_point[0] +
TOGLUNIT(x_cursor+(float)glyph.x_offset);
GLKMatrix4 model_modifier = GLKMatrix4MakeTranslation(x_glyphpos,
y_offsetpos, 0.0f);
float glyph_width = TOGLUNIT((float)glyph.char_width);
float glyph_height = TOGLUNIT((float)glyph.char_height);
// Move the cursor in the x axis for the following char
x_cursor += (float)glyph.x_advance;
// Create our model matrix, for scale and translate our char
GLKMatrix4 model_modifier = GLKMatrix4MakeTranslation(x_glyphpos,
y_offsetpos, 0.0f);
model_modifier = GLKMatrix4Scale(model_modifier, glyph_width,
glyph_height,0.0f);
GLuint uniform_dir = glGetUniformLocation(program, "model_matrix");
glUniformMatrix4fv(uniform_dir, 1, GL_FALSE, model_modifier.m);
glBindBuffer(GL_ARRAY_BUFFER, square_buff);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glBindBuffer(GL_ARRAY_BUFFER, glyph.uvscoord);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
glBindTexture(tex_information.target, tex_information.name);
glDrawArrays(GL_TRIANGLES, 0, 6);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(0);
}
the X Axis is not working good, it gives a bad result:
I already tried with a lot of fonts, generated by the angel'scode and
stills giving the same error. How the X Aligning on a bitmap font works?
No comments:
Post a Comment