Changing resolution of the screen without changing the screensize

Since setSize() changes the actual size of the screen, would it be possible to make the screen the same size, but render at a lower resolution? I don’t want to make the screen fullscreen because I cant get out of it while its in fullscreen.

You can use the render to a texture of the required size, then stretch the size at your discretion.

would it be like in this manual. also, would you be able to change the texture size while it is running?

It’s easy to check.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import NodePath

class ScreenSize(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)
        base.set_background_color((0, 0, 0, 1))

        self.buffer = base.win.make_texture_buffer("my screen", 64, 64)

        altRender = NodePath("my render")

        altCam = base.make_camera(self.buffer)
        altCam.reparent_to(altRender)
        altCam.set_pos(0, -10, 0)

        teapot = loader.load_model('teapot')
        teapot.hprInterval(1.5, (360, 360, 360)).loop()
        teapot.set_pos(0, 0, -1)
        teapot.reparent_to(altRender)

        plane = loader.load_model('plane.bam')
        plane.set_p(90)
        plane.reparent_to(aspect2d)
        plane.set_texture(self.buffer.get_texture(), 1)

        base.accept("space", self.resize)

    def resize(self):
        self.buffer.set_size(1024, 1024)

test = ScreenSize()
test.run()

plane.bam (1.1 KB)

when I implemented this, the teapot didnt show up when i reparented it to altRender, do I also need to reparent something to the alt cam so I can see whats reparented to it?

I don’t think that you have to parent anything to the camera, no.

Let me ask: Did you implement it as shown in serega’s code, above? Because that code appears to work on my end.

yes I did, I also just reparented altRender to render and it showed up, but it wasn’t at a lower resolution.

This much is, I think, to be expected: being a child of “render”, it would be rendered by the default camera, and so wouldn’t be subject to the offscreen buffer that handles the downscaling.

Could you show your version of the code, please? (Or, if it’s part of a larger program, the relevant portions.) That might help us to uncover what the problem might be.

here is the function that makes the screen

def makeScreen(self):
    self.height=base.pipe.getDisplayHeight()
    self.width=int((self.height/3)*4)
    #sets panda window size to display size
    self.wp.setSize(self.width,self.height)
    
    #chnges name of window
    self.wp.setTitle("Duckwars: Beaks of Rage")
    #sets fullscreen, not impemended in panda3D fully yet
    #
    
    #sets changes
    base.win.requestProperties(self.wp)
    #makes buffer
    self.buffer=base.win.make_texture_buffer("my screen",64,64)

    altRender=NodePath("my render")
    altRender.reparent_to(render) #doesnt show up without this line of code
    
    #makes camera for buffer
    altCam=base.make_camera(self.buffer)
    altCam.reparent_to(altRender)
    altCam.set_pos(0,0,0)
    
    #makes teapot spin in renderer
    teapot = loader.load_model("teapot")
    #teapot.hprInterval(1.5, (360, 360, 360)).loop()
    teapot.set_pos(0,10,-1)
    teapot.reparent_to(altRender)

We touched on this above, but for the sake of completeness and clarity, don’t reparent “altRender” to render.

(It causes the objects below “altRender” to be visible due to being rendered by the default camera, which is not what we want in this case, I believe.)

But perhaps most fundamentally, I don’t see the code that creates a plane on which to present the offscreen buffer. (Starting in serega’s code from “plane = <...>”.)

You see, this approach works by first rendering the object to an offscreen buffer, and then using that buffer as a texture to apply to a quad. The quad is in turn attached to the standard scene-graph–in this case the 2d portion thereof–which is what causes it to be rendered.

Without the quad, the object is presumably still rendered–but nothing is done with that render and thus it’s not seen.

1 Like

I see. thank you for clarifying that for me! I put the plane there and it worked! sorry for not understanding how the code worked.

2 Likes

Not a problem! I suspect that we all miss things sometimes. :slight_smile: