I am having some difficulties trying to integrate Pyimgui with pygame scene.
I am currently following this tutorial for the 3D pygame Scene https://github.com/ax-va/PyOpenGL-Pygame-Stemkoski-Pascale-2021/blob/main/py3d/core/base.py
and I am using pyimgui-pygame example from https://github.com/pyimgui/pyimgui/blob/master/doc/examples/integrations_pygame.py
I have tried changing the base of the 3D engine code like this
import pygame
import sys
from py3d.core.input import Input
from py3d.core.utils import Utils
from imgui.integrations.pygame import PygameRenderer
import imgui
class Base:
def __init__(self, screen_size=(512, 512)):
# Initialize all pygame modules
pygame.init()
# Indicate rendering details
display_flags = pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE
# Initialize buffers to perform antialiasing
pygame.display.gl_set_attribute(pygame.GL_MULTISAMPLEBUFFERS, 1)
pygame.display.gl_set_attribute(pygame.GL_MULTISAMPLESAMPLES, 4)
# Use a core OpenGL profile for cross-platform compatibility
pygame.display.gl_set_attribute(pygame.GL_CONTEXT_PROFILE_MASK, pygame.GL_CONTEXT_PROFILE_CORE)
# Create and display the window
self._screen = pygame.display.set_mode(screen_size, display_flags)
# Set the text that appears in the title bar of the window
pygame.display.set_caption("Graphics Window")
# Determine if main loop is active
self._running = True
# Manage time-related data and operations
self._clock = pygame.time.Clock()
# Manage user input
self._input = Input()
# number of seconds application has been running
self._time = 0
# Print the system information
Utils.print_system_info()
imgui.create_context()
self.impl = PygameRenderer()
self.io = imgui.get_io()
self.io.display_size = screen_size
@property
def delta_time(self):
return self._delta_time
@property
def input(self):
return self._input
@property
def time(self):
return self._time
@time.setter
def time(self, value):
self._time = value
def initialize(self):
""" Implement by extending class """
pass
def update(self):
""" Implement by extending class """
pass
def run(self):
# Startup #
self.initialize()
# main loop #
while self._running:
# process input #
self._input.update()
if self._input.quit:
self._running = False
# seconds since iteration of run loop
self._delta_time = self._clock.get_time() / 1000
# Increment time application has been running
self._time += self._delta_time
# Update #
self.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
self.impl.process_event(event)
imgui.new_frame()
if imgui.begin_main_menu_bar():
if imgui.begin_menu("File", True):
clicked_quit, selected_quit = imgui.menu_item(
"Quit", 'Cmd+Q', False, True
)
if clicked_quit:
exit(1)
imgui.end_menu()
imgui.end_main_menu_bar()
imgui.show_test_window()
imgui.begin("Custom window", True)
imgui.text("Bar")
imgui.text_colored("Eggs", 0.2, 1., 0.)
imgui.end()
# note: cannot use screen.fill((1, 1, 1)) because pygame's screen
# does not support fill() on OpenGL sufraces
imgui.render()
self.impl.render(imgui.get_draw_data())
# Display image on screen
pygame.display.flip()
# Pause if necessary to achieve 60 FPS
self._clock.tick(60)
# Shutdown #
pygame.quit()
sys.exit()
The normal scene without Pyimgui is Scene before Pyimgui
After implementing this code Scene after Pyimgui
it would be great if i could have some guidance on how to make pyimgui works with pygame 3D scene.