Displaying text via TextNode

I’m trying to display some text onto the screen via text node. What I want to eventually do is have a little message appear on screen informing the user they have pressed a key when they press it. I also want to display the current time. To display text the manual says to use the following code:

text = TextNode(‘node name’);
text.setText(“Every day in every way I’m getting better and better.”);
textNodePath = aspect2d.attachNewNode(text);
textNodePath.setScale(0.07);

and “To use a TextNode, simply create one” - but doesn’t say how. I tried changing the code to:

TextNode text = TextNode(‘name’)
text.setText(“Every day in every way I’m getting better and better.”)
textNodePath = aspect2d.attachNewNode(text)
textNodePath.setScale(0.07)

but I get the errors:

1>.\Panda3D Tute01.cpp(231) : error C2440: ‘’ : cannot convert from ‘int’ to ‘TextNode’
1> No constructor could take the source type, or constructor overload resolution was ambiguous
1>.\Panda3D Tute01.cpp(231) : error C2512: ‘TextNode’ : no appropriate default constructor available
1>.\Panda3D Tute01.cpp(232) : error C2039: ‘setText’ : is not a member of ‘TextNode’
1> e:\uni programs\panda3d-1.6.2\include\textNode.h(52) : see declaration of ‘TextNode’
1>.\Panda3D Tute01.cpp(233) : error C2065: ‘aspect2d’ : undeclared identifier
1>.\Panda3D Tute01.cpp(233) : error C2228: left of ‘.attachNewNode’ must have class/struct/union
1> type is ‘‘unknown-type’’
1>.\Panda3D Tute01.cpp(234) : error C2039: ‘setScale’ : is not a member of ‘NodePath’
1> e:\uni programs\panda3d-1.6.2\include\nodePath.h(150) : see declaration of ‘NodePath’
1>Build log was saved at “file://g:\02 Game Enhancement Technologies\GET - Assignment 1\Panda3D Tute01\Panda3D Tute01\Release\BuildLog.htm”
1>Panda3D Tute01 - 6 error(s), 22 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

What should I do?

Just do exactly as stated in the manual:

text = TextNode(‘node name’); # You are creating a textnode here
text.setText(“Every day in every way I’m getting better and better.”);
textNodePath = aspect2d.attachNewNode(text);
textNodePath.setScale(0.07);

I pasted this code in the ball-in-maze sample and it works.

Oh and remember

from pandac.PandaModules import TextNode

at the top

Remember to rather post in the “Scripting Issues” thread if you have questions about code.

Enjoy :slight_smile:

1 Like

"Remember to rather post in the “Scripting Issues” thread if you have questions about code. "

oops, sorry about that. I shall remember

“Code:
from pandac.PandaModules import TextNode”

Is that Python code? (I’m using C++)

That is indeed Python code. Pointing out that you’re using C++ is perhaps a useful tidbit to mention in the beginning of your post. (C++ questions should generally be posted in the C++ forum, rather than under Scripting Issues.)

We are gradually in the process of translating the Python references in the manual into C++ for C++ users, but this is still incomplete. In the meantime, you should learn how to translate Python code to C++ code. The above snippet translates like this:

PT(TextNode) text = new TextNode("node name"); // You are creating a textnode here
text->set_text("Every day in every way I'm getting better and better.");
NodePath textNodePath = window->get_aspect_2d().attach_new_node(text);
textNodePath.set_scale(0.07); 

where window is the pointer to your WindowFramework object.

David

Argh, me stupid! It took me a few hours to get this, because I had no internet access. I just couldnt fiddle out why the damn align didnt work with the onscreentext but worked with an older code. I had an “pandamodules import *”… Really, Panda needs a downloadable reference… Maybe the manual topic on textnodes is lacking this too?

There is, check the download page.

Hi,
i am using the code panda with c++.
I successfully display buttons and get interaction, so the engine works ok for now.

The problem is that i try to display some very basic text and it does not work. I use the code sample below (I’ve taken it from the website).

On the screen I get a very blur image - you can check it out at:
tinyurl.com/y9urhvv
or
picasaweb.google.com/appwizz/Scr … 4327902690

Any help is greatly appreciated.

Thank you.
Best regards

framework.open_framework(argc, argv);
framework.set_window_title(“My Panda3D Window”);
window = framework.open_window();

if (window != (WindowFramework *)NULL) {
nout << “Opened the window successfully!\n”;

PT(TextNode) text = new TextNode(“node name”); // You are creating a textnode here
text->set_text(“Every day in every way I’m getting better and better.”);
NodePath textNodePath = window->get_aspect_2d().attach_new_node(text);
textNodePath.set_scale(0.07);

 window->loop_animations();
 framework.main_loop();

} else {
nout << “Could not load the window!\n”;
}
//close the window framework
framework.report_frame_rate(nout);
framework.close_framework();

Hmm, did you compile this version of Panda yourself, or is it the standard distribution? I wonder if something went wrong with the default font that is compiled into Panda.

Try setting this in your Config.prc file:

text-default-font /c/my/panda/dir/cmss12.egg

where /c/my/panda/dir is the path to wherever your cmss12.egg file is stored. Or, add code something like this:

PT(TextFont) font = FontPool::load_font("/c/my/panda/dir/cmss12.egg")
nassertv(font != (TextFont *)NULL);
text->set_font(font);

David

Hey David

