ioxu / boxer

workflow tool
MIT License
1 stars 0 forks source link

pyglet and imgui #1

Closed ioxu closed 11 months ago

ioxu commented 1 year ago

test how to use pyimgui and pyglet together

pip install imgui[pyglet]

https://discord.com/channels/438622377094414346/1150795529035448322

pyglet Discord user Anudavai

import pyglet
import imgui
from imgui.integrations.pyglet import create_renderer

# ==== init ====
window = pyglet.window.Window(800, 600, "Pyglet Window")
imgui.create_context()
renderer = create_renderer(window) # pyglet renderer for imgui
# ==============

circle = pyglet.shapes.Circle(window.width//2, window.height//2, 100, color=(50, 70, 150))

@window.event
def on_draw():
    window.clear()

    # pyglet draw
    circle.draw()

    # ==== imgui draw ====
    imgui.new_frame()

    # widgets:
    imgui.show_demo_window()

    imgui.render()
    renderer.render(imgui.get_draw_data())
    # =====================

pyglet.app.run()
renderer.shutdown()
ioxu commented 1 year ago

immediate observations:

done:

https://github.com/ioxu/boxer/blob/3ba13b9357a0692cddc571678aa97a0dfc2bacbe/boxer/application.py#L54

https://github.com/ioxu/boxer/blob/3ba13b9357a0692cddc571678aa97a0dfc2bacbe/boxer/application.py#L128

https://github.com/ioxu/boxer/blob/3ba13b9357a0692cddc571678aa97a0dfc2bacbe/boxer/application.py#L180

ioxu commented 11 months ago

all imgui stuff is in

boxer/ui.py