Python glfw.window_should_close() Examples

The following are 10 code examples of glfw.window_should_close(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module glfw , or try the search function .
Example #1
Source File: integrations_all_in_one.py    From pyimgui with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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() 
Example #2
Source File: dm_control_viewer.py    From garage with MIT License 5 votes vote down vote up
def _render_once(self):
        # See https://github.com/deepmind/dm_control/blob/92f9913013face0468442cd0964d5973ea2089ea/dm_control/viewer/gui/glfw_gui.py#L280  # noqa: E501
        window = self._window
        tick_func = self._tick_func
        if (window._context
                and not glfw.window_should_close(window._context.window)):
            pixels = tick_func()
            with window._context.make_current() as ctx:
                ctx.call(window._update_gui_on_render_thread,
                         window._context.window, pixels)
            window._mouse.process_events()
            window._keyboard.process_events()
        else:
            window.close() 
Example #3
Source File: integrations_glfw3.py    From pyimgui with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def main():
    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()

        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()
    glfw.terminate() 
Example #4
Source File: window.py    From demosys-py with ISC License 5 votes vote down vote up
def should_close(self):
        """
        Ask glfw is the window should be closed
        """
        return glfw.window_should_close(self.window) 
Example #5
Source File: window.py    From moderngl-window with MIT License 5 votes vote down vote up
def is_closing(self):
        """bool: Checks if the window is scheduled for closing"""
        return glfw.window_should_close(self._window) 
Example #6
Source File: glfw_gui.py    From dm_control with Apache License 2.0 5 votes vote down vote up
def event_loop(self, tick_func):
    """Runs the window's event loop.

    This is a blocking call that won't exit until the window is closed.

    Args:
      tick_func: A callable, function to call every frame.
    """
    while not glfw.window_should_close(self._context.window):
      pixels = tick_func()
      with self._context.make_current() as ctx:
        ctx.call(
            self._update_gui_on_render_thread, self._context.window, pixels)
      self._mouse.process_events()
      self._keyboard.process_events() 
Example #7
Source File: glfw_app.py    From pyopenvr with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def run_loop(self):
        "keep rendering until the user says quit"
        while not glfw.window_should_close(self.window):
            self.render_scene() 
Example #8
Source File: hellovr_glfw.py    From pyopenvr with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def run_main_loop(self):
        while not glfw.window_should_close(self.window):
            self.handle_input()
            self.render_frame()
            glfw.swap_buffers(self.window)
            GL.glClearColor(0, 0, 0, 1)
            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
            glfw.poll_events() 
Example #9
Source File: fonts.py    From pyimgui with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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() 
Example #10
Source File: plots.py    From pyimgui with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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()