Advertisement

Text Blitting

Started by March 03, 2000 02:50 PM
8 comments, last by PsYcHoPrOg 24 years, 6 months ago
How would I create a function to blit text from a bitmap containing all of the charecters? Would I create some sort of lookup table for the location of each of the charecters? If so, how would this be done? Thanks, I really appreciate the help. "Remember, I'm the monkey, and you're the cheese grater. So no fooling around." -Grand Theft Auto, London
D:
I usually calculate the location of the letter in the bitmap. Make sure your letters are all the same width and height, and multiply the width by the letter number in the file. I usually put all lowercase letters on one line, and all uppercase on another. Just modify the blit from rectangle to frame the correct letter.

*oof*
*oof*
Advertisement
Yeah, I know this, but how would I do this(this is in a function TextBlt(char text[64], int x, int y):


.....
//assume that all of the
//variables have been defined

stringleangth = strlen(text);

for(index; index < stringleangth; index++)
{
//look at text[index]
//and find the charecter in the bitmap.
//how would I know the location
//of the charecter in the bitmap?
//use a lookup table?

if(FAILED(textsurface->Blt(...)))
//error

//...ect. blah blah
}



Obviously this won't compile or run, but you get the idea.

"Remember, I'm the monkey, and you're the cheese grater. So no fooling around."
-Grand Theft Auto, London

Edited by - PsYcHoPrOg on 3/3/00 3:22:56 PM
D:
For variable length characters you could precreate a table of offsets into the bitmap. you could start the table with the space character (ASCII no. 32) and use the ASCII codes for the chars as the index into the table (char code - 32 = index)

Hope this helps
bstach, I kind of understand what your saying, but I don''t know anything about ASCII.

"Remember, I'm the monkey, and you're the cheese grater. So no fooling around."
-Grand Theft Auto, London
D:
To get the ASCII code of a char, typecast it as an int.
This, along with the other posts, should get you on your way.

Hope that helps.

Ben
Advertisement
ASCII (American Standard Code for Information Interchange)

ASCII is just the numerical representaion of the characters used for text. It starts at 0(nul character) and goes through 127(del character).

The range of characters that you would define bitmaps for is in the range 32(space) - 126(~)

Capitol letters start at code 65 (A=65, B=66, C=67, etc.) and lower case starts at code 97 (a=96, b=97, c=98, etc.) If you look around you can find ASCII charts just about anywhere. Here is a link to one on the internet http://www.jimprice.com/ascii-0-127.gif

Now what you would do to create a look up table is to store the x pos and y pos of the upper left corner of the character and the width of the character in each entry of the lookup table.

Then using some pseudo code like this we can blit the characters to the screen.

struct CharTable
{
int xpos;
int ypos;
int width;
int height;
};

BltText(char* string, Bitmap* pTextBitmap, int xDest, int yDest)
{
char* p = string;
while(*p != 0)
{
int index = (*p) - 32;
int xpos = CharTable[index].xpos;
int ypos = CharTable[index].ypos;
int width = CharTable[index].width;
int height = CharTable[index].height;

BlitFast(pScreenBitmap, xDest, yDest, pTextBitmap, xpos, ypos, width, height);
xDest += CharTable[index].width;
p++;
}
}

Hope this clears it up.
Thanks, That kinda cleared things up. If anyone has any more suggestions, please post them up. And just to clear things up, this is how I would get the ASCII value of a char, right?


char ascii;

cout<<"please type in a charecter./n";
cin>>ascii;

int asciivalue = (int)ascii;
cout<< "The value of the char in ASCII is ";
<< asciivalue;
<< "\n";


If there are any problems with the code, please tell me.


"Remember, I'm the monkey, and you're the cheese grater. So no fooling around."
-Grand Theft Auto, London




Edited by - PsYcHoPrOg on 3/3/00 4:20:54 PM
D:
Yes, that''ll display the number of the character, or you could do it like this (I think):
cout << "hello" << (int)ascii;
but i could be wrong.
I was thinking of doing that but I wasn''t sure if it would work.

I could create a bitmap having all of the charecters in ASCII order from 32-98(space to delete?), each charecter being 16x16 on a 640x480 bitmap. And then I would do something like this, right?


bool BltText(char text[64], int x, int y)
{
int textlength = strlen(text);
int index;
int blitsrcx;
int blitsrcy;


for(index = 0; index < textlength, index++)
{
blitsrcx = (int)text[index]*16;
//wait, I lost it, what do I do next?
}
}


"Remember, I'm the monkey, and you're the cheese grater. So no fooling around."
-Grand Theft Auto, London
D:

This topic is closed to new replies.

Advertisement