How to display text with different resolutions?

Posted By: preacherX

How to display text with different resolutions? - 04/16/17 08:27

What do you think would be the best way to use text in a way that it won't change its size or position when changing the resolution of the game?
Posted By: Ezzett

Re: How to display text with different resolutions? - 04/16/17 09:00

To position an object independent from the screen resolution you have to place it inside a range from 0 to 1 and multiply it by the current screen resolution.

For example, to place the upper left corner of a text at the center of the screen you would do:

pos_x = 0.5 * screen_size.x;
pos_y = 0.5 * screen_size.y;

To cut off decimals you also need to use integer:

pos_x = integer (0.5 * screen_size.x);
pos_y = integer (0.5 * screen_size.y);

I think you need to create a new font for each resolution and change it with the old font after the resolution was changed.
Posted By: preacherX

Re: How to display text with different resolutions? - 04/18/17 08:55

Thanks for the info! But the thing with the fonts is bad cause there so many different resolutions today... Is that really the only way?
Posted By: Ezzett

Re: How to display text with different resolutions? - 04/18/17 10:32

That's a general problem. When I'm creating Android apps I have to create many different layouts. For different display sizes, for landscape and normal mode and for different pixel densities. It's a pain.
Posted By: jenGs

Re: How to display text with different resolutions? - 04/18/17 14:03

you could use a bitmap font. They can be scaled. But of course they are forced monospaced .
Posted By: Ayumi

Re: How to display text with different resolutions? - 04/18/17 18:41

One way would be to change the font at runtime (with Window Fonts).

FONT* font = ...define default

... and change it, after resolution is changed

font = font_create("Arial#14"); -> if 1024
font = font_create("Arial#12"); -> if 800 (i.e)
Posted By: txesmi

Re: How to display text with different resolutions? - 04/19/17 05:07

If you own a commercial or higher license, you might render the panels of the largest resolution over their render targets, scale them down by a shader and show those downsampled bitmaps on other panels. Buttons and sliders should be set on last panels.
Posted By: Dooley

Re: How to display text with different resolutions? - 04/22/17 20:46

Originally Posted By: Ayumi
One way would be to change the font at runtime (with Window Fonts).

FONT* font = ...define default

... and change it, after resolution is changed

font = font_create("Arial#14"); -> if 1024
font = font_create("Arial#12"); -> if 800 (i.e)


Hmmmm.... I can't seem to get this to work. Have you done this successfully?
Posted By: Ayumi

Re: How to display text with different resolutions? - 04/22/17 22:59

Sure

Code:
#include <acknex.h>
#include <default.c>
#include <atypes.h>
#include <d3d9.h>
#include <litec.h>

// Call this, if your font is not default Window Font like Arial...
void AddFontType(STRING* name)
{
 	int res = AddFontResource(name);
   if(!res)
        printf("Font %s not found....", name);
}

// ...in Main function
AddFontType("XerosTheorem.ttf");

// Declare your Fonts
FONT* FontMenuMain = "Xero's Theorem#36";
FONT* FontMenuSub = "Xero's Theorem#28";


// Call this after switched Resolution
// MnuSettings.Resolution is an integer in a struct (7,8,9...)
// Override Fonts 
void CreateFont()
{
	// Fonts für den Auflösungswechsel neu erstellen
	
	switch(MnuSettings.Resolution)
	{
		case 1:
		case 2:
			FontMenuMain = font_create("Xero's Theorem#29");
			FontMenuSub = font_create("Xero's Theorem#23");	
			break;
		
		case 3:
			FontMenuMain = font_create("Xero's Theorem#36");
			FontMenuSub = font_create("Xero's Theorem#28");			
			break;
	}	
}


// Use it at runtime like this...
pan_setdigits(MnuPMainScreen, mainDigNum[0], mainDigPosXY[0][0],mainDigPosXY[0][1],StrBtnMnuMission, FontMenuMain,1,0);

Posted By: Dooley

Re: How to display text with different resolutions? - 04/24/17 03:49

Thanks, I will try this out!
© 2024 lite-C Forums