views:

359

answers:

6

Hi, I need to do some rudimentary text rendering to a pixel buffer, and I think that having a table indexed by char with the representation of the letters as a binary array would be more than enough... Anybody knows about a free header as such?

Example:

char data[256][8][8];
void init()
{
  data['a'] = {
    {0,0,1,1,1,0,0,0},
    {0,1,0,0,0,1,0,0},
    {0,0,0,0,0,0,1,0},
    {0,0,1,1,1,0,1,0},
    {0,1,0,0,0,1,1,0},
    {0,1,0,0,0,0,1,0},
    {0,1,0,0,0,1,1,0},
    {0,0,1,1,1,0,1,0},
  };
}

I could go on with the rest of the alphabet, but then I wouldn't need to ask... ¡But that gives me an idea! if there's no free header with a bitmapped font readily available, each answer could implement a letter and I could assemble the whole file here ^_^

A: 

I know it doesn't answer your question but I would recommend just using something like http://www.angelcode.com/products/bmfont/ to generate a simple bitmap font. Loading a tga file is pretty simple. I wouldn't expect a crowdsourced font to look very nice.

Dolphin
I don't need it to look nice, it's for a quick n' dirty image tagging :-)
fortran
+1  A: 

I know you can save images as a c header file in gimp. Maybe you can find a tool which does the job on the command line. So you could automate the creation. ImageMagick can at least load ttf fonts.

EDIT: Gimp does only support RGB data as output format, so it's not a solution for you.

Anyway here is an 'b' for you:


/* GIMP RGB C-Source image dump (b.c) */

static const struct {
  unsigned int   width;
  unsigned int   height;
  unsigned int   bytes_per_pixel; /* 3:RGB, 4:RGBA */ 
  char          *comment;
  unsigned char  pixel_data[8 * 8 * 3 + 1];
} gimp_image = {
  8, 8, 3,
  "Created with GIMP",
  "\377\377\377\377\377\377\0\0\0\377\377\377\377\377\377\377\377\377\377\377"
  "\377\377\377\377\377\377\377\377\377\377\0\0\0\377\377\377\377\377\377\377"
  "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377\377\377"
  "\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0"
  "\0\0\0\377\377\377\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377"
  "\0\0\0\377\377\377\377\377\377\377\377\377\0\0\0\377\377\377\377\377\377"
  "\377\377\377\0\0\0\377\377\377\377\377\377\377\377\377\0\0\0\377\377\377"
  "\377\377\377\377\377\377\0\0\0\377\377\377\377\377\377\0\0\0\377\377\377"
  "\377\377\377\377\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377"
  "\377\377\377",
};
quinmars
Craig McQueen
A: 

To convert arbitrary files into C headers, there are several options available. Take a look at Python's bin2c.py for basic example.

Lua has a similar tool called "Bin2Cee".

geekscrap
"BinToCee" is only the name of the wiki page for bin2c (bin2c.lua).
Mark Edgar
+4  A: 

Update: I tried this approach and the characters come out fairly distorted. Possibly Nimbus is a poor font choice.

Go with the imagemagick approach. You can generate each character with this:

convert -resize 7x13\! -font Nimbus-Mono-Regular -pointsize 10 label:A A.xbm

A.xbm looks like:

#define A_width 7
#define A_height 13
static char A_bits[] = {
  0x00, 0x00, 0x00, 0x00, 0x1C, 0x08, 0x00, 0x3C, 0x00, 0x66, 0x00, 0x00,
  0x00, };

Loop through the characters you need and assemble this into a single header file.

You need the -resize 7x13! argument because even though we've selected a monospace font, the sometimes the generated widths are off by a pixel.

+1  A: 

"Pixel fonts" may be a good resource: http://www.alvit.de/blog/article/25-best-license-free-pixelfonts

A: 

Its a bit late, but have a look here.

Christoph