Custom fonts?

General Programming help in C, C++ or ASM, Compiling / Debugging, and R3000A Central Processing Unit (CPU) information
Post Reply
NaughtyCow
Curious PSXDEV User
Curious PSXDEV User
Posts: 15
Joined: June 7th, 2016, 8:05 am
I am a: Student
Skype: friedonibot
Location: Croatia

Custom fonts?

Post by NaughtyCow » June 8th, 2016, 6:01 am

How do you guys do your custom fonts? I've tried creating one big TIM image (font), then drawing a sprite for each character (same sprite instance), but the emulator breaks when I draw more than 4 characters.

EDIT: PSXSDK

Code: Select all

void printText(char* text, unsigned char x, unsigned char y) {
	unsigned char id = 0;
	short px = x;
	short py = y;
	while (text[id] != '\0') {
		if (text[id] == '\n') {
			px = x;
			py++;
		} else {
			sfont.x = (short)px * 16;
			sfont.y = (short)py * 16;
			sfont.u = (text[id] % 16) * 16;
			sfont.v = (text[id] / 16 - 1) * 16;
			GsSortSimpleSprite(&sfont);
			px++;
		}
		id++;
	}
}

Code: Select all

int main() {
..
	while (1) {
		if (redraw) {
			GsSetDrawEnvSimple(0, buffer?264:8, 320, 240);
			GsSetDispEnvSimple(0, buffer?8:264);
			buffer = !buffer;
			GsSortCls(0, 0, 0);

			printText("Test A", 0, 0);

			GsDrawList();
			while (GsIsDrawing());
			redraw = 0;
		}		
	}
..
}

NaughtyCow
Curious PSXDEV User
Curious PSXDEV User
Posts: 15
Joined: June 7th, 2016, 8:05 am
I am a: Student
Skype: friedonibot
Location: Croatia

Re: Custom fonts?

Post by NaughtyCow » June 8th, 2016, 6:15 am

Found my own mistake (I think). Turns out I should have drawn after each sprite. I also have an another question: How many sprites can I draw per frame (does it depend on the primitives table size, or something else).

User avatar
gwald
1997 Yaroze Enthusiast
1997 Yaroze Enthusiast
Posts: 256
Joined: September 18th, 2013, 8:44 am
I am a: programmer/DBA
PlayStation Model: Net Yaroze
Location: Australia
Contact:

Re: Custom fonts?

Post by gwald » June 8th, 2016, 8:50 am

The limitations are really VRAM, GPU speed (if your scaling and/or rotating) and OT size (for depth sorting).

User avatar
Shendo
C Programming Expert
C Programming Expert
Posts: 238
Joined: March 21st, 2012, 4:34 am
I am a: Programmer
Motto: Never settle
PlayStation Model: SCPH-9002
Location: Croatia, EU

Re: Custom fonts?

Post by Shendo » June 8th, 2016, 9:28 am

You can take a look at my PadTest for the font routine.
It's not the best one because each letter is a sprite but it does the job.

Ideally you should use a VRAM 2 VRAM copy function to construct whole paragraph
and then create 1 sprite and place it in the framebuffer. That's how MGS does it for subtitles and Codec screen.
My PS1 consoles: 2 x SCPH-1002, SCPH-5552, SCPH-7002, 4x SCPH-9002, 2 x SCPH-102.
Dev console: SCPH-9002, MM3 - 7 wire modchip, PAL color mod, CH340 serial cable addon.

NaughtyCow
Curious PSXDEV User
Curious PSXDEV User
Posts: 15
Joined: June 7th, 2016, 8:05 am
I am a: Student
Skype: friedonibot
Location: Croatia

Re: Custom fonts?

Post by NaughtyCow » June 9th, 2016, 4:14 am

Shendo wrote:You can take a look at my PadTest for the font routine.
It's not the best one because each letter is a sprite but it does the job.

Ideally you should use a VRAM 2 VRAM copy function to construct whole paragraph
and then create 1 sprite and place it in the framebuffer. That's how MGS does it for subtitles and Codec screen.
Thanks. I was thinking about that, and ideally, I was hoping to avoid it, since it would occupy much VRAM, and allow less for my game sprites/backgrounds. But, seems like I must roll with it.

Xavi92
C Programming Expert
C Programming Expert
Posts: 122
Joined: October 6th, 2012, 12:53 am

Re: Custom fonts?

Post by Xavi92 » June 9th, 2016, 4:30 am

As others have said, primitive list defines size limit for how many sprites / lines / rectangles / whatever can be drawn on screen. This size is selected by user, so I usually set it around 4000 - 5000. If you want to optimise resources, always precalculate new frame when GPU is working, but do NOT sort any sprite as long as DMA CPU -> GPU transfer hasn't finished. Then, sort everything, wait until GPU has finished and finally call GsDrawList() and swap buffers.

That method made my game improve its framerate from 25 up to 50 fps.

Sblorgz
Curious PSXDEV User
Curious PSXDEV User
Posts: 22
Joined: May 18th, 2015, 1:47 pm

Re: Custom fonts?

Post by Sblorgz » June 9th, 2016, 11:48 am

Shendo wrote:Ideally you should use a VRAM 2 VRAM copy function to construct whole paragraph
and then create 1 sprite and place it in the framebuffer. That's how MGS does it for subtitles and Codec screen.
Bad solution and not ideal. You end up eating RAM and VRAM more than you need. Allocate a VRAM page for font and use SPRT8/16 instead, then chain then with a DR_TPAGE primitive to account for the destined page.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest