YS Bitmap-Font Library Reference

Revision:

2010/12/11 First version of the reference

 

License

This library (including font data) is copyrighted to CaptainYS.  But, this library is open source.  When I say open source, I mean it.  You can use it for any purposes, commercial, private, internal, open source, or proprietary as long as you take responsibility for the consequence.  (If you use it for an illegal purpose, the police will come to you!  Whatcha gonna do when they come to you?  So, don't use it for an illegal purpose.)  You can cut & paste some part of the code and use in your program.  If you want to reverse-engineer, sure, go ahead!  That's the way you learn programming.  Only condition is you are responsible, and I will NOT take any responsibility for the consequence of using this library.  If you do not agree with this condition, please do not use this library.  Of course, I will be happy if you let me know about your interesting projects with this library.

Contact

Web site    http://www.ysflight.com

E-Mail    PEB01130[A]nifty.com   (Please replace [A] with @)

Abstract

This library gives you functions for drawing ASCII text on the OpenGL window.  There are two sets of functions, one is for making bitmap-font display list (just like wglUseFontBitmap and glxUseFont) and the other for directly drawing fonts without using display list.  Of course, the former is faster, but it contaminates display-list name space.  The latter is slow, but as long as you don't draw too many characters, it may be good enough.

There are also functions that makes up a bitmap from a text string so that you can use as texture, which hasn't been extensively tested, but I think it works.  Let me know if you find bugs.

Only one weakness of OpenGL is lack of the text-drawing function.  I'm not talking about a fancy decorated stylish font.  I need ugliest tiniest simplest fixed-pitch ASCII character font that is readable.  If you go with wglUseFontBitmap or glxUseFont, you suddenly lose portability.  The font differs slightly from platform to platform.  This library gives you a simple portable solution.  (Simple is good, isnt' it?)

Header file

ysglfontdata.h

This header file must be included to use this library.  The include path must be added to the location where this file is stored, or this file needs to be copied to the location where the include path is pointing.

Source files

The following source files need to be added in the project.

ysglfontdata.c

ysglmaketextbitmap.c

ysglusefontbitmap.c

Available fonts

As of 2010/12/10, this library has following set of fonts:

6x7, 6x8, 6x10, 7x10, 8x8, 8x12, 12x16, 16x20, 16x24, 20x28, 20x32

Functions

void YsGlDrawFontBitmap6x7(const char str[]);
void YsGlDrawFontBitmap6x8(const char str[]);
void YsGlDrawFontBitmap6x10(const char str[]);
void YsGlDrawFontBitmap7x10(const char str[]);
void YsGlDrawFontBitmap8x8(const char str[]);
void YsGlDrawFontBitmap8x12(const char str[]);
void YsGlDrawFontBitmap12x16(const char str[]);
void YsGlDrawFontBitmap16x20(const char str[]);
void YsGlDrawFontBitmap16x24(const char str[]);
void YsGlDrawFontBitmap20x28(const char str[]);
void YsGlDrawFontBitmap20x32(const char str[]);

These functions draws a text string given by str.  The lower bottom of the string should be specified by glRasterPos function.

 

void YsGlUseFontBitmap6x7(int listBase);
void YsGlUseFontBitmap6x8(int listBase);
void YsGlUseFontBitmap6x10(int listBase);
void YsGlUseFontBitmap7x10(int listBase);
void YsGlUseFontBitmap8x8(int listBase);
void YsGlUseFontBitmap8x12(int listBase);
void YsGlUseFontBitmap12x16(int listBase);
void YsGlUseFontBitmap16x20(int listBase);
void YsGlUseFontBitmap16x24(int listBase);
void YsGlUseFontBitmap20x28(int listBase);
void YsGlUseFontBitmap20x32(int listBase);

These functions makes display lists for the ASCII character drawing.  It works just like wglUseFontBitmap and glxUseFont.  The application must make sure at least 128 display lists are available starting from listBase.  The best way of making sure the availability of the display list is to use glGenLists function.

 

int YsGlWriteStringToSingleBitBitmap(
    const char str[],
    unsigned char bmpPtr[],unsigned int bmpWid,unsigned int bmpHei,
    int bottomLeftX,int bottomLeftY,
    unsigned char const *fontPtr[],int fontWid,int fontHei);

This function makes a monochrome bitmap that can be given to glBitmap function or be used as a texture of a text string given by str.

The bitmap will be stored in bmpPtr.  The size of the bitmap is bmpWid and bmpHei,  If the image of text string does not fit within the size of the given bitmap, the image will be trimmed to fit within the given bitmap.  Parameters bottomLeftX and bottomLeftY specify the lower left corner of the first letter within the bitmap.

One of the following pointers (defined in ysglfontdata.h) can be given as fontPtr, and fontWid and fontHei must match the pointer you specify in fontPtr.

extern unsigned char *YsFont6x7[];
extern unsigned char *YsFont6x8[];
extern unsigned char *YsFont6x10[];
extern unsigned char *YsFont7x10[];
extern unsigned char *YsFont8x8[];
extern unsigned char *YsFont8x12[];
extern unsigned char *YsFont12x16[];
extern unsigned char *YsFont16x20[];
extern unsigned char *YsFont16x24[];
extern unsigned char *YsFont20x28[];
extern unsigned char *YsFont20x32[];

 

int YsGlWriteStringToRGBA8Bitmap(
    const char str[],
    unsigned int c0,unsigned int c1,unsigned int c2,unsigned int c3,
    unsigned char bmpPtr[],unsigned int bmpWid,unsigned int bmpHei,
    int bottomLeftX,int bottomLeftY,
    unsigned char const *fontPtr[],int fontWid,int fontHei);

This function makes a color bitmap that can be given to glDrawPixels function or be used as a texture of a text string given by str.  The color is given by c0, c1, c2, and c3, which corresponds to R, G, B, and A respectively.

The bitmap will be stored in bmpPtr.  The size of the bitmap is bmpWid and bmpHei,  If the image of text string does not fit within the size of the given bitmap, the image will be trimmed to fit within the given bitmap.  Parameters bottomLeftX and bottomLeftY specify the lower left corner of the first letter within the bitmap.

One of the following pointers (defined in ysglfontdata.h) can be given as fontPtr, and fontWid and fontHei must match the pointer you specify in fontPtr.

extern unsigned char *YsFont6x7[];
extern unsigned char *YsFont6x8[];
extern unsigned char *YsFont6x10[];
extern unsigned char *YsFont7x10[];
extern unsigned char *YsFont8x8[];
extern unsigned char *YsFont8x12[];
extern unsigned char *YsFont12x16[];
extern unsigned char *YsFont16x20[];
extern unsigned char *YsFont16x24[];
extern unsigned char *YsFont20x28[];
extern unsigned char *YsFont20x32[];