From b1b72d0fccab83e19eb0f8ad3999ed3ce6a984d4 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Mon, 20 Feb 2023 14:01:03 +0700 Subject: [PATCH] Prelude before we migrate to pyimgui[glfw] --- .gitignore | 1 + ImguiWindow.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ mm.py | 3 +-- 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 ImguiWindow.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a348e50 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/__pycache__/ diff --git a/ImguiWindow.py b/ImguiWindow.py new file mode 100644 index 0000000..6cb55b7 --- /dev/null +++ b/ImguiWindow.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +import glfw +import OpenGL.GL as gl + +import imgui as im +from imgui.integrations.glfw import GlfwRenderer + +class ImguiWindow(): + def impl_glfw_init(self, w, h): + window_name = "minimal Imgui/GLFW3 example" + + if not glfw.init(): + print("Could not initialize OpenGL context") + exit(1) + + # OS X supports only forward-compatible core profiles from 3.2 + glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3) + glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3) + glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) + + glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, gl.GL_TRUE) + + # Create a windowed mode window and its OpenGL context + window = glfw.create_window( + int(w), int(h), window_name, None, None + ) + glfw.make_context_current(window) + + if not window: + glfw.terminate() + print("Could not initialize Window") + exit(1) + + return window + + def __init__(self, draw_fn, window_name, width, height): + im.create_context() + self.window = self.impl_glfw_init(width, height) + impl = GlfwRenderer(self.window) + + while not glfw.window_should_close(self.window): + glfw.poll_events() + impl.process_inputs() + + im.new_frame() + + draw_fn() + + gl.glClearColor(1., 1., 1., 1) + gl.glClear(gl.GL_COLOR_BUFFER_BIT) + + im.render() + impl.render(im.get_draw_data()) + glfw.swap_buffers(self.window) + + impl.shutdown() + glfw.terminate() + + + + diff --git a/mm.py b/mm.py index 3729bc2..3719853 100644 --- a/mm.py +++ b/mm.py @@ -200,8 +200,7 @@ def moon_row(id,source): for name,(supply,ts) in source[1].items(): col = sg.Col([[sg.Text(name)], [sg.Button("Mine", key=("-MINE-",id,name))]]) wbtns.append(col) - row = [sg.Image("moon.png"), - sg.Column([wbtns])] + row = [sg.Image("moon.png"), sg.Column([wbtns])] return [sg.pin(sg.Column([row, [sg.Button("Destroy", key=("-DESTROY-",id))]], key=("-MROW-",id)))] def get_inventory_ui():