I’m trying to load .png (non-square) images without using a square aspect ratio. Even tho I set the following panda3d config variables, the textures are still loaded (and transformed) to a square aspect ratio. I’m using the OnscreenImage() class to render the image.
I would like to render the non-square image in it’s original aspect ratio. Is there something I need to do extra to achieve this?
In short, and if I’m not much mistaken, the issue isn’t that the texture is being changed to be square, but rather that the geometry being used by OnscreenImage is square.
As a result, the texture ends up being stretched across square geometry.
The solution, then, is to scale the OnscreenImage such that its scale matches the aspect ratio of the texture.
Now, that of course calls for knowing the aspect ratio of the texture. Presuming that you don’t want to hard-code this, I see two ways of finding it programmatically:
Either way, you thus end up with a value that can be applied to the x- or z- scale of the OnscreenImage, as applicable.
The two config variables that you mentioned are unrelated to this, I believe; they simply allow you to have textures whose dimensions are not powers-of-two in length, whether square or non-square.
(Although I’m not sure, offhand, of whether the approaches that I outlined above might gain complications should you in fact have images with non-power-of-two dimensions.)
As a small addition to this, I suggest you use getOrigFileXSize() (and YSize) on the Texture object to retrieve the image size prior to scaling to a power-of-2 size, so that it’ll give the same result no matter whether you have power-of-2 scaling enabled or disabled.
You can pass the loaded texture object directly to OnscreenImage, so you end up loading the file only once.