%d or %s... For custom font?

Graphic based area of development (Graphics Processing Unit), including the Geometry Transform Engine (GTE), TIM, STR (MDEC), etc.
Post Reply
User avatar
NITROYUASH
Serious PSXDEV User
Serious PSXDEV User
Posts: 76
Joined: January 7th, 2018, 12:03 am
PlayStation Model: PSone
Steam: NITROYUASH
Location: Russian Federation
Contact:

%d or %s... For custom font?

Post by NITROYUASH » April 2nd, 2018, 3:25 am

Hello PSXDEV :>
So... It is possible to create %d, %s, /n, etc, for custom fonts? Like printf or fntprint?

Code: Select all

GsSPRITE Font_Tahoma;
extern unsigned char SYS_FONT_TAHOMA[];

extern int DrawFontTahoma(char *string, int X, int Y, int R, int G, int B, int DIST, int SCALE, ...);

extern int DrawFontTahoma(char *string, int X, int Y, int R, int G, int B, int DIST, int SCALE, ...)
{
	GsIMAGE FontInfo;
	int fntval=0;

	GsGetTimInfo((u_long *)SYS_FONT_TAHOMA+1,&FontInfo);

	// Setting Font proprieties
	Font_Tahoma.tpage=14; //Font tpage
	Font_Tahoma.attribute=((FontInfo.pmode&0x3f)<<24);  // pattern bit mode: 15bitdirect

	Font_Tahoma.cx=FontInfo.cx;
	Font_Tahoma.cy=FontInfo.cy;

	// Text cell size
	Font_Tahoma.w=16;
	Font_Tahoma.h=16;

	Font_Tahoma.x = X;            // COORDINATE X
	Font_Tahoma.y = Y;            // COORDINATE Y
	
	Font_Tahoma.r = R;			// Font RED colors
	Font_Tahoma.g = G;			// Font GREEN colors
	Font_Tahoma.b = B;			// Font BLUE colors
	
	Font_Tahoma.scalex=Font_Tahoma.scaley=SCALE;

	while(*string){

		if(*string>='A' && (*string)<='Z')
		fntval=(*string)-'A';

		else if(*string>='1' && (*string)<='9')
		fntval=26+(*string)-'1';

		else if(*string == '0') fntval=35;
		
		else if(*string>='a' && (*string)<='z')
		fntval=36+(*string)-'a';
		
		else if(*string == '!') fntval=62;
		else if(*string == '?') fntval=63;
		else if(*string == ':') fntval=64;
		else if(*string == ';') fntval=65;
		else if(*string == '.') fntval=66;
		else if(*string == ',') fntval=67;
		else if(*string == '[') fntval=68;
		else if(*string == ']') fntval=69;
		else if(*string == '(') fntval=70;
		else if(*string == ')') fntval=71;
		else if(*string == '{') fntval=72;
		else if(*string == '}') fntval=73;
		else if(*string == '+') fntval=74;
		else if(*string == '-') fntval=75;
		else if(*string == '=') fntval=76;
		else if(*string == '/') fntval=77;
		else if(*string == '|') fntval=79;
		else if(*string == '_') fntval=80;
		else if(*string == '*') fntval=81;
		else if(*string == '@') fntval=82;
		else if(*string == '`') fntval=84; // It's actually [']
		else if(*string == '~') fntval=85;
		else if(*string == '^') fntval=86;
		else if(*string == '<') fntval=87;
		else if(*string == '>') fntval=88;
		else if(*string == '$') fntval=89;
		else if(*string == '#') fntval=90;
		else if(*string == '«') fntval=92;
		else if(*string == '»') fntval=93;
		else if(*string == '&') fntval=94;
		else if(*string == '%') fntval=95;
		else if(*string == '—') fntval=96;
		else if(*string == ' ') fntval=111;
		
		// Restricted Symbols
		
		// ["] SYMBOL
		else if(*string == '\1') fntval=98;
		
		// [No.] SYMBOL
		else if(*string == '\2') fntval=91;

		// [LOGO] SYMBOL
		else if(*string == '\3') fntval=97;
		
		// New Line
		else if(*string == '\n') {
			string++;
			Font_Tahoma.x = X;
			Font_Tahoma.y += 17;
			continue;
		}

		else {
			string++;
			continue;
		}

		Font_Tahoma.u=(fntval%16)*16;
		Font_Tahoma.v=(fntval/16)*16+1;
		
		//Draw text to OT
		GsSortSprite(&Font_Tahoma,&myOT[ActiveBuffer],0);

		string++;
		
		//Screen position
		Font_Tahoma.x+=16+(DIST);
	}
}

