
from panda3d.core import NodePath, loadPrcFileData
loadPrcFileData('','copy-texture-inverted 1')
from direct.actor.Actor import Actor
from direct.showbase.ShowBase import ShowBase

from imgui_bundle import imgui, imgui_ctx

import p3dimgui

class MyApp(ShowBase):
    def  __init__(self):
        ShowBase.__init__(self)

        # Install Dear ImGui
        p3dimgui.init()

        self.mybuffer = self.win.makeTextureBuffer("My Buffer", 512, 512)
        self.mytexture = self.mybuffer.getTexture()
        self.texref = self.imgui.loadTexture(self.mytexture)
        self.mybuffer.setSort(-100)

        self.mycamera = self.makeCamera(self.mybuffer)
        self.myscene = NodePath("My Scene")
        self.mycamera.reparentTo(self.myscene)

        self.panda = Actor('models/panda.egg', {'walk': 'models/panda-walk.egg'})
        self.panda.loop('walk')
        self.panda.reparentTo(self.myscene)
        self.panda.setPosHpr((0.00, 31.70, -4.65), (-29.25, 25.55, 12.90))
        self.panda.place()

        self.accept('imgui-new-frame', self.draw)

    def draw(self):
        with imgui_ctx.begin("A Panda", flags=imgui.WindowFlags_.always_auto_resize.value):
            imgui.image(self.texref, (512, 512))

app = MyApp()
app.run()
