PDA

View Full Version : Blitting characters in graphics modes



SMurf
03-29-2002, 01:15 PM
Hi,
I've been using this code (which is from "Teach Yourself Game Programming In 21 Days") to blit characters from the BIOS ROM font to the screen:-


unsigned char *screen = (unsigned char *)MK_FP(0xA000, 0);
unsigned char far *rom_char_set = (char far *)MK_FP(0xF000, 0xFA6E);

void Blit_Char(int x, int y, char c, int colour)
{
int offset, xc, yc;
char far *work_char;
unsigned char bit_mask = 0x80;

work_char = rom_char_set + c * 8;
offset = (y << 8) + (y << 6) + x;
for (yc=0;yc<8;yc++)
{
bit_mask = 0x80;
for (xc=0;xc<8;xc++)
{
if ((*work_char & bit_mask))
screen[offset+xc] = colour;
bit_mask = (bit_mask>>1);
}
offset += 320;
work_char++;
}
}

void Blit_String(int x, int y, int colour, char *string)
{
int index;

for (index=0;string[index]!=0;index++)
Blit_Char(x+(index<<3), y, string[index], colour);
}

The thing is, comparing it with a standard printf call, the characters look different, and the spacing between the characters seems a bit wayward. Does anyone know a way of emulating the printf function with transparent coloured text (i.e. for gaphics modes)?

sean
03-29-2002, 06:35 PM
To solve that problem you're going to want a function that specializes on a certain platform. There are basically two types: functions that specialize on a specific routine on almost all platforms, and those that have general routiones (can do alot) but focus on one specific latform. printf specializes on sending only plain text, but it'll work in almost all situations. What you have right now works fine, so stick with that.

VirtualAce
04-03-2002, 08:39 PM
I think the term 'blit' here necessitates that he does want to use printf() since that will also plot the 'uncolored' pixels of the cell. He wants to blit from the data in memory, when the pixel is 0 or blank, he will move on. When it is not blank, he will plot a pixel to the screen in the current color for the text. This will draw the text over an image, but will not show the cells of the characters.

doubleanti
04-05-2002, 02:47 AM
so far as that goes... sorry to disappoint but i've yet to encounter a pixel granularity alteration method of the video display under text modes... after all, that's why they are called text... i'm sure you could edit the BIOS font characters themselves... but so far as anything further than that, i'm unsure... oh and by the way, is 80 by 25, per pixel, 640 by 480? or maybe 400... not too sure, but if it was i want to know...

VirtualAce
04-05-2002, 03:58 AM
Hey DA, in the code he has a pointer to A000:0000. So he is in graphics mode - he is just trying to read the ROM fonts so that he does not have to create his own.

doubleanti
04-05-2002, 12:08 PM
oooh i see... well for my own bitmapped fonts what i did was output all the asciis, window the DOS box, take a screenshot, and read the windows bitmap into a bit mapped font file of my own... for your reference... but this might be an even better idea ... [tho i did get a nice turnout for my font... :)]