Skip to main content
gamedev.net
🔒 Locked

Custom bitmap font loader

Started by CC Ricers Jul 14, 2004 at 10:08 PM 0 replies 650+ views
Original Post
CC Ricers
CC Ricers
I want to make a simple bitmap font loader that takes in characters of uniform width. I'd figure that I would set up an array to match the correct character of a string to the x position of the bitmap, and it will begin drawing the surface at that point. Unfortunately, I don't know how to split up char variables into their individual characters and call up a bitmap letter to represent that character. I could probably figure out how to set the x and y values for the string on my own; I'll be using SDL for this. I just need help actually taking apart the strings and setting them up. Take this code for example: void drawString(SDL_Surface *screen, int x, int y, char *str, ...) Something akin to cone3D's tutorial, but without needing the RAW and INI files. Also if you can, tell me how I can display int and float variable values on the text.
Geocyte
Geocyte

here's some psuedocode adapted from
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=13

void print(const char *format_text, ...)
{
char text[256];
va_list ap; // Pointer To List Of Arguments

if (format_text == NULL) return;
va_start(ap, format_text);
vsprintf(text, format_text, ap);
va_end(ap);
for (int i = 0; text != NULL; i++)
{
draw_character(text);
}
}

draw_character should be a function which will draw an image of the character passed to it at the current raster position and then advance the raster position.

The for loop assumes that the string is NULL terminated. It probably will be, but I don't really know.

This c-style way of doing things is not my cup of tea... I use std::string instead of char* and std::stringstream instead of vsprintf()... if I were you I'd look into using the Standard Template Library but that's a whole other barrel of monkeys.

STL tutorials are all over the net and are found with ease.
http://www.cs.brown.edu/people/jak/proglang/cpp/stltut/tut.html
That one ^ has some pretty diagrams.

More details about vsprintf can be found on msdn.
Geocyte Has Committed Suicide.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.