thank you for the suggestions.
First I use panda on Ubuntu, as installed with the deb package, so I did not compile anything manually.

Secondly, I’ve tried the suggested piece of code, as follows:

PT(TextNode) tn = new TextNode("instructions");
tn->set_text("hello world");
PT(TextFont) font = FontPool::load_font("./cmss12.egg");
if (font != (TextFont *)NULL)
{
	tn->set_font(font);
	printf("font not null\n");
}
else
	printf("null font\n");

I’ve copied the file cmss12.egg.pz in the local folder, such a way I am sure it finds is. Also the program displays “font not null”, so I presume it loads something.

Still the displayed image is the same blued one.

Any hints?

I am not sure where to find the Config file for ubuntu, I’ve searched the /etc directory and the /usr/share/panda3d and did not find it.

Thank you.
Best regards,
vlad

The configuration file is /etc/Config.prc.
Which version of Ubuntu are you using, and what video card do you have? I recall that on Ubuntu Jaunty there were some problems with Intel cards.

Hi
i installed the Panda Hardy Heron, that is Ubuntu 8.04
I currently use Ubuntu 9.10 (Karmic Koala).

The video card: Intel Corporation Mobile GM965/GL960 Integrated Graphics Controller (rev 03) Subsystem: ASUSTeK Computer Inc. Device 14e2

Any hints?

Thank you.
vlad

Hmm. What happens if you run “pview -a”. Do you see the text “No animation” on screen, or is it a blurred mess? How about your other models, do they all render correctly?

I have seen driver issues with mipmapping before. Try putting:

text-minfilter nearest

in your Config.prc file.

Also, to rule out driver issues altogether, try running with tinydisplay. This might not work, as I’ve heard some Ubuntu issues are unable to run tinydisplay with the 1.6.2 version of Panda, but it’s worth a try anyway. Put:

load-display tinydisplay

in your Config.prc file.

David

Hey David

thank you so much for your support, I do appreciate it a lot!

I’ve tried pview -a, it also displays a messy text before and after inserting those 2 lines in Config.prc. By the way, I inserted the 2 lines at the end of the file, I presume the order doesn’t matter.

I do succeed in loading textures, so I do not understand how it can be a driver problem?! Can I try anything else to make it work, or at least identify the problem?

This is the result of pview - tinyurl.com/yaenyo9

Thank you.
Best regards
vlad

It might matter if there is already a “load-display pandagl” line in that file. The tinydisplay line must appear before that (or comment out or remove the pandagl line) in order for it to be respected.

It is certainly mysterious, but textures have lots of different rendering modes, and it’s not uncommon for a driver to succeed in most modes, but fail with one or two of them. If it happens to be failing with one of the modes that we use for rendering text, then you get this sort of behavior; and that’s what I’m trying to home in on.

The first guess was that it was mipmapping, since we normally enable mipmapping on text textures, but it might not be enabled on your other textures. That doesn’t appear to do it. The next guess might be the single-channel alpha texture. This is uncommon in other textures, but it’s the way we load text textures. Try hand-editing the cmss12.egg file. Look for the line near the top like this:

  <Scalar> format { alpha }

and replace it with this:

  <Scalar> format { luminance }

Be sure to keep the text-default-font line in your Config.prc file. Does that have an effect?

Also, what does it look like if you pview the cmss12.egg file directly?

David

Hi David,

  1. load-display tinydisplay - does not work, it gives the following. As far as i can see from other posts on the forum, this may happen, but am not sure what is the reason for it.

:display(warning): Unable to load: /usr/lib/panda3d/libtinydisplay.so: undefined symbol: XAllocSizeHints
Known pipe types:
(all display modules loaded.)
No graphics pipe is available!
Your Config.prc file must name at least one valid panda display
library via load-display or aux-display.

  1. Try hand-editing the cmss12.egg file.
    I googled the internet about how to uncompress the cmss12.egg.pz file, and i didn’t find anything. Any clues? (The closest thing i got were some functions from Panda itself that seem to decode it.)

  2. what does it look like if you pview the cmss12.egg file directly?
    I am not sure what you mean. As i mentioned i do not have cmss12.egg but cmss12.egg.pz that seems to be a binary version of the font file.

Thank you.
Best regards
vlad

  1. That’s a build error in 1.6.2, it has been fixed in the current CVS version of Panda3D.
  2. Use the ‘punzip’ utility that ships with Panda.
  3. You should call this on the command prompt:
pview path/to/your/cmss12.egg.pz

Alternatively, rightclick the file and use ‘Open with’.

Thank you.

  1. I unpacked the pz file. And changed it as David was suggesting. No changes.

  2. also running pview cmss12.egg shows a small white point in the middle of the screen that moves very very slow. I presume this is not the intended demo :slight_smile: Also it seems i can move the small dot with the mouse.

  3. do you think they will consider updating the deb package soon to 1.6.2? or should i just go for building panda from sources asap?!

Thank you.
Best regards
vlad

Are you on amd64 architecture? If so, I can email you a cvs snapshot build.

Hi rdb,
nope i am 32.
Thank you for the idea.

PS: as i can see it now, my only alternative is to do the build. If you guys have any other thoughts, i appreciate it.

Best regards
vlad

It smells to me like a video driver issue. I’ve heard reports that Intel drivers were buggy on Ubuntu. Have you tried upgrading your drivers?

Building from source will only allow you to use “tinydisplay”, which will give you software rendering. Not really an ideal solution.