General Programming help in C, C++ or ASM, Compiling / Debugging, and R3000A Central Processing Unit (CPU) information
-
NaughtyCow
- Curious PSXDEV User

- Posts: 15
- Joined: Jun 07, 2016
- I am a: Student
- Location: Croatia
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

- Posts: 15
- Joined: Jun 07, 2016
- I am a: Student
- Location: Croatia
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).
-
gwald
Verified
- Net Yaroze Enthusiast

- Posts: 342
- Joined: Sep 18, 2013
- I am a: programmer/DBA
- PlayStation Model: Net Yaroze
-
Contact:
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).
-
Shendo
Verified
- C Programming Expert

- Posts: 250
- Joined: Mar 21, 2012
- I am a: Programmer
- Motto: Never settle
- PlayStation Model: SCPH-7502
- Discord: ShendoXT
- Location: Croatia, EU
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.
Dev console: SCPH-7502, FreePSXBoot, CH340 serial cable.
-
NaughtyCow
- Curious PSXDEV User

- Posts: 15
- Joined: Jun 07, 2016
- I am a: Student
- Location: Croatia
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 Verified
- C Programming Expert

- Posts: 161
- Joined: Oct 06, 2012
- PlayStation Model: SCPH-5502
-
Contact:
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

- Posts: 22
- Joined: May 18, 2015
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.
Users browsing this forum: No registered users and 4 guests