Practicing with creating textures at a low level, I came to the conclusion that I was using the Texture class incorrectly. I used the read() method which overrides the previously set parameters. This is not what I want, I switched to the set_ram_image() method, however, I had difficulties.
from direct.showbase.ShowBase import ShowBase
from panda3d.core import Texture, PTAUchar, CPTAUchar
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
file = open('fon.png', mode = 'rb')
image = CPTAUchar(file.read())
#image = PTAUchar(file.read())
file.close()
tex = Texture("Texture")
tex.setup_2d_texture(256, 256, Texture.T_unsigned_byte, Texture.F_rgba)
tex.set_ram_image(image)
app = MyApp()
app.run()
I get such an error, which is completely not informative.
D:\Code\Blank>D:\Panda3D-1.10.13-x64\python\python.exe main.py
Known pipe types:
wglGraphicsPipe
(all display modules loaded.)
Assertion failed: compression != CM_off || image.size() == do_get_expected_ram_image_size(cdata) at line 5652 of c:\buildslave\sdk-windows-amd64\build\panda\src\gobj\texture.cxx
Traceback (most recent call last):
File "main.py", line 18, in <module>
app = MyApp()
File "main.py", line 16, in __init__
tex.set_ram_image(image)
AssertionError: compression != CM_off || image.size() == do_get_expected_ram_image_size(cdata) at line 5652 of c:\buildslave\sdk-windows-amd64\build\panda\src\gobj\texture.cxx