|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +import glfw |
| 3 | +import OpenGL.GL as gl |
| 4 | + |
| 5 | +import imgui |
| 6 | +from imgui.integrations.glfw import GlfwRenderer |
| 7 | +# from testwindow import show_test_window |
| 8 | +import implot |
| 9 | + |
| 10 | + |
| 11 | +def main(): |
| 12 | + ctx = imgui.create_context() |
| 13 | + implot.create_context() |
| 14 | + implot.set_imgui_context(ctx) |
| 15 | + |
| 16 | + window = impl_glfw_init() |
| 17 | + impl = GlfwRenderer(window) |
| 18 | + |
| 19 | + while not glfw.window_should_close(window): |
| 20 | + glfw.poll_events() |
| 21 | + impl.process_inputs() |
| 22 | + |
| 23 | + imgui.new_frame() |
| 24 | + |
| 25 | + if imgui.begin_main_menu_bar(): |
| 26 | + if imgui.begin_menu("File", True): |
| 27 | + |
| 28 | + clicked_quit, selected_quit = imgui.menu_item( |
| 29 | + "Quit", 'Cmd+Q', False, True |
| 30 | + ) |
| 31 | + |
| 32 | + if clicked_quit: |
| 33 | + exit(1) |
| 34 | + |
| 35 | + imgui.end_menu() |
| 36 | + imgui.end_main_menu_bar() |
| 37 | + |
| 38 | + |
| 39 | + imgui.begin("Custom window", True) |
| 40 | + imgui.text("Bar") |
| 41 | + imgui.text_ansi("B\033[31marA\033[mnsi ") |
| 42 | + imgui.text_ansi_colored("Eg\033[31mgAn\033[msi ", 0.2, 1., 0.) |
| 43 | + imgui.extra.text_ansi_colored("Eggs", 0.2, 1., 0.) |
| 44 | + imgui.end() |
| 45 | + |
| 46 | + # show_test_window() |
| 47 | + imgui.show_test_window() |
| 48 | + implot.show_demo_window() |
| 49 | + |
| 50 | + gl.glClearColor(1., 1., 1., 1) |
| 51 | + gl.glClear(gl.GL_COLOR_BUFFER_BIT) |
| 52 | + |
| 53 | + imgui.render() |
| 54 | + impl.render(imgui.get_draw_data()) |
| 55 | + glfw.swap_buffers(window) |
| 56 | + |
| 57 | + impl.shutdown() |
| 58 | + glfw.terminate() |
| 59 | + |
| 60 | + |
| 61 | +def impl_glfw_init(): |
| 62 | + width, height = 1280, 720 |
| 63 | + window_name = "minimal ImGui/GLFW3 example" |
| 64 | + |
| 65 | + if not glfw.init(): |
| 66 | + print("Could not initialize OpenGL context") |
| 67 | + exit(1) |
| 68 | + |
| 69 | + # OS X supports only forward-compatible core profiles from 3.2 |
| 70 | + glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3) |
| 71 | + glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3) |
| 72 | + glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) |
| 73 | + |
| 74 | + glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, gl.GL_TRUE) |
| 75 | + |
| 76 | + # Create a windowed mode window and its OpenGL context |
| 77 | + window = glfw.create_window( |
| 78 | + int(width), int(height), window_name, None, None |
| 79 | + ) |
| 80 | + glfw.make_context_current(window) |
| 81 | + |
| 82 | + if not window: |
| 83 | + glfw.terminate() |
| 84 | + print("Could not initialize Window") |
| 85 | + exit(1) |
| 86 | + |
| 87 | + return window |
| 88 | + |
| 89 | + |
| 90 | +if __name__ == "__main__": |
| 91 | + main() |
0 commit comments