972
edits
[unchecked revision] | [unchecked revision] |
m (Bot: Replace deprecated source tag with syntaxhighlight) |
m (Bot: Replace deprecated source tag with syntaxhighlight) |
||
Line 112:
And finally we came to the point where we can display a character. I'll assume you have a putpixel procedure ready.
We have to draw 8x16 pixels, one for every bit in the bitmap.
<
//this is the bitmap font you've loaded
unsigned char *font;
Line 128:
}
}
</syntaxhighlight>
The arguments are straightforward. You may wonder why to subtract 12 from y. It's for the baseline: you specify y coordinate as the bottom of the character, not counting the "piggy tail" in a glyph that goes down (like in "p","g","q" etc.). I other words it's the most bottom row of letter "A" that has a bit set.
Although it's mostly useful to erase the screen under the glyph, in some cases it could be bad (eg.: writing on a shiny gradiented button). So here's a slightly modificated version, that uses a transparent background.
<
//this is the bitmap font you've loaded
unsigned char *font;
Line 148:
}
}
</syntaxhighlight>
As you can see, we have only foreground color this time, and the putpixel call has a condition: only invoked if the according bit in the bitmap is set.
Of course the code above will be excruciatingly slow (mostly due to doing one pixel at a time, and repeatedly recalculating the address for each pixel within the "putpixel()" function). For much better performance, the code above can be optimised to use boolean operations and a "mask lookup table" instead. For example (for an 8-bpp mode):
<
//this is the bitmap font you've loaded
unsigned char *font;
Line 207:
}
}
</syntaxhighlight>
In this case the address in display memory is only calculated once (rather than up to 128 times) and 8 pixels are done in parallel (which removes the inner loop completely).
|