def main(): global window # Configure to use pyglet window settings.WINDOW['class'] = 'moderngl_window.context.pyglet.Window' window = moderngl_window.create_window_from_settings() # Map callback functions window.resize_func = resize window.iconify_func = iconify window.key_event_func = key_event window.mouse_position_event_func = mouse_position_event window.mouse_drag_event_func = mouse_drag_event window.mouse_scroll_event_func = mouse_scroll_event window.mouse_press_event_func = mouse_press_event window.mouse_release_event_func = mouse_release_event window.unicode_char_entered_func = unicode_char_entered timer = Timer() timer.start() while not window.is_closing: window.use() window.clear() time, frame_time = timer.next_frame() window.ctx.clear( (math.sin(time) + 1.0) / 2, (math.sin(time + 2) + 1.0) / 2, (math.sin(time + 3) + 1.0) / 2, ) window.swap_buffers() window.destroy()
def run(self, change_vertex_buffer=None, before_frame_func=None, after_frame_func=None): timer = Timer() timer.start() while not self.wnd.is_closing: self.wnd.clear() time, frame_time = timer.next_frame() if change_vertex_buffer: buffer = change_vertex_buffer(self, time, frame_time) self.vbo.write(buffer) if before_frame_func: before_frame_func(self, time, frame_time) self.render(time, frame_time) if after_frame_func: after_frame_func(self, time, frame_time) self.wnd.swap_buffers() self.wnd.destroy()
def run_window_config(config_cls: WindowConfig, timer=None, args=None) -> None: """ Run an WindowConfig entering a blocking main loop Args: config_cls: The WindowConfig class to render args: Override sys.args """ setup_basic_logging(config_cls.log_level) parser = create_parser() config_cls.add_arguments(parser) values = parse_args(args=args, parser=parser) config_cls.argv = values window_cls = get_local_window_cls(values.window) # Calculate window size size = values.size or config_cls.window_size size = int(size[0] * values.size_mult), int(size[1] * values.size_mult) # Resolve cursor show_cursor = values.cursor if show_cursor is None: show_cursor = config_cls.cursor window = window_cls( title=config_cls.title, size=size, fullscreen=config_cls.fullscreen or values.fullscreen, resizable=values.resizable if values.resizable is not None else config_cls.resizable, gl_version=config_cls.gl_version, aspect_ratio=config_cls.aspect_ratio, vsync=values.vsync if values.vsync is not None else config_cls.vsync, samples=values.samples if values.samples is not None else config_cls.samples, cursor=show_cursor if show_cursor is not None else True, ) window.print_context_info() activate_context(window=window) timer = Timer() window.config = config_cls(ctx=window.ctx, wnd=window, timer=timer) timer.start() while not window.is_closing: current_time, delta = timer.next_frame() if window.config.clear_color is not None: window.clear(*window.config.clear_color) else: window.use() window.render(current_time, delta) window.swap_buffers() _, duration = timer.stop() window.destroy() if duration > 0: logger.info("Duration: {0:.2f}s @ {1:.2f} FPS".format( duration, window.frames / duration))
def run(self): timer = Timer() timer.start() self.update() while not self.wnd.is_closing: self.wnd.clear() time, frame_time = timer.next_frame() self.render(time, frame_time) self.wnd.swap_buffers() self.wnd.destroy()
def run_window_config(config_cls: WindowConfig, timer=None, args=None) -> None: """ Run an WindowConfig entering a blocking main loop Args: config_cls: The WindowConfig class to render args: Override sys.args """ values = parse_args(args) window_cls = get_local_window_cls(values.window) window = window_cls( title=config_cls.title, size=config_cls.window_size, fullscreen=values.fullscreen, resizable=config_cls.resizable, gl_version=config_cls.gl_version, aspect_ratio=config_cls.aspect_ratio, vsync=values.vsync, samples=values.samples, cursor=values.cursor, ) window.print_context_info() window.config = config_cls(ctx=window.ctx, wnd=window) timer = Timer() timer.start() while not window.is_closing: current_time, delta = timer.next_frame() window.ctx.screen.use() window.render(current_time, delta) window.swap_buffers() _, duration = timer.stop() window.destroy() print("Duration: {0:.2f}s @ {1:.2f} FPS".format(duration, window.frames / duration))