Display 2 color font

SGDK only sub forum

Moderator: Stef

Post Reply
orlanrod
Very interested
Posts: 99
Joined: Fri Sep 25, 2015 7:46 pm

Display 2 color font

Post by orlanrod » Tue Oct 27, 2015 2:35 am

Is there a way to have two colors in text? The single color text is fine for dialog, but i would like to display 2 or more for larger text.

Thanks.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Display 2 color font

Post by Stef » Tue Oct 27, 2015 9:34 am

You just need to define your own font with several color. Default SGDK font only use colors 0 (background/transparent) and 15 (foreground) but you are free to redefine it so you have nice gradient in your letter for instance :)

mikejmoffitt
Very interested
Posts: 86
Joined: Fri Sep 25, 2015 4:16 pm

Re: Display 2 color font

Post by mikejmoffitt » Tue Oct 27, 2015 8:41 pm

You can use your four palettes to print up to four different colors without having to touch the font in VRAM.

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Display 2 color font

Post by dub » Wed Oct 28, 2015 8:23 am

Hi.

I try to insert my font image.
Image

I tried the two functions :

Code: Select all

u16 VDP_loadFont(const TileSet *font, u8 use_dma)
(myfont = VDP_loadFont(fontrom, 1);)
void VDP_loadFontData(const u32 *font, u16 length, u8 use_dma)
I always have the same error : incompatible type for argument 1. I read the first argument of VDP_loadFont and insert in my .res file :
TILESET fontrom "font.png" 0

I try with BITMAP or IMAGE without success

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Display 2 color font

Post by Stef » Wed Oct 28, 2015 9:07 am

You were close :

Code: Select all

VDP_loadFont(&fontrom, TRUE);
And indeed you have to use TILESET resource type here.

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Display 2 color font

Post by dub » Wed Oct 28, 2015 10:59 am

Oh my god, i forgot the pointer.

I've adding a planB to see the transparent color with VDP_drawText(). Now, I use his own palette but we can use the palette we want.
Image

I've made an example, maybe that can help someone else.
https://www.dropbox.com/s/awey2em7by2ygr8/font.zip

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Re: Display 2 color font

Post by KanedaFr » Thu Oct 29, 2015 9:43 pm

Last month, I faced the same problem.
in my case, I wanted to use 8 colors fonts !
The 'only' valid way to do it was to load 8 version of the font.

Hopefully, colors needed to be changed every row so....HInt color change !

If anyone would like to know more, here the code snippet for SGDK:

Code: Select all

void handleHBlank()
{
	u8 currentRow = ((GET_VCOUNTER+1) >> 3);
	u16 fontColor;
	
	if (currentRow < 8)	return;
	fontColor = colors[ 1+(currentRow-8)% 8 ];

	asm("move.l #0xc0220000, 0xc00004.l");
	while((*((volatile u16*)GFX_CTRL_PORT) & 4) == 0);
	asm("move.w %0, 0xc00000.l":/*nothing */:"r"(fontColor) );
}

....

//faster than SYS_setHIntCallback(&handleHBlank);
internalHIntCB = &handleHBlank;

VDP_setHInterrupt(TRUE);
	
perhaps it could be optimized but it works like this so....

Post Reply