Subscribe to the RSS Feed Add to Google

Debug Text Render

January 4, 2010

The result of the DebugFont renderer.

When working on games, I often find it useful to be able to quickly and easily display text strings on the screen for debugging purposes. A long time ago I wrote a simple little piece of code which could draw text onto a bitmap, and without having a dependency on anything else - it doesn't use any other classes, functions or libraries, and it doesn't need any external data - the font bitmaps are included in the source file, as a static array. This system, in all its simplicity, have turned out to be very, very useful, and I've used it for most of my stuff for the last 10 years or so.

I recently spent a little time cleaning it up a little, and thought I'd release it to anyone who's interested. As usual, it's public domain, so use it in any way you like.

You can download the DebugFont source code here.

To draw text on any bitmap, you simple include "DebugFont.h", and do something like this:

DebugFont font;
font.Blit(pixelDataPtr,w,h,20,30,"My text"); // 20,30 is the x,y position of the text

Where pixelDataPtr is a pointer to the pixel data of the bitmap we want to draw onto, and w and h are the width and height (in pixels) of that pixel data area. The pixel data of the bitmap to draw on, can be 8-, 16- or 32-bit data.

As I finish the refactoring of more parts of my Pixie game engine, I'll try and post more of these little useful, stand-alone code snippets which can just be dropped into any project - let me know if you find any of them useful :-)


   Digg this Digg this    submit to reddit Add to reddit

<< New Characters for Jade Figurines
Dungeon Master-style game >>


Comments

Aaron
2010-02-04 20:58:38
This is awesome.
Aaron
2010-02-04 21:27:16
FYI - I had to change line 50 from "char c" to "unsigned char c" to eliminate several warnings.

Write a comment








Video Games BlogRankers.com Video Games blogs Directory of Video Games Blogs Blog directory Game Blogs - BlogCatalog Blog Directory Free Page Rank Tool Bloggtoppen.se Blogg om Bloggar.Topplista.se - topplistan med de bästa bloggarna - lägg till din blogg du också! My Zimbio DigNow.net

© Copyright Mattias Gustavsson 2008. All Rights Reserved. Reproduction/republishing of any material on this site without permission is strictly prohibited.