async def async_main(window, config): await asyncjob.start_worker() imgui_impl = GlfwRenderer(window) renderer = WorldRenderer() app = StarboundMap(renderer) frame_size = np.ones(2) while not glfw.window_should_close(window): glfw.poll_events() if G.minimized: # do not render zero sized frame continue imgui_impl.process_inputs() frame_size = np.array(glfw.get_framebuffer_size(window)) gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0) gl.glViewport(0, 0, frame_size[0], frame_size[1]) gl.glClearColor(0.1, 0.1, 0.2, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) app.gui() glfw.swap_buffers(window) await asyncio.sleep(0) config[CONFIG_WIDTH] = str(int(frame_size[0])) config[CONFIG_HEIGHT] = str(int(frame_size[1])) imgui_impl.shutdown() imgui.shutdown()
def main(): window = impl_glfw_init() impl = GlfwRenderer(window) box1 = box2 = box3 = True while not glfw.window_should_close(window): 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("Scope Test") box1 = imgui.checkbox("Checkbox", box1)[1] with imgui.scope(2): imgui.new_line() imgui.text("Same name, different scope:") box2 = imgui.checkbox("Checkbox", box2)[1] imgui.new_line() imgui.text("Same name, same scope:") imgui.text("(This will not work right)") box3 = imgui.checkbox("Checkbox", box3)[1] imgui.end() gl.glClearColor(1., 1., 1., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() glfw.swap_buffers(window) impl.shutdown() imgui.shutdown() glfw.terminate()
def main(): window = impl_glfw_init() impl = GlfwImpl(window) opened = True while not glfw.window_should_close(window): 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.show_user_guide() imgui.show_test_window() if opened: expanded, opened = imgui.begin("fooo", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.end() with imgui.styled(imgui.STYLE_ALPHA, 1): imgui.show_metrics_window() gl.glClearColor(114 / 255., 144 / 255., 154 / 255., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() glfw.swap_buffers(window) impl.shutdown() imgui.shutdown() glfw.terminate()
def main(): window = impl_glfw_init() impl = GlfwRenderer(window) while not glfw.window_should_close(window): 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.show_test_window() imgui.begin("Custom window", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.end() gl.glClearColor(1., 1., 1., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) glfw.swap_buffers(window) impl.shutdown() imgui.shutdown() glfw.terminate()
def run(self): while not glfw.window_should_close(self.window): glfw.poll_events() if self.gui_impl is not None: self.gui_impl.process_inputs() self.io = imgui.get_io() imgui.new_frame() if glfw.get_key(self.window, glfw.KEY_ESCAPE) == glfw.PRESS: glfw.set_window_should_close(self.window, True) self.render() if self.gui_impl is not None: imgui.render() self.gui_impl.render(imgui.get_draw_data()) glfw.swap_buffers(self.window) if self.gui_impl is not None: self.gui_impl.shutdown() imgui.shutdown() glfw.terminate()
def shutdown(self): self._invalidate_device_objects() imgui.shutdown()
def run_imgui_glfw_app( app_init=None, pre_frame=None, draw=DEFAULT_DRAW, post_frame=None, app_shutdown=None, # should_update, window_title: str = DEFAULT_WINDOW_TITLE, window_size=DEFAULT_WINDOW_SIZE, # pause_on_no_input: bool = DEFAULT_PAUSE_ON_NO_INPUT, target_framerate: float = DEFAULT_TARGET_FRAMERATE ) -> None: user_app_init = app_init user_pre_frame = pre_frame user_post_frame = post_frame user_app_shutdown = app_shutdown window = impl_glfw_init(window_title=window_title, window_size=window_size) renderer = GlfwRenderer(window) io = imgui.get_io() max_frame_dur = 1 / target_framerate frame_start = 0. frame_end = 0. frame_dur = 0. wait_dur = 0. prev_mouse_pos = (0, 0) mouse_pos = (0, 0) prev_mouse_down_0 = False prev_frame_click_0_finished = False def got_input() -> bool: """ Checks if the user sent any left-mouse mouse inputs, like moving/clicking the mouse """ nonlocal mouse_pos nonlocal prev_mouse_pos nonlocal prev_mouse_down_0 nonlocal prev_frame_click_0_finished mouse_pos = io.mouse_pos mouse_moved = (mouse_pos != prev_mouse_pos) mouse_changed = io.mouse_down[0] != prev_mouse_down_0 click_0_finished = prev_mouse_down_0 and ( not io.mouse_down[0]) # mouse was down previous frame, now it's up # key_clicked = any(io.keys_down) result = mouse_moved or mouse_changed or io.mouse_down[ 0] or prev_frame_click_0_finished # or key_clicked prev_mouse_pos = mouse_pos prev_mouse_down_0 = io.mouse_down[0] prev_frame_click_0_finished = click_0_finished return result # ======================== if user_app_init != None: user_app_init() # ======================== while not glfw.window_should_close(window): frame_start = glfw.get_time() # seconds # debug_log("frame_start_ms", frame_start*1000) # miliseconds glfw.poll_events() renderer.process_inputs() got_inp = got_input() if got_inp: imgui.new_frame() # ========================= if user_pre_frame != None: # TODO: should this run before imgui.new_frame(?) user_pre_frame() draw() if user_post_frame != None: # TODO: should this run before imgui.end_frame(?) user_post_frame() # ========================= gl.glClearColor(1., 1., 1., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() glfw.swap_buffers(window) frame_end = glfw.get_time() # seconds frame_dur = frame_end - frame_start wait_dur = max_frame_dur - frame_dur if wait_dur > 0: sleep(wait_dur) # ========================= if user_app_shutdown != None: user_app_shutdown() # ========================= renderer.shutdown() imgui.shutdown() glfw.terminate()