Bitmap font engine problem...

Started by
2 comments, last by Nali 23 years, 2 months ago
Hello! I have a problem with my routine for loading bitmap numbers into surfaces and display them. Here is the important code: // Vars LPDIRECTDRAWSURFACE g_lpDDNum[9]; int life = 3; // Loading fonts for(int i=0;i<9;i++) { g_lpDDSStatusBarNum = DDLoadBitmap(g_lpDD,"num.bmp",i*18,0); } // Display them g_lpDDSBuffer->BltFast(100,50, g_lpDDNum[life-1],&r_SbNum,DDBLTFAST_WAIT); The num.bmp contains 10 numbers from 0 - 9 and are exact 18 pixels in width and 14 in height. When I use this code it just pushes the original bitmap together and displays it, which looks very strange.I want the seperated numbers to be displayed. Whats wrong in this code? or does anyone have a better way to do this? Thanks in Advance!!!
Advertisement
Don''t use a variable called i as an index into an array on this messageboard. It (stupidly) interprets i in square brackets as an italic formatting code.

It looks like you are loading the same bitmap ten times. What do you mean by "pushes the original bitmap together"?

Steve ''Sly'' Williams  Code Monkey  Krome Studios
Steve 'Sly' Williams  Monkey Wrangler  Krome Studios
turbo game development with Borland compilers
Your code looks rather strange.

What you need to do is:

Create one surface and load your bitmap into it.

when you want to display a number, you use Blt or BltFast. This will take 2 rectangles as arguments. One rectangle is the destination and one is the source.

They do not have to be the same size as the bmp. So you can make the source and dest rects the same size as one of your numbers. This means you effectively 'chop' a number out of the bmp and paste(or blt) it onto another surface.

For this you should only be using 3 surfaces. The bmp surface, the back buffer surface and the primary surface. You don't need the 9 surfaces you create with LPDIRECTDRAWSURFACE g_lpDDNum[9];.

-DeVore

and some code (off the top of my head and untested, does not work with numbers over 9 and assumes a bmp 0->9 in order.)


//
// Displays a number between 0 and 9
//
void displayNumber(int num, int x, int y)
{
int bmp_width = 12;
int bmp_height = 18;

LPDIRECTDRAWSURFACE numbers_surface = DDLoadBitmap(g_pDD, "num.bmp", 0, 0);

src.left = num * bmp_width;
src.top = 0;
src.right = src.left + bmp_width;
src.bottom = src.top + bmp_height;

dest.left = x;
dest.top = 0;
dest.right = x + bmp_width;
dest.bottom = bmp_height;

ddrval = g_pDDSBack->Blt(&dest, numbers_surface, &src, DDBLT_WAIT|DDBLT_KEYSRC , NULL);
}


Edited by - DeVore on February 15, 2001 6:39:55 AM
Aha... got it know!

Thanks DeVore!

This topic is closed to new replies.

Advertisement