Game Development Reference
In-Depth Information
25. Paint only non-zero pixels. This will preserve the existing content of the frame buffer:
if(m_col != 0)
put_pixel(buf, w, h, x+x1-u, y+y1-v, col);
}
}
26. Render a complete line of ASCII text into the buffer:
void render_text(unsigned char* buf, const char* str,
int x, int y, int col)
{
const char* c = str;
while (*c)
{
render_char(buf, *c, x, y, col);
c++;
27. Advance by a ixed number of pixels:
x += char_w;
}
}
How it works…
Let's read the output of the FreeType font generator. We use the following code to test it:
font = read_bmp( “font.bmp”, &fw, &fh );
char_w = fw / CHAR_SIZE;
char_h = fh / CHAR_SIZE;
Allocate and clear the output 3-channel RGB bitmap:
unsigned char* bmp = (unsigned char* )malloc( w * h * 3 );
memset( bmp, 0, w * h * 3 );
Render the white text line at position (10,10) :
render_text( bmp, “Test string”, 10, 10, 0xFFFFFF );
Save the resulting bitmap to a ile:
write_bmp( “test.bmp”, w, h, bmp );
free( bmp );
 
Search WWH ::




Custom Search