Game Development Reference
In-Depth Information
17. Now, draw to our target bitmap, converting the position:
draw_bitmap( &slot->bitmap,
(pen.x/64)+slot->bitmap_left,
EIGHT-(pen.y / 64) - slot->bitmap_top );
}
18. Save the generated font texture as a rectangular .bmp image ile:
write_bmp( “font.bmp”, WIDTH, HEIGHT, 32,
(unsigned char*)image );
19. Clear the font face and release resources allocated by the library:
FT_Done_Face(face);
FT_Done_FreeType(library);
return 0;
}
20. Now, we have an ASCII string written in a left-to-right language, and we want to build
a graphical representation of this string. We iterate string characters to render them
one by one. At the end of each iteration, we copy the bitmap of the current character
to the frame buffer, and then increment the current position using the ixed font width
(the SLOT_SIZE value).
21. Here is the complete code to render a text string using the pre-rendered bitmap font.
We use font array to store the RGB bitmap of our font:
unsigned char* font;
22. The width and height of the output frame buffer is deined as follows:
int w = 1000;
int h = 1000;
int fw, fh;
int char_w, char_h;
23. Render a single character into the bitmap buffer:
void render_char(unsigned char* buf, char ch,
int x, int y, int col)
{
int u = (ch % 16) * char_w;
int v = char_h / 2 + ((((int)ch) >> 4) - 1) * char_h;
24. Iterate through the pixels of the current character:
for (int y1 = v ; y1 < v + char_h ; y1++ )
for (int x1 = u ; x1 <= u + char_w ; x1++ )
{
int m_col = get_pixel(font, fw, fh, x1, y1);
 
Search WWH ::




Custom Search