Example #1
0
    def update(self):
        self.impl.process_inputs()
        imgui.new_frame()

        self.on_gui and self.on_gui()
        self.on_gui_editor and self.on_gui_editor()

        imgui.render()
        self.impl.render(imgui.get_draw_data())
Example #2
0
def draw(s, impl):
    MainFrame.draw(impl)

    # note: cannot use screen.fill((1, 1, 1)) because pygame's screen
    #       does not support fill() on OpenGL sufraces
    gl.glClearColor(0.3, 0.4, 0.4, 1)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    imgui.render()
    impl.render(imgui.get_draw_data())
    pygame.display.flip()
Example #3
0
def main():
    pygame.init()
    size = 800, 600

    pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE)

    imgui.create_context()
    impl = PygameRenderer()

    io = imgui.get_io()
    io.display_size = size

    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

            impl.process_event(event)

        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.same_line()
        imgui.text_colored("Eggs", 0.2, 1., 0.)
        #imgui.same_line()
        imgui.bullet_text("bullet_text")
        # 不换行
        #imgui.same_line()
        imgui.end()

        # note: cannot use screen.fill((1, 1, 1)) because pygame's screen
        #       does not support fill() on OpenGL sufraces
        gl.glClearColor(1, 1, 1, 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        imgui.render()
        impl.render(imgui.get_draw_data())

        pygame.display.flip()
Example #4
0
def on_draw(dt):
    app.clock.tick()
    window.clear()

    impl.process_inputs()

    imgui.new_frame()
    imgui.show_test_window()

    imgui.render()
    impl.render(imgui.get_draw_data())
Example #5
0
    def render_ui(self):
        imgui.new_frame()
        imgui.begin("camera")

        is_change_y, self.u_campos.y = imgui.slider_float(
            "y", self.u_campos.y, -3.14159 * 4.0, 3.14159 * 4.0)
        if is_change_y:
            self.uniform("u_campos", self.u_campos)

        imgui.end()
        imgui.render()
        self.imgui.render(imgui.get_draw_data())
Example #6
0
def draw(s, impl):
    MainFrame.draw(impl)

    # note: cannot use screen.fill((1, 1, 1)) because pygame's screen
    #       does not support fill() on OpenGL sufraces
    x = math.fabs(math.sin(time.time()))
    y = math.fabs(math.cos(time.time()))
    gl.glClearColor(x, y, x, 1)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    imgui.render()
    impl.render(imgui.get_draw_data())
    pygame.display.flip()
Example #7
0
    def render_ui(self):

        # Test window
        imgui.new_frame()
        imgui.begin("Custom window", True)
        imgui.text("Bar")
        imgui.text_colored("Eggs", 0.2, 1., 0.)
        imgui.end()

        # Render
        imgui.render()
        self.imgui.render(imgui.get_draw_data())
Example #8
0
    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()
Example #9
0
    def draw_imgui(self):
        io = self.io
        # start new frame context
        imgui.new_frame()
        if self.activate_plots:
            self.plot_manager.render_imgui()
        if self.show_console:
            self.console.render_lines()

        imgui.render()
        data = imgui.get_draw_data()
        self.imgui_renderer.render(data)
        imgui.end_frame()
Example #10
0
    def draw(self):
        imgui.new_frame()

        imgui.set_next_window_position(16, 32, imgui.ONCE)
        imgui.set_next_window_size(512, 512, imgui.ONCE)

        imgui.begin("Example: empty window")
        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
Example #11
0
 def run(self):
     while 1:
         for event in pygame.event.get():
             if event.type == pygame.QUIT:
                 sys.exit()
             self.impl.process_event(event)
         imgui.new_frame()
         # render game elements
         # render gui
         gl.glClearColor(1, 1, 1, 1)
         gl.glClear(gl.GL_COLOR_BUFFER_BIT)
         imgui.render()
         self.impl.render(imgui.get_draw_data())
         pygame.display.flip()
Example #12
0
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()
Example #13
0
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()
Example #14
0
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()
Example #15
0
    def draw(self, data):
        # render to texture
        time = default_timer() - self.t0
        with self.preview_surface:
            self.preview_draw(self.preview_surface.cam)
            # start flashing message & allow input
            if time > 3.14:
                self.can_finish = True
                self.render_start.color.a = sin(time*3)/2 + 0.85
                self.start_text_bg.draw(self.preview_surface.cam)
                self.render_start.draw(self.preview_surface.cam)
            self.mock_keys.draw(self.preview_surface.cam)
        self.preview_surface.draw(self.win.cam)
        self.render_title.draw(self.win.cam)

        # imgui window
        imgui.new_frame()
        imgui.push_font(self.imgui_font)
        imgui.set_next_window_size(*self.imgui_dims)
        imgui.set_next_window_position(*self.imgui_pos)
        title = {'en': 'Instructions', 'es': 'Instrucciones'}
        imgui.begin(title[self.default_lang], False, flags=self.flags)
        imgui.push_text_wrap_pos(1000)
        imgui.text(self.it2)
        imgui.pop_text_wrap_pos()
        imgui.end()
        imgui.set_next_window_position(100, 100)
        imgui.set_next_window_size(180, 50)
        imgui.begin('##blockcount', flags=self.flags | WINDOW_NO_TITLE_BAR)
        rnd = {'en': 'Round', 'es': 'La ronda'}
        imgui.text('%s %s/%s' % (rnd[self.default_lang], self.num, self.tot))
        imgui.end()
        imgui.pop_font()
        imgui.render()
        self.imgui_renderer.render(imgui.get_draw_data())
        # fade in effect
        if self.fade_in:
            self.fade_sqr.fill_color.a -= 0.05
            if self.fade_sqr.fill_color.a <= 0:
                self.fade_in = False
            self.fade_sqr.draw(self.win.cam)
        if self.fade_out:
            self.fade_sqr.fill_color.a += 0.05
            self.fade_sqr.draw(self.win.cam)
            if self.fade_sqr.fill_color.a >= 1:
                return True
        if data and self.can_finish:
            self.fade_out = True
        return False
Example #16
0
    def render_ui(self):
        imgui.new_frame()

        imgui.begin("Description - Histogram", False)
        imgui.text("Shows the histogram of a selected photo")
        imgui.text("FPS: %.2f" % self.fps)
        imgui.end()


        imgui.begin("Controls - Histogram", False)
        imgui.text("Press P to select a photo")
        imgui.end()

        imgui.render()
        self.imgui.render(imgui.get_draw_data())
Example #17
0
    def draw(self):
        imgui.new_frame()

        imgui.set_next_window_position(16, 32, imgui.ONCE)
        imgui.set_next_window_size(512, 512, imgui.ONCE)

        imgui.begin("Image example")
        imgui.image(self.texture.glo, *self.texture.size)
        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
Example #18
0
    def render(self):
        imgui.new_frame()

        imgui.begin("Test Window")
        imgui.text("This is the test window.")
        changed, self.test_input = imgui.input_int("Integer Input Test",
                                                   self.test_input)

        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
Example #19
0
    def render_ui(self, time):
        imgui.new_frame()

        imgui.begin("Description - Music", False)
        imgui.text("Pick a song to vizualize:")
        comboOut = imgui.listbox("", -1, [
            "Sweet Dreams", "Children of the Omnissiah", "We all lift together"
        ])
        imgui.text("FPS: %.2f" % self.fps)
        imgui.end()

        imgui.render()
        self.imgui.render(imgui.get_draw_data())
        if comboOut[0]:
            self.playSong(comboOut[1], time)
Example #20
0
    def render_ui(self, t, dt):
        imgui.new_frame()

        if imgui.begin_main_menu_bar():
            if imgui.begin_menu("Test Menu"):
                imgui.end_menu()

            imgui.end_main_menu_bar()

        imgui.begin("Control")
        imgui.text(f"FPS {1.0 / (dt):.2f}")
        imgui.end()
        imgui.render()

        self.imgui.render(imgui.get_draw_data())
Example #21
0
def draw_ui():
    imgui.new_frame()
    if _ui_state == UIState.MAIN_MENU:
        glfw.set_input_mode(window, glfw.CURSOR, glfw.CURSOR_NORMAL)
        menus.show_main_menu()
    if _ui_state == UIState.IN_GAME_HUD:
        hud.show_ingame_hud()
        if console.SHOW_CONSOLE:
            glfw.set_input_mode(window, glfw.CURSOR, glfw.CURSOR_NORMAL)
        else:
            glfw.set_input_mode(window, glfw.CURSOR, glfw.CURSOR_DISABLED)
    draw_console()
    imgui.render()
    imgui_renderer.render(imgui.get_draw_data())
    imgui.end_frame()
Example #22
0
def main():
    window, gl_context = impl_pysdl2_init()
    imgui.create_context()
    impl = SDL2Renderer(window)

    running = True
    event = SDL_Event()
    while running:
        while SDL_PollEvent(ctypes.byref(event)) != 0:
            if event.type == SDL_QUIT:
                running = False
                break
            impl.process_event(event)
        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()

        show_test_window()
        #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())
        SDL_GL_SwapWindow(window)

    impl.shutdown()
    SDL_GL_DeleteContext(gl_context)
    SDL_DestroyWindow(window)
    SDL_Quit()
Example #23
0
    def draw(self):
        # Clear the window to dark blue.
        gl.glClearColor( 0, 0, 0.2, 1 )
        gl.glClear( gl.GL_COLOR_BUFFER_BIT )

        # Draw the game.
        self.game.sprite.drawSetup()
        self.game.draw()
        self.game.sprite.drawCleanup()

        # Draw imgui windows.
        imgui.render()
        self.imGuiManager.render( imgui.get_draw_data() )

        # Display what we drew.
        pygame.display.flip()
Example #24
0
    def draw(self):
        imgui.new_frame()

        imgui.begin("Font")

        imgui.text("Text displayed using default font")
        with imgui.font(self.new_font):
            imgui.text("Text displayed using custom font")

        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
Example #25
0
    def draw(self):
        imgui.new_frame()

        imgui.set_next_window_position(16, 32, imgui.ONCE)
        imgui.set_next_window_size(512, 512, imgui.ONCE)

        imgui.begin("Example: drag int")
        changed, self.values = imgui.drag_int4("drag ints", *self.values)
        imgui.text("Changed: %s, Values: %s" % (changed, self.values))
        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
Example #26
0
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 draw(self):
        imgui.new_frame()

        imgui.set_next_window_position(16, 32, imgui.ONCE)
        imgui.set_next_window_size(512, 512, imgui.ONCE)

        imgui.begin("Example: popup context window")
        if imgui.begin_popup_context_window(mouse_button=0):
            imgui.selectable("Clear")
            imgui.end_popup()
        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
def render_frame(impl, window, font):
    glfw.poll_events()
    impl.process_inputs()
    imgui.new_frame()

    gl.glClearColor(0.1, 0.1, 0.1, 1)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)

    if font is not None:
        imgui.push_font(font)
    frame_commands()
    if font is not None:
        imgui.pop_font()

    imgui.render()
    impl.render(imgui.get_draw_data())
    glfw.swap_buffers(window)
Example #29
0
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()
Example #30
0
    def draw(self):
        imgui.new_frame()

        imgui.set_next_window_position(16, 32, imgui.ONCE)
        imgui.set_next_window_size(512, 512, imgui.ONCE)

        imgui.begin("Example: bullet text")
        imgui.bullet_text("Bullet 1")
        imgui.bullet_text("Bullet 2")
        imgui.bullet_text("Bullet 3")
        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())