Any idea why the aspect ratio is not maintained when I set the size of the window to 800 x 600 and when I use 1600 x 1200.
winProps = WindowProperties()
Am I missing something in terms of adjusting the resolution. Looks like the actual canvas is not being resized
aspect ratio should be calculated like this:
if canvas is not resized, you may need to call base.win.getDisplayRegions(), then adjust the size of each display region.
I’ve made some test with the camera and lens, and it looks like the base lens cannot be changed.
Instead, try creating a new lens (you probably want a PerspectiveLens) and attaching it to the base camera:
winProps = WindowProperties()
lens = PerspectiveLens()
Hope it helps!
How you adjust the dimensions of an existing display region? I tried setAspectRation but this method is not available in the DisplayRegion class.
I did try this method on the lens but I am still getting the same problem
So it looks like it is a problem with the DisplayRegion which is still at 800x600, how to change it without creating a new one?
you should have the ‘reference’ documentation of Panda3d by you.
setAspectRatio method is in Lens class, while display region is another class. display region class should have a setDimension method.
also, if you use python, in interactive mode, you can type dir(base.camLens) to see what you can call on the Lens object. the same applies to any other python object.
Panda should automatically adjust the display regions and aspect ratio of a window that changes size. There should be no need for you to do it manually. Doing so may interfere with Panda’s mechanism.
If this is not the behaviour you’re seeing, there may be a bug in Panda. Which version of Panda are you using, and on which platform?
Note that Python sees your division as an integer division:
There should be no issues with changing the lens associated with base.cam, but there is also no reason to do so in your case, since Panda automatically adjusts the aspect ratio of whatever lens is stored in base.camLens.
I tried a couple of things including using OpenWindow for a new window.
Does setting the width and height of a new window through the WindowProperties. What I need to understand is how setting the size of a brand new window automatically sets its aspect ratio and if so, how can size of the canvas in that window (which I assume is based on the aspect ratio) be adjusted.
fbProps = FrameBufferProperties.getDefault()
win = base.openWindow(scene = base.render, aspectRatio = MyNewAspectRatio, props = winProps, type = 'onscreen', keepCamera = False, makeCamera = True, requireWindow = True)
It might help for you to look in the ShowBase.py source code to see how this happens. ShowBase listens to “window-event”, and calls base.windowEvent(), which calls adjustWindowAspectRatio, which calls base.camLens.setAspectRatio.
This will not apply to a custom window opened by openWindow(), only to the default window.