User avatar
MrQuetch
Curious PSXDEV User
Curious PSXDEV User
Posts: 23
Joined: April 1st, 2018, 9:34 am
Motto: You can accomplish anything.
Looking to: Create professional homebrew.
Location: United States

Re: %d or %s... For custom font?

Post by MrQuetch » April 3rd, 2018, 4:23 am

Hi, NITROYUASH.

I'm very new to the PS1 Homebrew, but having been using the C language for over the past year. I'm certain that even if I'm not able to fully help, I will at least be able to lead you in the right direction. Perhaps we will both be able to learn more from this.

From my experience (I mean in general), you could use images, sprites, or even textures for your font. If you already know how to set up geometry in the PS1, you could draw out your text through primitives, set the depth to draw over everything else, and then use a "switch" statement to check which letter or other character is next in your array of strings (Does "while" work for what you're doing so far)? I noticed you're using that to check the characters.

I know for sure that you can use %d or %s to draw out some text. However, keep in mind that the %d is used for numbers while %s is used for an array of characters. Since the majority of your game will use strings, you could make a function that converts your number to a string, and only have to use %s throughout the game.

If you use "sprintf" in someway, you should be able to print out the contents of a number properly. I still have much to learn myself, but I hope this information helps you. You already have a good chunk of code... I'm sure you will get to where you want to be eventually.

Good luck.

Edit: You may want to look at this: viewtopic.php?f=64&t=319

User avatar
NITROYUASH
Serious PSXDEV User
Serious PSXDEV User
Posts: 76
Joined: January 7th, 2018, 12:03 am
PlayStation Model: PSone
Steam: NITROYUASH
Location: Russian Federation
Contact:

Re: %d or %s... For custom font?

Post by NITROYUASH » April 4th, 2018, 12:39 am

Thanks for the answer!
I found the another way to translate our stuff in custom fonts.

We also can use strcat() for this c:

User avatar
MrQuetch
Curious PSXDEV User
Curious PSXDEV User
Posts: 23
Joined: April 1st, 2018, 9:34 am
Motto: You can accomplish anything.
Looking to: Create professional homebrew.
Location: United States

Re: %d or %s... For custom font?

Post by MrQuetch » April 4th, 2018, 4:59 am

NITROYUASH wrote:
April 4th, 2018, 12:39 am
Thanks for the answer!
I found the another way to translate our stuff in custom fonts.

We also can use strcat() for this c:
Thank you - I'm glad you found an answer to your problem.

May I ask how you did that? I'm still learning, so I like looking at other code to learn from.

User avatar
NITROYUASH
Serious PSXDEV User
Serious PSXDEV User
Posts: 76
Joined: January 7th, 2018, 12:03 am
PlayStation Model: PSone
Steam: NITROYUASH
Location: Russian Federation
Contact:

Re: %d or %s... For custom font?

Post by NITROYUASH » April 4th, 2018, 5:23 am

Code: Select all

char	STRING[64];
char	FNTCHR[2];

int	test() {

	// Load our font from PS-EXE :)
	LoadTIM((u_long*)SYS_FONT_TAHOMA);

	while (1) {
		// Font test
		// [*STRING, X, Y, R, G, B, DISTANCE BETWEEN LETTERS, SCALE]
		DrawFontTahoma(testfont3, 50, 190, 128, 128, 128, -4, ONE);
		DrawFontTahoma("1234\n1234", 50, 190, 128, 128, 128, -4, ONE);

		// More font stuff!
		STRING[0] = 0; 
		strcat(STRING, "Timer"); strcat(STRING, "test:");
		FNTCHR[0] = '0'+FSEC[1]; strcat(STRING, FNTCHR);
		FNTCHR[0] = '0'+FSEC[0]; strcat(STRING, FNTCHR);
		DrawFontTahoma(STRING, 50, 190, 128, 128, 128, -4, ONE);
	}
}
I am not good in c, but i hope this example will help someone.

User avatar
MrQuetch
Curious PSXDEV User
Curious PSXDEV User
Posts: 23
Joined: April 1st, 2018, 9:34 am
Motto: You can accomplish anything.
Looking to: Create professional homebrew.
Location: United States

Re: %d or %s... For custom font?

Post by MrQuetch » April 4th, 2018, 5:25 am

NITROYUASH wrote:
April 4th, 2018, 5:23 am

Code: Select all

char	STRING[64];
char	FNTCHR[2];

int	test() {

	// Load our font from PS-EXE :)
	LoadTIM((u_long*)SYS_FONT_TAHOMA);

	while (1) {
		// Font test
		// [*STRING, X, Y, R, G, B, DISTANCE BETWEEN LETTERS, SCALE]
		DrawFontTahoma(testfont3, 50, 190, 128, 128, 128, -4, ONE);
		DrawFontTahoma("1234\n1234", 50, 190, 128, 128, 128, -4, ONE);

		// More font stuff!
		STRING[0] = 0; 
		strcat(STRING, "Timer"); strcat(STRING, "test:");
		FNTCHR[0] = '0'+FSEC[1]; strcat(STRING, FNTCHR);
		FNTCHR[0] = '0'+FSEC[0]; strcat(STRING, FNTCHR);
		DrawFontTahoma(STRING, 50, 190, 128, 128, 128, -4, ONE);
	}
}
I am not good in c, but i hope this example will help someone.
Actually, this may be useful enough for me (And hopefully others). Is the "SYS_FONT_TAHOMA" already on the PS1 by default? Or is that something you need to add to it? Anyways, thank you for sharing. :)

