Page 1 of 1

Glitches in gsKit font display

Posted: Mon Sep 24, 2007 7:31 am
by cosmito
I've been trying a bit the font support of gsKit and I modicied the gsKit\examples\fontm example so that it scrolls a bunch of text lines up and down the screen.

Code: Select all

#include "gsKit.h"
#include "dmaKit.h"
#include "malloc.h"

int main(void)
{
	u64 White, Black, BlackFont, WhiteFont, BlueTrans, RedTrans, GreenTrans, WhiteTrans;
	GSGLOBAL *gsGlobal = gsKit_init_global(GS_MODE_NTSC);
	GSTEXTURE test;
    int Y = -400;
    int sig = 1;

	GSFONT *gsFont = gsKit_init_font(GSKIT_FTYPE_FONTM, NULL);

	dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
		    D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF&#41;;

	// Initialize the DMAC
	dmaKit_chan_init&#40;DMA_CHANNEL_GIF&#41;;
	dmaKit_chan_init&#40;DMA_CHANNEL_FROMSPR&#41;;
	dmaKit_chan_init&#40;DMA_CHANNEL_TOSPR&#41;;
	
	Black = GS_SETREG_RGBAQ&#40;0x00,0x00,0x00,0x00,0x00&#41;;
	White = GS_SETREG_RGBAQ&#40;0xFF,0xFF,0xFF,0x00,0x00&#41;;
	
	WhiteFont = GS_SETREG_RGBAQ&#40;0x80,0x80,0x80,0x80,0x00&#41;;
	BlackFont = GS_SETREG_RGBAQ&#40;0x00,0x00,0x00,0x80,0x00&#41;;
    u64 TexCol = GS_SETREG_RGBAQ&#40;0x80,0x80,0x80,0x80,0x00&#41;;

	BlueTrans = GS_SETREG_RGBAQ&#40;0x00,0x00,0xFF,0x40,0x00&#41;;
	RedTrans = GS_SETREG_RGBAQ&#40;0xFF,0x00,0x00,0x60,0x00&#41;;
	GreenTrans = GS_SETREG_RGBAQ&#40;0x00,0xFF,0x00,0x50,0x00&#41;;
	WhiteTrans = GS_SETREG_RGBAQ&#40;0xFF,0xFF,0xFF,0x50,0x00&#41;;

    gsGlobal->PrimAlphaEnable = GS_SETTING_OFF;
	gsKit_init_screen&#40;gsGlobal&#41;;
	gsKit_font_upload&#40;gsGlobal, gsFont&#41;;

	gsFont->FontM_Spacing = 0.95f;

	gsKit_texture_bmp&#40;gsGlobal, &test, "host&#58;test.bmp"&#41;;
	test.Filter = GS_FILTER_LINEAR;

    gsKit_mode_switch&#40;gsGlobal, GS_ONESHOT&#41;;

	while&#40;1&#41;
	&#123;
		gsKit_clear&#40;gsGlobal, Black&#41;;

		gsKit_font_print_scaled&#40;gsGlobal, gsFont, 50, Y, 3, 0.85f, TexCol, 
			"1&#58; ABCDEFGHIJKLM\n"
			"2&#58; NOPQRSTUVWXYZ\n"
			"3&#58; abcdefghijklm\n"        
            "4&#58; nopqrstuvwxyz\n"
			"5&#58; 1234567890,./`\n"
			"1&#58; ABCDEFGHIJKLM\n"
			"2&#58; NOPQRSTUVWXYZ\n"
			"3&#58; abcdefghijklm\n"        
            "4&#58; nopqrstuvwxyz\n"
			"5&#58; 1234567890,./`\n"
			"1&#58; ABCDEFGHIJKLM\n"
			"2&#58; NOPQRSTUVWXYZ\n"
			"3&#58; abcdefghijklm\n"
            "4&#58; nopqrstuvwxyz\n"
			"5&#58; 1234567890,./`\n"
			"6&#58; ~!@#$%^&*&#40;&#41;_<>\n"&#41;; 

        Y = Y + &#40;1 * sig&#41;;
        if &#40;Y>600&#41;
        &#123;
            sig = -1;
            Y = 600;
        &#125;

        if &#40;Y<-400&#41;
        &#123;
            sig = 1;
            Y = -400;
        &#125;
		gsKit_sync_flip&#40;gsGlobal&#41;;
		gsKit_queue_exec&#40;gsGlobal&#41;;
	&#125;
	return 0;
&#125;
I noticed some glitches in the '1' of the first line when the text block reaches the lowest half of the screen... If we reduce the number of text lines to the first 3, it seems to go away.

Maybe a timing issue of gsKit font rendering?

Posted: Mon Sep 24, 2007 8:43 am
by Lukasz
My guess would be that you are rendering with invalid coordinates. Make sure that XYOFFSET + your X,Y coords dont exceed 4096 and get below 0. You can read more about this in the GS Manual, look for "Coordinate Systems".

Timing could also be an issue, but as long as you are waiting for FINISH, there shouldn't be a problem.

Posted: Tue Sep 25, 2007 8:15 am
by cosmito
Lukasz wrote:My guess would be that you are rendering with invalid coordinates. Make sure that XYOFFSET + your X,Y coords dont exceed 4096 and get below 0. You can read more about this in the GS Manual, look for "Coordinate Systems".
Yes in fact you're right and playing on the right side. I should read the docs but I went straight experimenting with it, hoping support for negative coords. Thanks for the tip on the chapter title.

But if negative could cause problems that would invalidate my approach to get a simple scrolling method...

Basically you'll only need to keep a text block long enough to cover some few lines above and bellow the visible area of the screen, not the whole text at once. When the text block moved N pixels (being N the height of the font) the text string block would be replaced by a new with the next line and the Y coord would go back N pixels... Well, trivial I guess :)

a complete example

Posted: Wed Oct 31, 2007 9:39 am
by cosmito
Finally I had the time to pack an example of text scrolling I made based on the fontm gsKit example.

Like I suspected, the use of negative coordinates is not responsable for the occasional glitches (I made a version that uses only positive text positioning)

If you want to try the scroll example, go to :

http://www.esnips.com/web/ps2-homebrew/

and download the fontm_scroll.zip.

The glitches seems to occurs on some characters depending on the line length... Change the text and with luck you get a perfect scrolling.

Posted: Wed Oct 31, 2007 12:56 pm
by radad
I have come across some text glitches also. What I found was that there was a limited number of buffers for blocks of text information loaded to the GS. I am going from memory here but I think the default was two blocks. Changing this to four blocks made the glitches less common but they didn't completely go away. The problem is that the more blocks you use for font texture information leaves less room for other textures.