My first question ever, so I’ll try to be as descriptive as possible.
I have a TFT display that I have connected to an embedded processor’s bus (64kb RAM, no OS obviously). I wrote a C++ class to set pixels on the display. My goal is to print letters. Each pixel of the letter only needs to be described by 1 bit: on or off. I imagined making a header file of the following format:
#ifndef ABC_H
#define ABC_H
namespace ABC{
const unsigned int a[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
}
#endif
The character above, which I have called “ABC::a”, represents a thin white box with a black box on top and bottom. I have a program that turns bmp files into a header file above. The array is 32 ints long, and each int is 32 bits (I will probably use uint32_t in the final draft, so don’t worry!). This effectively means that I’ve described one ASCII character as a 32×32 bmp. To print it at a specified (X,Y) coordinate, I would just need to do this:
void PrintChar(const int* c,X,Y){
for(unsigned int y=0; y<32; y++)
for(unsigned int x=0; x<32; x++)
if(c[y] & 1<<x)
SetPixel(x+X,y+Y); //SetPixel(x,y) lights up a pixel at coordinates (x,y) on the display
}
Question: What would be a good way to generate 32×32 bmps of ASCII characters, preferably not tediously by hand with paint.exe. Alternatively once, does someone have a better means to the end that I want (like skipping the middleman program somehow)? Alternatively twice, am I just being dumb and there’s a much better way to describe ASCII characters for my purposes?
Note: I realize using C++ for an embedded processor is a questionable practice (at least I think so) but that’s what I was instructed to do. /shrug
edit: Ignore the compression part! I’ll handle that on my own (unless you really want to share some ideas, then fire away!).
You can use any graphics library to draw characters to a buffer, and then construct your character data from the buffer.
On Windows, the most obvious way would be to use GDI+ and ClearType, or you could take a look at Cairo. If you want full control over character rendering, I suggest using Freetype.
Once you have a buffer containing the character, you might need to test individual pixesl whether they should be black or white (because graphics libraries might apply anti-alias). Alternatively, depending on how you draw the text and which font you use, it might not use anti-alias at all.