Page 1 of 1

VGA Fonts In Graphics Mode

Posted: Sat May 25, 2019 4:52 pm
by dannywrayuk
I'm currently trying to set up printing characters to the screen and I'm following the article on the wiki: https://wiki.osdev.org/VGA_Fonts

I can get the inefficient versions to work quit easily, that is, just calling the putpixel command several times. but I can't seem to get he optimised versions to work. I'm Specifically talking about the last piece of code in the article:

Code: Select all

void drawchar_transparent_8BPP(unsigned char c, int x, int y, int fgcolor)
{
	void *dest;
	uint32_t *dest32;
	unsigned char *src;
	int row;
	uint32_t fgcolor32;
 
	fgcolor32 = fgcolor | (fgcolor << 8) | (fgcolor << 16) | (fgcolor << 24);
	src = font + c * 16;
	dest = videoBuffer + y * bytes_per_line + x;
	for(row = 0; row < 16; row++) {
		if(*src != 0) {
			mask_low = mask_table[*src][0];
			mask_high = mask_table[*src][1];
			dest32 = dest;
			dest32[0] = (dest[0] & ~mask_low) | (fgcolor32 & mask_low);
			dest32[1] = (dest[1] & ~mask_high) | (fgcolor32 & mask_high);
		}
		src++;
		dest += bytes_per_line;
	}
}
I cant seem to get this code to work even after modifying it a fair bunch. There is also an example on the wiki in a slightly different article https://wiki.osdev.org/Drawing_In_Protected_Mode
(the last code section in the article) but i also cant get that one to work either. Can someone confirm is these pieces of code are actually correct? or if you have any alternate implementations?

cheers
danny

Re: VGA Fonts In Graphics Mode

Posted: Sat May 25, 2019 8:24 pm
by MichaelPetch
Out of curiosity is this a 32-bit kernel or 64-bit kernel? Using Multiboot or your own custom bootloader? Do you have a project available to look at? Building with optimizations on or off?

Re: VGA Fonts In Graphics Mode

Posted: Tue May 28, 2019 6:02 am
by bzt
Hi,

I've written a font renderer that may help you. See "ssfn_putc()".

Cheers,
bzt

Re: VGA Fonts In Graphics Mode

Posted: Wed May 29, 2019 12:43 pm
by dannywrayuk
Cheers bzt that helped quite a lot.
Turned out the issue was that the examples on wiki are only optimised for 8bpp and I was working in up to 32.
Solved the issue by reintroducing the inner for-loop and keeping the 'where' pointer outside of all the loops.