It is either I am doing something wrong to show Text1 and Text2 in the new window or there is a gap in my understading on how the same TextNodes can be placed in the multiple windows.
One thing is definitely missing in your code: nowhere do you set the actual text to be rendered . You need to call TextNode.setText() if you want to see your text.
And do you really want your text to be placed in the new scene as a 3D object? If not, then giving both TextNodePaths a different Y-value will not make any difference; they will still have the same position on screen. More importantly, your second window will need its own 2D layer, similar to render2D and aspect2d, as explained here, to which you can then copy your TextNodePaths from base.aspect2d, using TextNodePath.copyTo().
Forgive me if I misunderstood what you’re trying to do exactly, because it isn’t all that clear to me - the more info you give, the better we can help you .
Basically I think what I need is to know how to switch the default ‘render’ or ‘render2d’ to become attached to the second window (and subsequent new windows) so the TextNode can be rendered also in the second window with a different value.
I am already able to render my procedural model in each window with no problem but for some reason I can’t seem to do the same for the TextNodes as all of them are rendered in the first window only.
Could you describe in a bit more detail what exactly you’re trying to do?
The code you showed doesn’t seem to make a lot of sense, as it first assigns base.cam2d to the display region, but then overrides that setting immediately by setting it to base.cam. If you remove the last setCamera line, it should display render2d in both windows.
I don’t think it’s possible to make one and the same TextNode show a different text depending on what window it is rendered to… A different TextNode for each window will be needed I think.
Which brings us to the next point:
Unless I’m missing something, that doesn’t seem to be the case; according to the API:
That’s the default render2d being mentioned, right? And the following code sample seems to support that, as it shows the same TextNode in both windows (at least for me, it does):
from panda3d.core import *
from direct.showbase.ShowBase import ShowBase
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
# open a second window with its own camera
props = WindowProperties.getDefault()
props.setTitle("Second Window")
my_scene = NodePath("my_scene")
win2 = self.openWindow(props=props, type='onscreen', keepCamera=False,
scene=my_scene, makeCamera=True, requireWindow=True)
dr = win2.makeDisplayRegion()
dr.setCamera(self.makeCamera2d(win2))
text = TextNode("my_text")
text.setText("This is my text")
self.text_np = self.aspect2d.attachNewNode(text)
self.text_np.setScale(.07)
self.text_np.setPos(-.5, 0., -.3)
app = MyApp()
app.run()
On my own desktop PC, replacing “dr.setCamera(self.makeCamera2d(win2))” with “dr.setCamera(self.cam2d)” in the above code gives the following OpenGL error and makes the Python interpreter crash (happens also on my crappy old laptop, but that’s no longer surprising):
:display:gsg:glgsg(error): GL_INVALID_OPERATION error generated. Not a valid sam
pler name.
Hmm, yes, makeCamera2d does seem to create under render2d, and for some reason it doesn’t take a scene= parameter to override this like makeCamera does. However, all you have to do is reparent the return value to a new scene graph of your choosing.
All it does, though, is create a new display region, camera and lens, and reparents the camera to render2d.
Hmm, the sampler error seems a bit worrying, though it’s probably unrelated to the matter of using a 2d camera.
I actually got that error after adding “loadPrcFileData(‘’, ‘gl-debug true’)” to the top of that code sample; before that (and without “scene=my_scene” in the self.openWindow call), the code was spamming the following error message in the command console (closing the second window stops the error messages):
:display:gsg:glgsg(error): at 2954 of c:\buildslave\sdk-windows-i386\build\panda
\src\glstuff\glGraphicsStateGuardian_src.cxx : invalid operation
:display:gsg:glgsg(error): An OpenGL error (invalid operation) has occurred. Se
t gl-debug #t in your PRC file to display more information.
Although there is no crash while those messages are spamming, the second window doesn’t show the TextNode (or anything else parented to either aspect2d or render2d).
And now I found out that without any renderable NodePaths parented to either aspect2d or render2d, there is no error/crash (a TextNode without text or any empty NodePath causes no problems, while attaching e.g. the smiley model does).
Maybe you could file a separate bug report on this with the full log of “notify-level-glgsg debug” and “gl-debug true”; it doesn’t seem related to the matter of TextNode in multiple windows.