Edit: I just realized in the first snippet of code you have you show how to get the "SYS_FONT_TAHOMA".

User avatar
NITROYUASH
Serious PSXDEV User
Serious PSXDEV User
Posts: 76
Joined: January 7th, 2018, 12:03 am
PlayStation Model: PSone
Steam: NITROYUASH
Location: Russian Federation
Contact:

Re: %d or %s... For custom font?

Post by NITROYUASH » April 4th, 2018, 5:43 am

SYS_FONT_TAHOMA (Load from System (PS-EXE) Font Tahoma) - it's "my" custom font. I just ported Tahoma font into my code and loading this texture from PS-EXE.

Code: Select all

			opt C+

		section datasection
; ------------------( GFX DATA )-------------------
			CNOP	0,4
        global SYS_FONT_TAHOMA
SYS_FONT_TAHOMA:
        incbin "materials/TAHOMA_FONT_EXTENDED.TIM"
            END
Tahoma Texture from Tim Tool V3.0.A:
► Show Spoiler

User avatar
MrQuetch
Curious PSXDEV User
Curious PSXDEV User
Posts: 23
Joined: April 1st, 2018, 9:34 am
Motto: You can accomplish anything.
Looking to: Create professional homebrew.
Location: United States

Re: %d or %s... For custom font?

Post by MrQuetch » April 4th, 2018, 8:30 am

NITROYUASH wrote:
April 4th, 2018, 5:43 am
SYS_FONT_TAHOMA (Load from System (PS-EXE) Font Tahoma) - it's "my" custom font. I just ported Tahoma font into my code and loading this texture from PS-EXE.

Code: Select all

			opt C+

		section datasection
; ------------------( GFX DATA )-------------------
			CNOP	0,4
        global SYS_FONT_TAHOMA
SYS_FONT_TAHOMA:
        incbin "materials/TAHOMA_FONT_EXTENDED.TIM"
            END
Tahoma Texture from Tim Tool V3.0.A:
► Show Spoiler
Oh. That's cool. Thanks for the snippet of code. Now, it will be easier for me to do this too.

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

Re: %d or %s... For custom font?

Post by Xavi92 » April 4th, 2018, 4:47 pm

For my video game "Airport" I am also using custom fonts along with a simple library I built. Check it out here: https://github.com/XaviDCR92/Airport/bl ... rce/Font.c

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests