Retrieving pixel2d in C++

Hi guys! First of all, I’m new to Panda3D and sorry for any typos.

Well, I’ve been reading the manual for a couple days and in the Scene Graph Manipulations section, it is stated that there is a child of render2d called pixel2d. The thing is I just can’t see a way to access it.

Tried to look for any WindowFramework::get_pixel2d() method, with no success. I also tried to search for “pixel2d” in the contents of Panda3D’s source code files, and still no results.

Is pixel2d really there? How can I retrieve it, so that I can put a NodePath to be drawn using it?

Thanks in advance.

The code that creates pixel2d is only in Python. However, it’s trivially simple, and you can create your own pixel2d in C++. The Python code looks like this (in

        # This special root, pixel2d, uses units in pixels that are relative
        # to the window. The upperleft corner of the window is (0, 0),
        # the lowerleft corner is (xsize, -ysize), in this coordinate system.
        xsize, ysize = self.getSize()
        self.pixel2d = self.render2d.attachNewNode(PGTop("pixel2d"))
        self.pixel2d.setPos(-1, 0, 1)
        if xsize > 0 and ysize > 0:
            self.pixel2d.setScale(2.0 / xsize, 1.0, 2.0 / ysize)


That did the work, thank you!
The only problem was to get the window’s size, as it didn’t see to be pretty straightfoward to me, but I think I got it…

The code follows, for anybody interested:

int xsize = window->get_graphics_output()->get_x_size();
int ysize = window->get_graphics_output()->get_y_size();
NodePath pixel2d = window->get_render_2d().attach_new_node( new PGTop( "pixel2d" ) );
pixel2d.set_pos( -1, 0, 1 );
if ( xsize > 0 && ysize > 0 )
   pixel2d.set_scale( 2.0 / xsize, 1, 2.0 / ysize );