Prelude before we migrate to pyimgui[glfw]

This commit is contained in:
Joseph Ferano 2023-02-20 14:01:03 +07:00
parent 600bfbe5c8
commit b1b72d0fcc
3 changed files with 63 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/__pycache__/

61
ImguiWindow.py Normal file
View File

@ -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()

3
mm.py
View File

@ -200,8 +200,7 @@ def moon_row(id,source):
for name,(supply,ts) in source[1].items(): for name,(supply,ts) in source[1].items():
col = sg.Col([[sg.Text(name)], [sg.Button("Mine", key=("-MINE-",id,name))]]) col = sg.Col([[sg.Text(name)], [sg.Button("Mine", key=("-MINE-",id,name))]])
wbtns.append(col) wbtns.append(col)
row = [sg.Image("moon.png"), row = [sg.Image("moon.png"), sg.Column([wbtns])]
sg.Column([wbtns])]
return [sg.pin(sg.Column([row, [sg.Button("Destroy", key=("-DESTROY-",id))]], key=("-MROW-",id)))] return [sg.pin(sg.Column([row, [sg.Button("Destroy", key=("-DESTROY-",id))]], key=("-MROW-",id)))]
def get_inventory_ui(): def get_inventory_ui():