# -*- coding: utf-8 -*- import glfw import OpenGL.GL as gl import time import imgui from imgui.integrations.glfw import GlfwRenderer def main(): imgui.create_context() window = impl_glfw_init() impl = GlfwRenderer(window) framecount=0 while not glfw.window_should_close(window): framecount+=1 glfw.poll_events() impl.process_inputs() 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.begin("Custom window", True) imgui.text("Runtime:") imgui.same_line() imgui.text(str(glfw.get_time())) imgui.text("Frame:") imgui.same_line() imgui.text(str(framecount)) imgui.text("Unix time:") imgui.same_line() imgui.text(str(time.time_ns() / (10 ** 9))) if imgui.button("Pause"): time.sleep(1) imgui.end() imgui.show_test_window() if (framecount % 2) == 0: gl.glClearColor(1., 1., 1., 1) else: gl.glClearColor(0., 0., 0., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) glfw.swap_buffers(window) impl.shutdown() glfw.terminate() def impl_glfw_init(): width, height = 1280, 720 window_name = "imgui camera test" 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(width), int(height), window_name, None, None ) glfw.make_context_current(window) if not window: glfw.terminate() print("Could not initialize Window") exit(1) return window if __name__ == "__main__": main()