Skip to main content
GameDev.net gamedev.net
🔒 Locked

Bitmap Font engine

Started by Dunge Jan 6, 2001 at 12:01 PM 12 replies 2.4k views
Original Post
Dunge
Dunge
Hi, I made a little PONG game using the Nehe text tutorial and it slow down the game of 100fps! So I wanted to make a bitmap engine. You know like in Half-Life they take this bitmap : and they make all the game text with it (change the color, size, etc). How do they do that? They create a quad by letter and put it at -0.00000000000000001f on the z position? Anyway if someone have a code that I can modifie the bitmap or can help me please answer! Edited by - Dunge on January 6, 2001 1:03:58 PM
MButchers
MButchers
If your only using single colour fonts why dont
you just use wglUseFontBitmaps as this is very fast.
Dunge
Dunge
Humm that would be cool if I can draw my letters and do a command like Font("Mytext",x,y,size,color); and that use the bitmap I draw... What is wglUseFontBitmaps and where can I get info on it? thx...
MButchers
MButchers
Hello there,

heres a bit of code that you may find usefull.

  

//set font to system font

TFont *font = TControl::Font;
font->Name = "System";
font->Pitch = fpDefault;
font->Size = 10;
font->Style << fsBold;
// make the system font the device context''s selected font

SelectObject (hDC,font->Handle);
// create the bitmap display lists

// we''re making images of glyphs 0 thru 255

// the display list numbering starts at 1000, an arbitrary choice

wglUseFontBitmaps (hDC, 0, 255, 1000);

//to output text (slightly buggy but will give you the jist.


void __fastcall TViewPort::TextOut(int X,int Y,String Text,TColor Color,int Alpha)
{
int red = GetRValue(Color);
int green = GetGValue(Color);
int blue = GetBValue(Color);

float r,g,b,a;
//convert color to floating point values

r = (float)red / 255;
g = (float)green / 255;
b = (float)blue / 255;

//ensure alpha in range

Alpha > 255 ? Alpha = 255 : Alpha = Alpha;
Alpha < 0 ? Alpha = 0 : Alpha = Alpha;

a = (float)Alpha / 255;

glColor4f(r,g,b,a);

glRasterPos2i(X,Y);
// display a string:

// indicate start of glyph display lists

glListBase (1000);
// now draw the characters in a string

glCallLists (24, GL_UNSIGNED_BYTE, Text.c_str());
}



Hope it helps
MButchers
MButchers
Opps whats it doing all the way over there
Staffan
Staffan
wglXXX... sounds like one those evil windows-only extensions


"This album was written, recorded and edited at Gröndal, Stockholm in the year of 2000. At this point in time money still ruled the world. Capitalistic thoughts were wide spread. From the sky filled with the fumes of a billionarie''s cigar to the deepest abyss drenched in nuclear waste. A rich kid was a happy kid, oh..dirty, filthy times. Let this be a reminder."
- Fireside, taken from back of the Elite album
The_[PI]_ehT
The_[PI]_ehT
Yeah, seemingly
but wait... Windows, and speed ?!?
Isn''t that a contradiction?

pi~
Jan PieczkowskiBrainwave Studios
redmonkey
redmonkey
i wasnt getting anywhere with the font tuts from nehe (my own fault ) so i added a bmp rendering func

bassiclly it works like this, my texture(256x256) is dividded into sections of 32x32 for each character.

i keep a standard "alphabet" of the order, say
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef...01234...!"£$%^ etc

(it think its 8x8 per texture,so i have another for symbols)

then, that order, is stuck into a string, and i add a func to find its pos (on the texture)

it loops through my string("ABCDE...") till it finds the char (i should use scanf) increasing x and y as i go.

*then* i have the x/y on the pos (eg, "D" is x3 y0) so i can use that to apply the texture in a certain place on a flat quad.

you can also easily scale the font by chnaging the size of the quad, and colour it etc using color3f.

hope that kinda made sense :]

__________________
graham "red" reeves.

red@deadpenguin.org
www.deadpenguin.org
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
redmonkey
redmonkey
oop, as the bmp has now loaded at the top, i can tell you how they did that

they just use the char''s number to find its pos.
char*(texturewidth/256)

__________________
graham "red" reeves.

red@deadpenguin.org
www.deadpenguin.org
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
Dunge
Dunge
hummmm....
first MButchers I don''t understand anything to your code, except that it use glRasterPos2i(); and that''s what slow down the prog in the NeHe text tutorial.... and redmonkey I understand what you say but make it in C++ that''s another thing.... and that look very complicated! I know I ask a big thing but I want to make it working, and I want to understand it...

You said :
you can also easily scale the font by chnaging the size of the quad, and colour it etc using color3f.
Yeah but color3f don''t change the color of the textures!
redmonkey
redmonkey
color3f does change the color:
1.0f,1.0f,1.0f is white
it doesnt icnrease the brightness, so
1.0f,0.0f,0.0f is a red, but not too bright.

next, i dunno how good you are at reading code, and my project is kinda open source, so here it is:
http://www.deadpenguin.org/files/nwb10.zip


thats a very old shot, but kinda gives the indication of what it does

find fontwrite()

__________________
graham "red" reeves.

red@deadpenguin.org
www.deadpenguin.org
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
Dunge
Dunge
Hehe cool GTA like game..... I will check the code!
Dunge
Dunge
Grrr.... my way of understanding code is to modifie it and test what it''s doing.... but I''m not abble to compille this game because of the f***ing directx... Yes I included all the .lib files, yes I have the DX SDK, yes I added the include and lib dir in the VC++ option and put them on the top of the list... but I''m not abble to compille the Nehe DirectInput tutorial too... same error :
Lesson23.cpp(543) : error C2065: ''DirectInputCreateEx'' : undeclared identifier

Maybe that''s because I have DirectX8 and the Directx8 SDK?
MButchers
MButchers
Heres microsofts code then (non c++builder) from sdk help

Here''s a skeletal example that shows how to draw some text:

HDC hdc;
HGLRC hglrc;

// create a rendering context
hglrc = wglCreateContext (hdc);

// make it the calling thread''s current rendering context
wglMakeCurrent (hdc, hglrc);

// now we can call OpenGL API

// make the system font the device context''s selected font
SelectObject (hdc, GetStockObject (SYSTEM_FONT));

// create the bitmap display lists
// we''re making images of glyphs 0 thru 255
// the display list numbering starts at 1000, an arbitrary choice

wglUseFontBitmaps (hdc, 0, 255, 1000);

// display a string:
// indicate start of glyph display lists
glListBase (1000);
// now draw the characters in a string
glCallLists (24, GL_UNSIGNED_BYTE, "Hello Win32 OpenGL World");

my original post was in c++builder code (much easier?)

1st part changes the font
2nd part loads font into hdc
3rd part creates display lists for font
4th part (TextOut) displays text to current HGLRC


Topic Locked

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

Sign in to reply to this topic.