Problem Rendering onto display regions

I am looking to render scenes on the display region whose size is of my image(flags to do so have been set)
however, there is no scene rendered on the region. SetClearColor function works and changes the color of the display region but nothing rendered from the camera view

code:

    self.img_width, self.img_height = self.get_image_dimensions(example_image_path)
    
    # Find all cameras and create render buffers
    self.render_buffers = {}
    self.cameras = self.find_all_cameras()
    for camera_path in self.cameras:
        buffer = self.create_render_buffer(camera_path)
        self.render_buffers[camera_path.getName()] = buffer

    # Add the task to render to textures
    self.taskMgr.add(self.render_to_textures, "render_to_textures")
    self.accept("v", self.bufferViewer.toggleEnable)
    self.bufferViewer.setPosition("llcorner")
    self.bufferViewer.setCardSize(1.0, 0.0)

    
def find_all_cameras(self):
    cameras = []
    for camera_path in self.render.findAllMatches("**/*"):
        node = camera_path.node()
        if isinstance(node, Camera):
            
            print(node.getLens().getNear())
            print(node.getLens().getFov() )

            camera_name = camera_path.getName()
            if camera_name.startswith("Camera_"):
                cameras.append(camera_path)
                node.active= False
                break
    return cameras


def create_render_buffer(self, camera_path):
    #camera_path.hprInterval(1.5, (360, 360, 360)).loop()
    """Create a render buffer for each camera."""
    #texture = Texture()
    #texture.set_format(Texture.F_rgb8)  # Ensure the texture format is RGBA
    
    # Ensure the texture stores data in RAM
    #texture.set_compression(Texture.CM_off)  # Turn off compression
    #texture.set_keep_ram_image(True)         # Ensure RAM image is kept
    
    # Create a buffer to render into
    
    buffer = self.win.make_texture_buffer(camera_path.getName(), self.img_width, self.img_height)
    #buffer.add_render_texture(texture, GraphicsOutput.RTMCopyRam)
    
    # Create a display region and assign the camera to it
    dr = buffer.get_display_region(0)#self.win.get_display_region(0) #buffer.get_display_region(0)
    #self.win.setClearColor((0,1,0,1))
    buffer.setClearColor((1,0,1,0.5))
    print(dr)
    dr.set_camera(camera_path)
    print( camera_path.getPos(self.render) )
    #camera_path.lookAt(self.render)
    #camera_path.hprInterval(3.5, (360,720, 1850)).loop()
    smiley = self.loader.loadModel("smiley")
    smiley.reparentTo(self.render)
    smiley.setScale(1500)
    smiley.hprInterval(1.5, (360, 360, 360)).loop()
    smiley.setTwoSided(True)
    
    #self.oobe()
    print(self.render.getPos(camera_path))
    print(camera_path)
    return buffer
    def save_screenshot_from_buffer(self, buffer, filename):
    """Save screenshot directly from the buffer."""
    screenshot = PNMImage()
    
    # Get the screenshot from the buffer
    if buffer.get_screenshot(screenshot):
        # Save the screenshot to a file
        screenshot.write(filename)
        #print(f"Screenshot saved to {filename}")
    else:
        print("Failed to capture screenshot.")

def convert_pnm_to_png(self, pnm_path, png_path):
    """Convert PNM image to PNG."""
    with Image.open(pnm_path) as img:
        img.save(png_path)
    print(f"Converted PNM image to PNG: {png_path}")

def render_to_textures(self, task):
    # Force a render frame to ensure textures are populated
    self.graphics_engine.render_frame()
    self.graphics_engine.render_frame()
    self.graphics_engine.render_frame()
    
    for name, buffer in self.render_buffers.items():
        #texture = buffer.get_texture()
        
        # Save the screenshot from the buffer directly
        screenshot_filename = join(self.output_folder, f"{name}_screenshot.png")
        self.save_screenshot_from_buffer(buffer, screenshot_filename)
    
    # Continue rendering every frame
    return Task.done

All i get is grey background. the camera’S are loaded from the .bam file of my scene graph.
tried different debugs but nothing avails.
Potentially there is some issue in the create_render_buffers but unsure what…

Thank you and much appreciated

Hi, it looks like you’re confusing display regions with render-to-texture. If you want to render your scene to a texture, you can do it like this:

altBufferLoadSession = self.win.makeTextureBuffer("hello", 256, 256)
altRenderLoadSession = NodePath("new render")

#add some light
dlight = DirectionalLight('dlight')
alight = AmbientLight('alight')
dlnp = altRenderLoadSession.attachNewNode(dlight)
alnp = altRenderLoadSession.attachNewNode(alight)
dlight.setColor((0.8, 0.8, 0.5, 1))
alight.setColor((0.2, 0.2, 0.2, 1))
dlnp.setHpr(0, -60, 0)
altRenderLoadSession.setLight(dlnp)
altRenderLoadSession.setLight(alnp)

#camera:
altCam = self.makeCamera(altBufferLoadSession)
altCam.reparentTo(altRenderLoadSession)
altCam.setPos(0, -10, 0)

#add models to your scene:
traker=base.loader.loadModel("smiley.egg")
traker.reparentTo(altRenderLoadSession)
LerpHprInterval(traker, 0.8, Vec3(360,0,0),Vec3(0,0,0)).loop()

#now, render your scene to a texture, for example, the texture you'd use on a button:
startZ=0.48
imageObjectII=DirectButton(image = altBufferLoadSession.getTexture(), pos = (0.328849, 0, startZ--0.03), scale= (0.386496,0.386496,0.386496),relief=DGG.FLAT)
imageObjectII["state"]=DGG.DISABLED

#You can now position your button anywhere you'd like, which would be the same thing as
#positioning your scene anywhere you'd like on the screen!

That should do what you’re describing, if I understood you correctly. If you want to use an actual display region, instead of a render-to-texture solution, then please consult the manual here for more:
https://docs.panda3d.org/1.10/python/programming/rendering-process/display-regions

I hope this helps.