[QUESTION] Rendering text with better resolution/quality?

	PT(TextFont) FONT_UBUNTU_R = FontPool::load_font("bin/neuera/fonts/UbuntuMono-R.ttf");
	PT(DynamicTextFont) DFONT_UBUNTU_R = DCAST(DynamicTextFont, FONT_UBUNTU_R);
	DFONT_UBUNTU_R->set_pixels_per_unit(32);
	DFONT_UBUNTU_R->set_outline(LColor(0, 0, 0, 1), 1.5, 0);
	PT(TextNode) win_title = new TextNode("WndTitle");
	win_title->set_text(this->title);
	win_title->set_font(DFONT_UBUNTU_R);
	win_title->set_text_scale(.1);
	win_title->set_text_color(1, 1, 1, .65);
	win_title->set_glyph_shift(.05);
	NodePath textNodePath = window_np.attach_new_node(win_title);
	textNodePath.set_scale(.40);

Hi, is there any other way to render text with better res or quality (or maybe more sharp?) like this;
sharptext

Thanks…

You can try to set the filtering types, If you want a pixelation effect. Or experiment with the rendering mode.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import TextNode, NodePath, DynamicTextFont, Texture, TextFont

class Test(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        label = TextNode('label')
        label.set_text('Earth')
        label.set_font(DynamicTextFont('Roboto/Roboto-Italic.ttf'))

        label.font.set_render_mode(TextFont.RM_solid)
        label.font.set_minfilter(Texture.FT_nearest)
        label.font.set_magfilter(Texture.FT_nearest)
        #label.font.set_page_size(2, 2)
        #label.font.set_native_antialias(0)
        #label.font.set_anisotropic_degree(0)
        label.font.set_pixels_per_unit(64)

        label_node = NodePath(label.generate())
        label_node.set_scale(0.4)
        label_node.reparent_to(aspect2d)

test = Test()
test.run()

The code for python.

https://docs.panda3d.org/1.10/cpp/reference/panda3d.core.TextFont#_CPPv4N8TextFont10RenderModeE

Actually, I’m talking about the rendering of pixels without distortion, rather than the pixel effect. I will try the filtering options anyway. Thanks!

Depending on the resolution of the window, part of the issue may be that the pixels of your text aren’t aligned to the pixels of the screen. This may result in text-pixels straddling the borders of screen-pixels, and thus being represented by multiple of the latter.

If so, then fixing it may call for the use of the “pixel2d” NodePath (even if only for relative placement), and perhaps also care when determining the scale of your text.

Still can’t figure it :confused: i tried all rendermodes but still get bad results! Last code;

	PT(TextFont) FONT_TAHOMA = FontPool::load_font("/c/Windows/Fonts/tahoma.ttf");
	PT(DynamicTextFont) DFONT_TAHOMA = DCAST(DynamicTextFont, FONT_TAHOMA);
	DFONT_TAHOMA->set_point_size(12);
	DFONT_TAHOMA->set_space_advance(2);
	DFONT_TAHOMA->set_magfilter(SamplerState::FT_nearest);
	DFONT_TAHOMA->set_minfilter(SamplerState::FT_nearest);
	DFONT_TAHOMA->set_pixels_per_unit(64);
	DFONT_TAHOMA->set_outline(LColor(0, 0, 0, 1), 1, 0);
	
	PT(TextNode) win_title = new TextNode("WndTitle");
	win_title->set_text(this->title);
	win_title->set_font(DFONT_TAHOMA);
	win_title->set_text_scale(.5);
	win_title->set_text_color(1, 1, 1, .85);
	win_title->set_glyph_shift(0);
	NodePath win_title_np = window_np.attach_new_node(win_title);
	win_title_np.set_scale(.06);

	LVecBase3 title_pos;
	mouse_module->GlobalToAspectParentPos(window_np, 90, 28, &title_pos);
	win_title_np.set_pos(title_pos);

Result with/without outline;

The other game I referenced with same font;

Are you sure that the other game is using Tahoma…?

Looking that font up, it doesn’t appear to be a pixel-font–hence, I suspect, it not rendering well at low resolution.

[edit]
Hmm… I do now see the text at the bottom of the second image indicating that it is indeed Tahoma.

If so, then I wonder whether they aren’t doing some special processing to get usable pixel-letters from it.

Do you have a source for the picture? Perhaps they give more of an explanation there…

The other game called “Metin2” its an mmorpg. Its use Tahoma or Arial as default font;

As you said, they may be using a some special processing or render-technique im not sure but all gui is the same with any window resolution.
On the other hand, another idea came to my mind. I can use “PNImage” and “blend_sub_image” to build text as image just like my windows but its terrible idea for user inputs and probably it’ll cost a lot of performance :frowning:

I just want to do something like this;
dif

When I started writing the GUI system, I didn’t think the text part would be so difficult :smiley:

Honestly, I’d suggest that the easiest path might be to just… get actual pixel-fonts.

Oh, there will likely-enough still be some work to be done, but such should be rather easier to produce nice pixel-text from than a non-pixel-font, I imagine…

That said, I had a quick look around for the game, now that I know what it is, and I found a forum-thread that suggested to me that they’re rendering their font at a rather low resolution, but without antialiasing, thus producing a pixel-y result.

And indeed, in GIMP if I add text using the Verdana font (I’m on Linux, and so don’t have Tahoma) at a size of 9 and with antialiasing disabled, I get a pixel-y font such as you showed above.

So then, the question is that of how to get Panda to disable antialiasing of fonts!

And it looks like the offline tool “egg-mkfont” can achieve this.

Indeed, by disabling antialiasing, disabling reduction of the generated font-image, setting a low point-size, and setting a low pixels-per-unit value, I was able to produce a font-image that approximated what you seem to be after.

(See the built-in help for “egg-mkfont” to get the relevant command-line switches to do this.)

Now, the next question is that of whether this can be done with a font not pre-processed through “egg-mkfont”. And… I’m not sure. It looks like DynamicTextFont may have at least some of the required elements, but I haven’t tested it sufficiently to be confident.

(And note that, even with the above, you’d likely want to set the min- and mag- filters at the least, I imagine.)

2 Likes

Thank you for your interest. I’ll search more about this.
For now the best i can get;

	PT(TextFont) FONT_ARIAL = FontPool::load_font("/c/Windows/Fonts/arial.ttf");
	PT(DynamicTextFont) DFONT_ARIAL = DCAST(DynamicTextFont, FONT_ARIAL );
	DFONT_ARIAL->set_point_size(128);
	DFONT_ARIAL->set_space_advance(2);
	DFONT_ARIAL->set_magfilter(SamplerState::FT_nearest);
	DFONT_ARIAL->set_minfilter(SamplerState::FT_nearest);
	DFONT_ARIAL->set_pixels_per_unit(3);
	//DFONT_ARIAL->set_outline(LColor(0, 0, 0, 1), 11, 0);
	
	PT(TextNode) win_title = new TextNode("WndTitle");
	win_title->set_text(this->title);
	win_title->set_font(DFONT_ARIAL);
	win_title->set_text_scale(8);
	win_title->set_text_color(1, 1, 1, .85);
	NodePath win_title_np = window_np.attach_new_node(win_title);
	win_title_np.set_scale(.00032);


arial2

Well, at the least it might be worth trying the settings that I listed, as provided by DynamicTextFont–they might get you closer to your goal.

(Noting that antialiasing seems to be handled by both the “native antialias” setting and the “scale factor” setting in DynamicTextFont.)