“Marc A. Lepage” wrote:
Joe Knapka wrote:
“Marc A. Lepage” wrote:
Joe Knapka wrote:
Hi, everyone,
Correct me if I’m wrong, but there doesn’t seem to be a
standard way to write text to an SDL_Surface. Is this
true?
I expect people are transparent-blitting bitmap font images.
OK, this implies that everyone is inventing their own ad-hoc
fonts and schemes for mapping ASCII or Unicode to character
bitmaps, true? Or is there a standard bitmapped font format
that makes this trivial to do?
ASCII, ISO 8859-1, and UNICODE are fixed standards.
If I understand you, you mean how the characters are layed out in the
image?
Right. I mean, seems to me you’d like to be able to so something like:
SDL_Surface* font_bitmap = LoadImage(blah blah blah);
SDL_Surface* rendered_text = DrawText(“Hello, world”,font_bitmap);
and then rendered_text will be a surface containing the text, with
transparent background, which you can blit onto your screen. The
question is, how does DrawText() extract the individual character
bitmaps from the font bitmap? Seems like it would be highly desirable
to build a library that allowed a font bitmap to be described in a
standard way so that this would be easy to do.
What I am contemplating is a library that would take a font
bitmap and some XML like:
<FONT_DESCRIPTION bmapfile=“myfont.bmp”>
…
…
and do the rendering task, supplying SDL_Surfaces that could be
blitted wherever you want. Additionally, I was going to optionally
allow the character bitmaps to be embedded in the XML as text,
rather than requiring a separate bitmap file:
-----
–**-
-–
-****
-–
-–
In this case, the entire font could just be encoded in the
executable as a string, parsed and rendered during app initialization,
and used. (Incidentally, I know the font sizes in my examples
are really teeny tiny; it’s just an example. The library could
do scaling as well, though it’s not yet obvious to me how to do it
in a nice way.)
Does this look like a useful thing?
– Joe Knapka
I am using lines of 32 characters in my images. This makes the images
easier to deal with (size-wise) than one single long line. Calculations
are still easy (divide by 32 for character width, divide by number of
lines for character height).
It seems to align naturally with the ASCII set itself (consider upper
and lower case letters). And, it has the advantage that you can see line
spacing directly in your image.
–
Marc A. Lepage
http://www.antimeta.com/
Minion open source game, RTS game programming, etc.