def __init__(self, gui=True, pipe=None, img=None): self.use_imgui = gui self.use_occt = not gui self.please_stop = False self.rqq = rqQueue() self.texture_updated = False self.prev_pos = [0, 0] self.offscreen_view_size = [0, 0] if self.use_imgui: print("Creating IMGUI context") imgui.create_context() else: print("IMGUI disabled") # Create a windowed mode window and its OpenGL context if self.use_imgui: self.canva = glfwViewer3d() self.canva.set_pipe(pipe) self.canva.set_img(img) self.canva.init_driver() self.impl = GlfwRenderer(self.canva.window) else: self.canva = offscreenViewer3d() self.canva.set_pipe(pipe) self.canva.set_img(img)
def __init__(self, gui=False, width=800, height=600, window_name='opengl'): self.width = width self.height = height if not glfw.init(): raise RuntimeError('could not init glfw') hints = ((glfw.CONTEXT_VERSION_MAJOR, 4), (glfw.CONTEXT_VERSION_MINOR, 5), (glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)) for hint in hints: glfw.window_hint(*hint) self.window = glfw.create_window(int(self.width), int(self.height), window_name, None, None) glfw.make_context_current(self.window) def viewport_func(window, width, height): self.width = width self.height = height self.update_camera(update_proj=True) self.ctx.viewport = (0, 0, self.width, self.height) glfw.set_framebuffer_size_callback(self.window, viewport_func) if not self.window: glfw.terminate() raise RuntimeError('could not create glfw window') self.gui_impl = None if gui: self.gui_impl = GlfwRenderer(self.window) self.ctx = moderngl.create_context() self.ctx.viewport = (0, 0, self.width, self.height)
def main(): window = impl_glfw_init() impl = GlfwRenderer(window) font_scaling_factor = fb_to_window_factor(window) io = impl.io # clear font atlas to avoid downscaled default font # on highdensity screens. First font added to font # atlas will become default font. io.fonts.clear() # set global font scaling io.font_global_scale = 1. / font_scaling_factor # dictionary of font objects from our font directory fonts = { os.path.split(font_path)[-1]: io.fonts.add_font_from_file_ttf( font_path, FONT_SIZE_IN_PIXELS * font_scaling_factor, io.fonts.get_glyph_ranges_latin()) for font_path in FONTS_DIR } secondary_window_main_font = random.choice(list(fonts.values())) impl.refresh_font_texture() while not glfw.window_should_close(window): glfw.poll_events() impl.process_inputs() imgui.new_frame() imgui.begin("Window with multiple custom fonts", True) imgui.text("This example showcases font usage on text() widget") for font_name, font in fonts.items(): imgui.separator() imgui.text("Font:{}".format(font_name)) with imgui.font(font): imgui.text("This text uses '{}' font.".format(font_name)) imgui.end() with imgui.font(secondary_window_main_font): imgui.begin("Window one main custom font", True) imgui.text("This window uses same custom font for all widgets") 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() glfw.terminate()
def __init__(self, app: ImGuiPlayerApp): self.app = app #initialize window and GUI imgui.create_context() self.window = self.impl_glfw_init() self.impl = GlfwRenderer(self.window) self.quit_requested = False
def __init__(self): """Initialise a program and start a rendering loop This creates a glfw window + an imgui context This also then handles an update and rendering loop Raises: EnvironmentError: if GLFW fails to initialize EnvironmentError: if GLFW fails to creat a window """ if not glfw.init(): raise EnvironmentError("Failed to initialize GLFW.") # Create window window = glfw.create_window(1600, 900, "Hello World!", None, None) if not window: glfw.terminate() raise EnvironmentError("Failed to create window.") # Add in an imgui context for debugging / UIs glfw.make_context_current(window) imgui.create_context() impl = ImGuiGlfwRenderer(window) # Build the scene and load resources self.buildScene() currentTime = glfw.get_time() # Window loop while not glfw.window_should_close(window): # Calculate delta time prevTime = currentTime currentTime = glfw.get_time() delta = currentTime - prevTime # Identify which keys are being pressed keyStates = {} for name, id in glfwKeyNames.items(): keyStates[name] = glfw.get_key(window, id) == glfw.PRESS # Pass off to sub functions self.update(delta, keyStates) self.render(window) self.ui(window) # Render imgui stuff impl.render(imgui.get_draw_data()) glfw.swap_buffers(window) glfw.poll_events() impl.process_inputs() # Exit gracefully once glfw wants to close the window glfw.terminate()
def makeGUI(self, gui): """ Create the GUI context and GlfwRenderer Args: gui (bool): if True create the GUI context and GlfwRenderer """ if gui: imgui.create_context() self._renderer = GlfwRenderer(self.window(), True) self._opened = True else: self._renderer = None self._opened = False
def start(self): imgui.create_context() io = imgui.get_io() # io.fonts.add_font_default() io.fonts.add_font_from_file_ttf( "./res/font/Roboto-Medium.ttf", 14, io.fonts.get_glyph_ranges_chinese_full()) io.fonts.add_font_from_file_ttf( "./res/font/FZY3JW.ttf", 13, io.fonts.get_glyph_ranges_chinese_full(), True) self.window = App._impl_glfw_init() impl = GlfwRenderer(self.window) while not glfw.window_should_close(self.window): glfw.poll_events() impl.process_inputs() imgui.new_frame() # imgui.show_test_window() self.update() gl.glClearColor(1., 1., 1., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) glfw.swap_buffers(self.window) self.main_view and self.main_view.on_close() impl.shutdown() glfw.terminate()
def app(render, width=1280, height=720, window_name="Maldives"): """ :param render: :param width: :param height: :param window_name: :return: """ imgui.create_context() window = impl_glfw_init(width, height, window_name) impl = GlfwRenderer(window) while not glfw.window_should_close(window): glfw.poll_events() gl.glClearColor(0.3, 0.5, 0.4, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) impl.process_inputs() imgui.new_frame() render() imgui.render() impl.render(imgui.get_draw_data()) glfw.swap_buffers(window) impl.shutdown() glfw.terminate()
def main(recfile): imgui.create_context() window = impl_glfw_init() impl = GlfwRenderer(window) slamgui = SLAMGUI(recfile) 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, _ = imgui.menu_item("Quit", 'Cmd+Q', False, True) if clicked_quit: exit(0) imgui.end_menu() imgui.end_main_menu_bar() slamgui.render() 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 initialize(self): imgui.create_context() self.io = imgui.get_io() # TODO 这些枚举搜不到,需要式再说 # io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking # io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows # self.io.config_flags |= imgui.CONFIG_NAV_ENABLE_KEYBOARD # Enable Keyboard Controls TODO cause error window = G.appm.window_handle self.impl = GlfwRenderer( window, attach_callbacks=False ) # NOTE otherwise imgui will register glfw callbacks imgui.style_colors_dark() self.on_gui = G.appm.on_gui self.on_gui_editor = G.editorm.on_gui
def init(self, viewer): self.viewer = viewer window = Window(width=1200, height=675, name='contact modes') window.set_on_init(self.init_win) window.set_on_draw(self.render) window.set_on_key_press(self.on_key_press) window.set_on_key_release(self.on_key_release) window.set_on_mouse_press(self.on_mouse_press) window.set_on_mouse_drag(self.on_mouse_drag) window.set_on_resize(self.on_resize) viewer.add_window(window) self.window = window self.imgui_impl = GlfwRenderer(window.window, False)
class HelloTriangleImgui(OpenGLApp): def __init__(self): super().__init__("Hello Triangle with ImGui") self._vao = 0 self._shader_program = None self._ui = None def initialize(self): vertices = np.array([-0.5, -0.5, 0.0, 0.5, -0.5, 0.0, 0.0, 0.5, 0.0], dtype=np.float32) self._vao = GL.glGenVertexArrays(1) GL.glBindVertexArray(self._vao) vbo = GL.glGenBuffers(1) GL.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo) GL.glBufferData(GL.GL_ARRAY_BUFFER, vertices, GL.GL_STATIC_DRAW) GL.glVertexAttribPointer(0, 3, GL.GL_FLOAT, GL.GL_FALSE, 3 * ctypes.sizeof(ctypes.c_float), None) GL.glEnableVertexAttribArray(0) GL.glBindVertexArray(0) vertex_shader = Shader(GL.GL_VERTEX_SHADER, "shaders_src/hello_triangle_vertex.glsl") fragment_shader = Shader(GL.GL_FRAGMENT_SHADER, "shaders_src/hello_triangle_frag.glsl") self._shader_program = ShaderProgram(vertex_shader, fragment_shader) vertex_shader.delete() fragment_shader.delete() imgui.create_context() self._ui = GlfwRenderer(self._window, False) def render(self): self._shader_program.use() GL.glBindVertexArray(self._vao) GL.glDrawArrays(GL.GL_TRIANGLES, 0, 3) def render_ui(self): imgui.new_frame() imgui.show_demo_window() imgui.render() self._ui.render(imgui.get_draw_data()) self._ui.process_inputs()
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(): imgui.create_context() window = impl_glfw_init() impl = GlfwRenderer(window) ip_address = "localhost:3333" #imgui.set_window_font_scale(1.0) comms = MouseSocket() click_guard = True while not glfw.window_should_close(window): glfw.poll_events() impl.process_inputs() imgui.new_frame() imgui.set_next_window_size(300, 120) imgui.set_next_window_position(10, 0) imgui.begin("", False, imgui.WINDOW_NO_RESIZE) changed, ip_address = imgui.input_text(label="IP:PORT", value=ip_address, buffer_length=30) clicked = imgui.button(label="CONNECT") if clicked: comms.connect(ip_address) max_x, max_y = glfw.get_window_size(window) x, y = glfw.get_cursor_pos(window) norm_x = x / max_x norm_y = y / max_y state = glfw.get_mouse_button(window, glfw.MOUSE_BUTTON_LEFT) if state == glfw.PRESS: click_guard = False elif state == glfw.RELEASE and not click_guard: click_guard = True comms.send_click(norm_x, norm_y) comms.send_mouse_coords(norm_x, norm_y) imgui.text("Mouse Coords: {:.2f}, {:.2f}".format(norm_x, norm_y)) imgui.text("Connected: {}".format(comms.is_connected)) imgui.end() gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) glfw.swap_buffers(window) impl.shutdown() glfw.terminate()
def main(): desktop = Desktop() imgui.create_context() window = core.impl_glfw_init() impl = GlfwRenderer(window) imgui.core.style_colors_light() app_list = list(get_app_list()) # figure = plt.figure() # img = Image.open('./test.png') # texture, width, height = readImage(img) def update(): imgui.new_frame() if imgui.begin_main_menu_bar(): if imgui.begin_menu("System", True): for app in app_list: clicked, selected = imgui.menu_item( app.__name__, '', False, True) if clicked: desktop.add(app()) imgui.separator() clicked_quit, selected_quit = imgui.menu_item( "Quit", '', False, True) if clicked_quit: exit(1) imgui.end_menu() imgui.end_main_menu_bar() desktop.render() while not glfw.window_should_close(window): glfw.poll_events() impl.process_inputs() update() gl.glClearColor(1., 1., 1., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() data = imgui.get_draw_data() impl.render(data) glfw.swap_buffers(window) impl.shutdown() glfw.terminate()
def main(): imgui.create_context() window = impl_glfw_init() impl = GlfwRenderer(window) _ = gl.glGenFramebuffers(1) videoWindows = [] def dropFile(window, files): for file in files: videoWindows.append(VideoPlayer(file)) glfw.set_drop_callback(window, dropFile) while not glfw.window_should_close(window): glfw.poll_events() impl.process_inputs() imgui.new_frame() videoWindows = [x for x in videoWindows if x.open] if len(videoWindows) > 0: for videoWindow in videoWindows: videoWindow.render() else: imgui.core.set_next_window_position(10, 10) winw, winh = glfw.get_window_size(window) imgui.core.set_next_window_size(winw - 20, 10) imgui.begin("##Message", True, flags=imgui.WINDOW_NO_SCROLLBAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_MOVE) imgui.text("Drop one or more video files onto this window to play") imgui.end() 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) for videoWindow in videoWindows: videoWindow.terminate() impl.shutdown() glfw.terminate()
class Application: def __init__(self, args): imgui.create_context() self._window = self._glfw_init() self._renderer = GlfwRenderer(self._window) self._scene = TinyRendererEditor() self.main_loop() def main_loop(self): while not glfw.window_should_close(self._window): glfw.poll_events() self._renderer.process_inputs() imgui.new_frame() gl.glClearColor(0.2, 0.2, 0.2, 1.0) gl.glClear(gl.GL_COLOR_BUFFER_BIT) self._scene.update() imgui.render() draw_data = imgui.get_draw_data() if draw_data.valid: self._renderer.render(draw_data) glfw.swap_buffers(self._window) self._renderer.shutdown() glfw.terminate() def _glfw_init(self): """ Initializes the glfw an OpenGL context and returns a window """ width, height = 1600, 900 window_name = "Computer Graphics Playground" 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
def initialize(self): vertices = np.array([-0.5, -0.5, 0.0, 0.5, -0.5, 0.0, 0.0, 0.5, 0.0], dtype=np.float32) self._vao = GL.glGenVertexArrays(1) GL.glBindVertexArray(self._vao) vbo = GL.glGenBuffers(1) GL.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo) GL.glBufferData(GL.GL_ARRAY_BUFFER, vertices, GL.GL_STATIC_DRAW) GL.glVertexAttribPointer(0, 3, GL.GL_FLOAT, GL.GL_FALSE, 3 * ctypes.sizeof(ctypes.c_float), None) GL.glEnableVertexAttribArray(0) GL.glBindVertexArray(0) vertex_shader = Shader(GL.GL_VERTEX_SHADER, "shaders_src/hello_triangle_vertex.glsl") fragment_shader = Shader(GL.GL_FRAGMENT_SHADER, "shaders_src/hello_triangle_frag.glsl") self._shader_program = ShaderProgram(vertex_shader, fragment_shader) vertex_shader.delete() fragment_shader.delete() imgui.create_context() self._ui = GlfwRenderer(self._window, False)
def init(): global window, imgui_renderer, _ui_state glfw.set_error_callback(error_callback) imgui.create_context() if not glfw.init(): print("GLFW Initialization fail!") return graphics_settings = configuration.get_graphics_settings() loader_settings = configuration.get_loader_settings() if graphics_settings is None: print("bla") return screen_utils.WIDTH = graphics_settings.getint("width") screen_utils.HEIGHT = graphics_settings.getint("height") screen_utils.MAX_FPS = graphics_settings.getint("max_fps") screen = None if graphics_settings.getboolean("full_screen"): screen = glfw.get_primary_monitor() hints = { glfw.DECORATED: glfw.TRUE, glfw.RESIZABLE: glfw.FALSE, glfw.CONTEXT_VERSION_MAJOR: 4, glfw.CONTEXT_VERSION_MINOR: 5, glfw.OPENGL_DEBUG_CONTEXT: glfw.TRUE, glfw.OPENGL_PROFILE: glfw.OPENGL_CORE_PROFILE, glfw.SAMPLES: 4, } window = _create_window(size=(screen_utils.WIDTH, screen_utils.HEIGHT), pos="centered", title="Tremor", monitor=screen, hints=hints, screen_size=glfw.get_monitor_physical_size( glfw.get_primary_monitor())) imgui_renderer = GlfwRenderer(window, attach_callbacks=False) glutil.log_capabilities() glEnable(GL_CULL_FACE) glCullFace(GL_BACK) glEnable(GL_DEPTH_TEST) glDepthMask(GL_TRUE) glDepthFunc(GL_LEQUAL) glDepthRange(0.0, 1.0) glEnable(GL_MULTISAMPLE) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) create_branched_programs() # create the uniforms _create_uniforms() # initialize all the uniforms for all the prpograms init_all_uniforms()
def _init_window(self, width, height, fullscreen): if not glfw.init(): raise Exception("glfw can not be initialized!") monitor = None if fullscreen: monitor = glfw.get_primary_monitor() self.window = glfw.create_window(width, height, "Toy", monitor, None) if not self.window: raise Exception("glfw window can not be created!") glfw.set_window_pos(self.window, 50, 50) glfw.make_context_current(self.window) glfw.swap_interval(1) glfw.set_window_size_callback(self.window, self._on_resize) glfw.set_cursor_pos_callback(self.window, self._on_mouse_move) glfw.set_scroll_callback(self.window, self._on_scroll) imgui.create_context() self.impl = GlfwRenderer(self.window, False)
def main(): window = impl_glfw_init() imgui.create_context() impl = GlfwRenderer(window) plot_values = array('f', [sin(x * C) for x in range(L)]) histogram_values = array('f', [random() for _ in range(20)]) while not glfw.window_should_close(window): glfw.poll_events() impl.process_inputs() imgui.new_frame() imgui.begin("Plot example") imgui.plot_lines( "Sin(t)", plot_values, overlay_text="SIN() over time", # offset by one item every milisecond, plot values # buffer its end wraps around values_offset=int(time() * 100) % L, # 0=autoscale => (0, 50) = (autoscale width, 50px height) graph_size=(0, 50), ) imgui.plot_histogram( "histogram(random())", histogram_values, overlay_text="random histogram", # offset by one item every milisecond, plot values # buffer its end wraps around graph_size=(0, 50), ) 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() glfw.terminate()
def main(): ctx = imgui.create_context() implot.create_context() implot.set_imgui_context(ctx) 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.begin("Custom window", True) imgui.text("Bar") imgui.text_ansi("B\033[31marA\033[mnsi ") imgui.text_ansi_colored("Eg\033[31mgAn\033[msi ", 0.2, 1., 0.) imgui.extra.text_ansi_colored("Eggs", 0.2, 1., 0.) imgui.end() # show_test_window() imgui.show_test_window() implot.show_demo_window() 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() glfw.terminate()
def replay(fname): imgui.create_context() window = impl_glfw_init() impl = GlfwRenderer(window) replaygui = ReplayGUI(fname) 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, _ = imgui.menu_item( "Quit", 'Cmd+Q', False, True) if clicked_quit: exit(0) imgui.end_menu() if imgui.begin_menu("View", True): _, replaygui.show_frontview = imgui.menu_item( "Front view", selected=replaygui.show_frontview) imgui.end_menu() if imgui.begin_menu("Tools", True): clicked, _ = imgui.menu_item("Learn control params") if clicked: replaygui.learn_controls = True clicked, _ = imgui.menu_item("Lap timer") if clicked: replaygui.lap_timer = True imgui.end_menu() imgui.end_main_menu_bar() replaygui.render() 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 init(): if not glfw.init(): return # Create window m = glfw.get_primary_monitor() mode = glfw.get_video_mode(m) width = mode.size.width height = mode.size.height window = glfw.create_window(width, height, "Fractals", None, None) if not window: glfw.terminate() exit(0) glfw.make_context_current(window) impl = GlfwRenderer(window) #compile shaders try: mandelbrot_shader = from_files_names("fractal_v.glsl", "mandelbrot_f.glsl") julia_shader = from_files_names("fractal_v.glsl", "julia_f.glsl") newton_shader = from_files_names("fractal_v.glsl", "newton_f.glsl") except ShaderCompilationError as e: print(e.logs) exit() #setup data used for window and shaders window_dict = { 'width': width, 'height': height, 'n_iter': 100, 'b': 2, 'scalar': 4.5, 'x_off': 0, 'y_off': 0 } window_dict = struct(window_dict) #setep callback so they can change local variables glfw.set_key_callback(window, lambda *args: key_callback(window_dict, *args)) glfw.set_window_size_callback( window, lambda *args: window_size_callback(window_dict, *args)) #quad we are drawing to quad = pyglet.graphics.vertex_list( 4, ('v2f', (-1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0))) return window, window_dict, impl, quad, mandelbrot_shader, julia_shader, newton_shader
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(): imgui.create_context() window = impl_glfw_init() impl = GlfwRenderer(window) io = imgui.get_io() jb = io.fonts.add_font_from_file_ttf(path_to_font, 30) if path_to_font is not None else None impl.refresh_font_texture() while not glfw.window_should_close(window): render_frame(impl, window, jb) impl.shutdown() glfw.terminate()
def sim(): imgui.create_context() window = impl_glfw_init() impl = GlfwRenderer(window) sg = SimGUI() t0 = time.time() play = 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, _ = imgui.menu_item("Quit", 'Cmd+Q', False, True) if clicked_quit: exit(0) imgui.end_menu() imgui.end_main_menu_bar() t = time.time() if play: sg.step(min(t - t0, 0.03)) else: sg.idle() t0 = t play = sg.render(play) 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 main_glfw(): def glfw_init(): width, height = 1280, 720 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(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 window = glfw_init() impl = GlfwRenderer(window) while not glfw.window_should_close(window): glfw.poll_events() impl.process_inputs() imgui.new_frame() on_frame() 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() glfw.terminate()
def main(): init() imgui.create_context() window = impl_glfw_init() impl = GlfwRenderer(window) while not glfw.window_should_close(window): glfw.poll_events() impl.process_inputs() imgui.new_frame() draw(imgui) 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() glfw.terminate()
def __init__(self, width=640, height=480, title="Hello world"): imgui.create_context() if not glfw.init(): return self.window = glfw.create_window(width, height, title, None, None) if not self.window: glfw.terminate() return glfw.make_context_current(self.window) self.ctx = moderngl.create_context(require=460) self.impl = ImguiRenderer(self.window, attach_callbacks=False) glfw.set_key_callback(self.window, self._on_key) glfw.set_cursor_pos_callback(self.window, self._on_mouse_move) glfw.set_mouse_button_callback(self.window, self._on_mouse_button) glfw.set_window_size_callback(self.window, self._on_resize) glfw.set_char_callback(self.window, self._on_char) glfw.set_scroll_callback(self.window, self._on_scroll) self.init()