Example #1
0
def main():
    global window
    glfw.init()
    glfw.window_hint(glfw.CLIENT_API, glfw.OPENGL_API)
    glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 4)
    glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 6)
    glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_COMPAT_PROFILE)
    glfw.window_hint(glfw.CONTEXT_ROBUSTNESS, glfw.LOSE_CONTEXT_ON_RESET)
    glfw.window_hint(glfw.OPENGL_DEBUG_CONTEXT, True)
    glfw.window_hint(glfw.SAMPLES, 8)
    window = glfw.create_window(1024, 768, "Forest", None, None)
    glfw.make_context_current(window)
    glDebugMessageCallback(debug, None)
    init()
    resize_window(window, 1024, 768)
    glfw.set_window_size_callback(window, resize_window)
    glfw.set_key_callback(window, handle_key)
    glfw.set_cursor_pos_callback(window, handle_cursor)
    glfw.set_scroll_callback(window, handle_wheel)
    try:
        if glfw.raw_mouse_motion_supported():
            glfw.set_input_mode(window, glfw.RAW_MOUSE_MOTION, True)
    except AttributeError:
        pass  # ну, значит, не поддерживается
    t0 = glfw.get_time()
    while not glfw.window_should_close(window):
        glfw.poll_events()
        update0()
        render()
        glfw.swap_buffers(window)
        t1 = glfw.get_time()
        update(t1 - t0)
        t0 = t1
    glfw.destroy_window(window)
    glfw.terminate()
Example #2
0
def main():
    # inicia glfw
    if not glfw.init():
        return

    # crea la ventana,
    # independientemente del SO que usemos
    window = glfw.create_window(800, 800, "Mi ventana", None, None)
    glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL_TRUE)
    glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)

    # Validamos que se cree la ventana
    if not window:
        glfw.terminate()
        return
    # Establecemos el contexto
    glfw.make_context_current(window)

    # Activamos la validación de
    # funciones modernas de OpenGL
    glewExperimental = True

    # Inicializar GLEW
    if glewInit() != GLEW_OK:
        print("No se pudo inicializar GLEW")
        return

    # Obtenemos versiones de OpenGL y Shaders
    version = glGetString(GL_VERSION)
    print(version)

    version_shaders = glGetString(GL_SHADING_LANGUAGE_VERSION)
    print(version_shaders)

    glfw.set_key_callback(window, key_callback)

    iniciaizarObstaculos()

    while not glfw.window_should_close(window):
        # Establece regiond e dibujo
        glViewport(0, 0, 800, 800)
        # Establece color de borrado
        glClearColor(0.4, 0.8, 0.1, 1)
        # Borra el contenido de la ventana
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Dibujar
        actualizar(window)
        dibujar()

        # Preguntar si hubo entradas de perifericos
        # (Teclado, mouse, game pad, etc.)
        glfw.poll_events()
        # Intercambia los buffers
        glfw.swap_buffers(window)

    # Se destruye la ventana para liberar memoria
    glfw.destroy_window(window)
    # Termina los procesos que inició glfw.init
    glfw.terminate()
Example #3
0
    def close(self) -> None:

        # Destory window
        glfw.destroy_window(self.window)

        # finish GLFW
        glfw.terminate()
    def __del__(self):
        GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0)
        if hasattr(self, "FBORENDER"):
            GL.glDeleteTextures(self.TARGET)
            GL.glDeleteRenderbuffers(6, self.DEPTH)
            GL.glDeleteFramebuffers(1, [self.FBORENDER])
            report_GL_error()

        if hasattr(self, "FBOACCUM"):
            GL.glDeleteTextures([self.ACCUM])
            GL.glDeleteTextures([self.AREA])
            GL.glDeleteFramebuffers(1, [self.FBOACCUM])
            del self.prog
            report_GL_error()
        if hasattr(self, "SANGLE"):
            GL.glDeleteTextures([self.SANGLE])
            report_GL_error()

        if self.mesh is not None:
            del self.mesh
            report_GL_error()

        if hasattr(self, "wnd"):
            glfw.destroy_window(self.wnd)
            glfw.terminate()
Example #5
0
    def head_cam_viewer_close(self):
        if self.get_head_cam_viewer() is not None:
            #glfw.window_should_close()
            glfw.set_window_size_callback(
                self.head_cam_viewer.opengl_context.window, None)

            glfw.destroy_window(self.head_cam_viewer.opengl_context.window)
Example #6
0
def main():
    global angles, angley, anglez, scale, carcass, sphere
    if not glfw.init():
        return
    window = glfw.create_window(640, 640, "Lab2", None, None)
    if not window:
        glfw.terminate()
        return
    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, resize_callback)
    glfw.set_window_pos_callback(window, drag_callback)
    l_cube = Cube(0, 0, 0, 1)
    # r_cube = Cube(0, 0, 0, 1)
    sphere.recount(parts)
    while not glfw.window_should_close(window):
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LESS)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        set_projection()
        glLoadIdentity()
        sphere.draw(scale, angles, [0.3, 0.0, 0.4], carcass)
        # r_cube.draw(scale, angles, [0.3, 0.2, 0.4], carcass)
        l_cube.draw(0.5, [0, 0, 0], [-0.5, 0.0, -0.25], False)
        glfw.swap_buffers(window)
        glfw.poll_events()
    glfw.destroy_window(window)
    glfw.terminate()
Example #7
0
    def glfw_main_loop(self):
        while not glfw.window_should_close(self.main_window):
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

            self.image = self.stream.get_current_frame()
            self.draw_background(self.image)

            ids, rvecs, tvecs = self.find_marker(self.image)

            self.draw_AR(ids, rvecs, tvecs)
            self.draw_HUD()

            self.collision_evaluation()

            self.joystick()

            glfw.swap_buffers(self.main_window)
            glfw.poll_events()

            self.frames += 1

            if time.time() - self.toc >= 2:
                self.toc = time.time()
                print(self.frames/2)
                self.frames = 0

        glfw.destroy_window(self.main_window)
        glfw.terminate()
Example #8
0
def main():
    # GLFW初期化
    if not glfw.init():
        return

    # ウィンドウを作成
    window = glfw.create_window(640, 480, 'Hello World', None, None)
    if not window:
        glfw.terminate()
        print('Failed to create window')
        return

    # コンテキストを作成
    glfw.make_context_current(window)

    # バージョンを指定
    glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 4)
    glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 0)
    glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)

    while not glfw.window_should_close(window):
        # バッファを指定色で初期化
        glClearColor(1, 0, 0, 1)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # バッファを入れ替えて画面を更新
        glfw.swap_buffers(window)

        # イベントを受け付けます
        glfw.poll_events()

    # ウィンドウを破棄してGLFWを終了
    glfw.destroy_window(window)
    glfw.terminate()
Example #9
0
    def _close_viewer_window(self):
        """
        Close viewer window.

        Unfortunately, some gym environments don't close the viewer windows
        properly, which leads to "out of memory" issues when several of
        these environments are tested one after the other.
        This method searches for the viewer object of type MjViewer, Viewer
        or SimpleImageViewer, based on environment, and if the environment
        is wrapped in other environment classes, it performs depth search
        in those as well.
        This method can be removed once OpenAI solves the issue.
        """
        if self.env.spec:
            if any(package in self.env.spec._entry_point
                   for package in KNOWN_GYM_NOT_CLOSE_MJ_VIEWER):
                # This import is not in the header to avoid a MuJoCo dependency
                # with non-MuJoCo environments that use this base class.
                from mujoco_py.mjviewer import MjViewer
                if (hasattr(self.env, 'viewer')
                        and isinstance(self.env.viewer, MjViewer)):
                    glfw.destroy_window(self.env.viewer.window)
            elif any(package in self.env.spec._entry_point
                     for package in KNOWN_GYM_NOT_CLOSE_VIEWER):
                if (hasattr(self.env, 'viewer') and
                    (isinstance(self.env.viewer, Viewer)
                     or isinstance(self.env.viewer, SimpleImageViewer))):
                    self.env.viewer.close()
Example #10
0
def main_loop(data_path=None,
              texture_path=None,
              vertex_path=None,
              fragment_path=None,
              object_path=None):
    global ctx

    # Loop initialization
    win = glfw_initialization()
    ctx = ModernGL.create_context()
    load_data(
        ctx,
        data_path=data_path,
        vertex_path=vertex_path,
        fragment_path=fragment_path,
        texture_path=texture_path,
        object_path=object_path,
    )

    # Display
    while not glfw.window_should_close(win):
        render_scene(win, ctx)
        glfw.swap_buffers(win)
        glfw.poll_events()

    glfw.destroy_window(win)
    glfw.terminate()
Example #11
0
    def __receiveMode(self):
        if self.__displayMode == "Receive":
            glfw.set_window_title(self.__window,
                                  "Spout: " + self.__displayMode + " Texture")

            if self.__receiveWidth == 0 and self.__receiveHeight == 0:
                if not glfw.window_should_close(self.__window):

                    glActiveTexture(GL_TEXTURE0)
                    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
                    glLoadIdentity()
                    glBegin(GL_QUADS)
                    glTexCoord2f(0, 0)
                    glVertex2f(0, 0)
                    glTexCoord2f(1, 0)
                    glVertex2f(1, 0)
                    glTexCoord2f(1, 1)
                    glVertex2f(1, 1)
                    glTexCoord2f(0, 1)
                    glVertex2f(0, 1)
                    glEnd()
                    glfw.swap_buffers(self.__window)
                    glfw.poll_events()
                else:
                    glfw.destroy_window(self.__window)
                    glfw.terminate()

            else:
                if not glfw.window_should_close(self.__window):
                    left = 0
                    top = 0
                    width = self.__windowWidth
                    height = self.__windowHeight

                    sx = self.__windowWidth / self.__receiveWidth
                    sy = self.__windowHeight / self.__receiveHeight
                    if sx > sy:
                        width *= sy / sx
                        left = (self.__windowWidth - width) / 2
                    else:
                        height *= sx / sy
                        top = (self.__windowHeight - height) / 2
                    glActiveTexture(GL_TEXTURE0)
                    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
                    glLoadIdentity()
                    glBegin(GL_QUADS)
                    glTexCoord2f(0, 0)
                    glVertex2f(left, top)
                    glTexCoord2f(1, 0)
                    glVertex2f(left + width, top)
                    glTexCoord2f(1, 1)
                    glVertex2f(left + width, top + height)
                    glTexCoord2f(0, 1)
                    glVertex2f(left, top + height)
                    glEnd()
                    glfw.swap_buffers(self.__window)
                    glfw.poll_events()
                else:
                    glfw.destroy_window(self.__window)
                    glfw.terminate()
Example #12
0
    def _close_viewer_window(self):
        """Close viewer window.

        Unfortunately, some gym environments don't close the viewer windows
        properly, which leads to "out of memory" issues when several of
        these environments are tested one after the other.
        This method searches for the viewer object of type MjViewer, Viewer
        or SimpleImageViewer, based on environment, and if the environment
        is wrapped in other environment classes, it performs depth search
        in those as well.
        This method can be removed once OpenAI solves the issue.
        """
        # We need to do some strange things here to fix-up flaws in gym
        # pylint: disable=import-outside-toplevel
        if hasattr(self._env, 'spec') and self._env.spec:
            if any(package in getattr(self._env.spec, 'entry_point', '')
                   for package in KNOWN_GYM_NOT_CLOSE_MJ_VIEWER):
                # This import is not in the header to avoid a MuJoCo dependency
                # with non-MuJoCo environments that use this base class.
                try:
                    from mujoco_py.mjviewer import MjViewer
                    import glfw
                except ImportError:
                    # If we can't import mujoco_py, we must not have an
                    # instance of a class that we know how to close here.
                    return
                if (hasattr(self._env, 'viewer')
                        and isinstance(self._env.viewer, MjViewer)):
                    glfw.destroy_window(self._env.viewer.window)
            elif any(package in getattr(self._env.spec, 'entry_point', '')
                     for package in KNOWN_GYM_NOT_CLOSE_VIEWER):
                if hasattr(self._env, 'viewer'):
                    pass
Example #13
0
def main():
    global msh, nav
    msh = dfm2.Mesh()
    msh.read("../test_inputs/bunny_2k.ply")
    msh.scale_xyz(0.02)

    nav = dfm2.gl.glfw.NavigationGLFW(1.0)

    glfw.init()
    win_glfw = glfw.create_window(640, 480, 'Hello World', None, None)
    glfw.make_context_current(win_glfw)

    dfm2.gl.setSomeLighting()
    gl.glEnable(gl.GL_DEPTH_TEST)

    glfw.set_mouse_button_callback(win_glfw, mouseButtonCB)
    glfw.set_cursor_pos_callback(win_glfw, mouseMoveCB)
    glfw.set_key_callback(win_glfw, keyFunCB)

    while not glfw.window_should_close(win_glfw):
        gl.glClearColor(1, 1, 1, 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glEnable(gl.GL_POLYGON_OFFSET_FILL)
        gl.glPolygonOffset(1.1, 4.0)

        nav.camera.set_gl_camera()
        render()
        glfw.swap_buffers(win_glfw)
        glfw.poll_events()
        if nav.isClose:
            break
    glfw.destroy_window(win_glfw)
    glfw.terminate()
    print("closed")
Example #14
0
    def close(self):
        """Close the window and uninitialize the resources
        """
        # Test if the window has already been closed
        if glfw.window_should_close(self.winHandle):
            return

        _hw_handle = None

        try:
            self.setMouseVisibility(True)
            glfw.set_window_should_close(self.winHandle, 1)
            glfw.destroy_window(self.winHandle)
        except Exception:
            pass
        # If iohub is running, inform it to stop looking for this win id
        # when filtering kb and mouse events (if the filter is enabled of
        # course)
        try:
            if window.IOHUB_ACTIVE and _hw_handle:
                from psychopy.iohub.client import ioHubConnection
                conn = ioHubConnection.ACTIVE_CONNECTION
                conn.unregisterWindowHandles(_hw_handle)
        except Exception:
            pass
Example #15
0
    def run(self):
        glfw.make_context_current(self.window)
        if glfw.window_should_close(self.window):
            glfw.destroy_window(self.window)
            return 1
        else:

            glfw.poll_events()

            glClearColor(0.2, 0.3, 0.3, 1.0)
            glClear(GL_COLOR_BUFFER_BIT)

            self.deltatime = glfw.get_time() - self.time
            self.time = glfw.get_time()

            if self.currentSheet is not None and self.running:
                self.sheetObjects[self.currentSheet["loopnode"]].run()
            else:
                pass    # TODO: Display default thing with monitor and resolution

            glfw.swap_buffers(self.window)

            self.beatlow = False
            self.beatmid = False
            self.beathigh = False

            return 0
Example #16
0
    def run(self):
        # Initialize environment
        if glfw.init():

            # Create window
            glfw.window_hint(glfw.VISIBLE, False)
            window = glfw.create_window(800, 600, "hidden window", None, None)
            glfw.make_context_current(window)

            # Initialize
            self.initialize()

            # Loop
            while self.running and self.pipe:
                # Check pipe
                if self.pipe.poll():
                    start = time.perf_counter()
                    self.render(self.pipe.recv())
                    if self.response:
                        dt = time.perf_counter() - start
                        self.pipe.send(
                            f'Image {self.format} rendered in {int(dt*1e3)}ms')
                # Sleep
                time.sleep(1e-3)

            # Destroy camera
            glfw.destroy_window(window)

        # Terminate environment
        glfw.terminate()
Example #17
0
 def close(self, fig):
     with self.l:
         for i in range(len(self.windows)):
             if fig == self.windows[i]:
                 glfw.destroy_window(self.windows[i].window)
                 self.windows.pop(i)
                 break
Example #18
0
    def close(self):
        """Close the window and uninitialize the resources
        """
        # Test if the window has already been closed
        if glfw.window_should_close(self.winHandle):
            return

        _hw_handle = None

        try:
            self.setMouseVisibility(True)
            glfw.set_window_should_close(self.winHandle, 1)
            glfw.destroy_window(self.winHandle)
        except Exception:
            pass
        # If iohub is running, inform it to stop looking for this win id
        # when filtering kb and mouse events (if the filter is enabled of
        # course)
        try:
            if IOHUB_ACTIVE and _hw_handle:
                from psychopy.iohub.client import ioHubConnection
                conn = ioHubConnection.ACTIVE_CONNECTION
                conn.unregisterWindowHandles(_hw_handle)
        except Exception:
            pass
def main():
    global vertices, window_height, window_width, to_redraw

    if not glfw.init():
        return

    window = glfw.create_window(400, 400, "Lab4", None, None)
    if not window:
        glfw.terminate()
        return

    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, resize_callback)

    glfw.set_mouse_button_callback(window, mouse_button_callback)
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LESS)
    glClearColor(0, 0, 0, 0)

    while not glfw.window_should_close(window):
        # print(vertices)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        draw()

        glfw.swap_buffers(window)
        glfw.poll_events()

    glfw.destroy_window(window)
    glfw.terminate()
Example #20
0
    def close(self):
        self.viewer = None
        self._viewers.clear()

        for viewer in self._viewers.items():
            import glfw
            glfw.destroy_window(viewer.window)
Example #21
0
def main():
    global angles, angley, anglez, scale, carcass, sphere
    if not glfw.init():
        return
    window = glfw.create_window(640, 640, "Lab2", None, None)
    if not window:
        glfw.terminate()
        return
    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, resize_callback)
    glfw.set_window_pos_callback(window, drag_callback)
    l_cube = Cube(0, 0, 0, 1)
    # r_cube = Cube(0, 0, 0, 1)
    sphere.recount(parts)
    while not glfw.window_should_close(window):
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LESS)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        set_projection()
        glLoadIdentity()
        sphere.draw(scale, angles, [0.3, 0.0, 0.4], carcass)
        # r_cube.draw(scale, angles, [0.3, 0.2, 0.4], carcass)
        l_cube.draw(0.5, [0, 0, 0], [-0.5, 0.0, -0.25], False)
        glfw.swap_buffers(window)
        glfw.poll_events()
    glfw.destroy_window(window)
    glfw.terminate()
Example #22
0
 def close(self):
     if not self.is_open:
         return
     with self._switch_to_current_context():
         glfw.set_input_mode(self.__gl_handle, glfw.CURSOR, glfw.CURSOR_NORMAL)
         glfw.destroy_window(self.__gl_handle)
     self.__gl_handle = None
Example #23
0
def change_parameters_of_soft_body_demo(episodes):

    for _ in range(episodes):

        env = suite.make('Ultrasound',
                         robots='UR5e',
                         controller_configs=None,
                         gripper_types='UltrasoundProbeGripper',
                         has_renderer=True,
                         has_offscreen_renderer=False,
                         use_camera_obs=False,
                         use_object_obs=False,
                         control_freq=50,
                         render_camera=None,
                         horizon=800)

        print_world_xml_and_soft_torso_params(env.model)

        sim, viewer = create_mjsim_and_viewer(env)

        for _ in range(env.horizon):
            sim.step()
            viewer.render()

        glfw.destroy_window(viewer.window)
Example #24
0
def sample_sawyer_push_nips():
    env = SawyerPushAndReachXYEasyEnv()
    for _ in range(100):
        env.render()
        env.step(env.action_space.sample())
        time.sleep(0.05)
    glfw.destroy_window(env.viewer.window)
Example #25
0
def main():
  global mshelm, wmngr_glfw
  mshelm = dfm2.MeshElem("../test_inputs/bunny_2k.ply");
  mshelm.scaleXYZ(0.02)

  wmngr_glfw = dfm2.WindowManagerGLFW(1.0)

  glfw.init()
  win_glfw = glfw.create_window(640, 480, 'Hello World', None, None)
  glfw.make_context_current(win_glfw)

  dfm2.setSomeLighting()
  glEnable(GL_DEPTH_TEST)

  glfw.set_mouse_button_callback(win_glfw, mouseButtonCB)
  glfw.set_cursor_pos_callback(win_glfw,  mouseMoveCB)
  glfw.set_key_callback(win_glfw, keyFunCB)

  while not glfw.window_should_close(win_glfw):
    glClearColor(1, 1, 1, 1)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    wmngr_glfw.camera.set_gl_camera()
    render()
    glfw.swap_buffers(win_glfw)
    glfw.poll_events()
    if wmngr_glfw.isClose:
      break
  glfw.destroy_window(win_glfw)
  glfw.terminate()
  print("closed")
Example #26
0
def sample_sawyer_push_multiobj():
    env = SawyerTwoObjectEnv()
    for _ in range(100):
        env.render()
        env.step(np.array([0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]))
        time.sleep(0.05)
    glfw.destroy_window(env.viewer.window)
Example #27
0
def sample_sawyer_throw():
    env = SawyerThrowEnv()
    for i in range(1000):
        if i % 100 == 0:
            env.reset()
        env.step(np.array([0, 0, 0, 1]))
        env.render()
    glfw.destroy_window(env.viewer.window)
Example #28
0
def sample_sawyer_window_open():
    env = SawyerWindowOpenEnv()
    env.reset()
    for _ in range(100):
        env.render()
        env.step(np.array([1, 0, 0, 1]))
        time.sleep(0.05)
    glfw.destroy_window(env.viewer.window)
Example #29
0
def sample_sawyer_sweep_into_goal():
    env = SawyerSweepIntoGoalEnv(fix_goal=True)
    for i in range(1000):
        if i % 100 == 0:
            env.reset()
        env.step(np.array([0, 1, 1]))
        env.render()
    glfw.destroy_window(env.viewer.window)
Example #30
0
def sample_sawyer_sweep():
    env = SawyerSweepEnv(fix_goal=True)
    for i in range(200):
        if i % 100 == 0:
            env.reset()
        env.step(env.action_space.sample())
        env.render()
    glfw.destroy_window(env.viewer.window)
Example #31
0
def sample_sawyer_stick_pull():
    env = SawyerStickPullEnv()
    env.reset()
    for _ in range(100):
        env.render()
        env.step(env.action_space.sample())
        time.sleep(0.05)
    glfw.destroy_window(env.viewer.window)
Example #32
0
def sample_sawyer_shelf_place():
    env = SawyerShelfPlaceEnv()
    env.reset()
    for _ in range(100):
        env.render()
        env.step(env.action_space.sample())
        time.sleep(0.05)
    glfw.destroy_window(env.viewer.window)
Example #33
0
def sample_sawyer_rope():
    env = SawyerRopeEnv()
    env.reset()
    for _ in range(50):
        env.render()
        env.step(env.action_space.sample())
        time.sleep(0.05)
    glfw.destroy_window(env.viewer.window)
Example #34
0
File: Lab1.py Project: ROOOOO/Study
def main():
    global delta
    global angle
    # Initialize the library
    if not glfw.init():
        return
    # Create a windowed mode window and its OpenGL context
    window = glfw.create_window(640, 640, "Lab1", None, None)
    if not window:
        glfw.terminate()
        return
    # Make the window's context current
    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    # Loop until the user closes the window
    while not glfw.window_should_close(window):
        # Render here, e.g. using pyOpenGL

        glClear(GL_COLOR_BUFFER_BIT)
        glLoadIdentity()
        glClearColor(1.0, 1.0, 1.0, 1.0)
        glPushMatrix()

        glRotatef(angle, 0, 0, 1)

        glBegin(GL_QUADS)

        glColor3f(0.0,0.0,0.0)
        glVertex3f( 0.5, 0.5, 0.0)
        glColor3f(1.0,0.0,0.0)
        glVertex3f(-0.5, 0.5, 0.0)
        glColor3f(0.0,0.0,1.0)
        glVertex3f(-0.5, -0.5, 0.0)
        glColor3f(1.0,0.0,1.0)
        glVertex3f( 0.5, -0.5, 0.0)


        glEnd()

        glPopMatrix()
        angle += delta

        # Swap front and back buffers
        glfw.swap_buffers(window)
        # Poll for and process events
        glfw.poll_events()
    glfw.destroy_window(window)
    glfw.terminate()
Example #35
0
def main():

    glfw.init()

    window = glfw.create_window( 640, 480, "glfw triangle", None, None )
    
    glfw.make_context_current( window )
    glfw.swap_interval( 1 )
    glfw.set_key_callback( window, on_key )

    while not glfw.window_should_close( window ):

        # set up model view
        width, height = glfw.get_framebuffer_size( window )
        ratio = width / float(height)
        gl.glViewport( 0, 0, width, height )
        gl.glClear( gl.GL_COLOR_BUFFER_BIT )
        gl.glMatrixMode( gl.GL_PROJECTION )
        gl.glLoadIdentity()
        gl.glOrtho( -ratio, ratio, -1.0, 1.0, 1.0, -1.0 )
        gl.glMatrixMode( gl.GL_MODELVIEW )
        gl.glLoadIdentity()
        gl.glRotatef( float(glfw.get_time()) * 50.0, 0.0, 0.0, 1.0 )

        # draw triangle
        gl.glBegin(gl.GL_TRIANGLES);
        gl.glColor3f( 1.0, 0.0, 0.0 )
        gl.glVertex3f( -0.6, -0.4, 0.0 )
        gl.glColor3f( 0.0, 1.0, 0.0 )
        gl.glVertex3f( 0.6, -0.4, 0.0 )
        gl.glColor3f( 0.0, 0.0, 1.0 )
        gl.glVertex3f( 0.0, 0.6, 0.0 )
        gl.glEnd()

        # swap buffers
        glfw.swap_buffers(window)

        # poll for events
        glfw.poll_events()
    
    glfw.destroy_window(window)
    glfw.terminate()
Example #36
0
 def run(self, render_frame):
     try:
         prev = start = time.time()
         avg_elapsed = 0
         avg_render_elapsed = 0
         while not glfw.window_should_close(self.win):
             time0 = time.time()
             render_frame()
             avg_render_elapsed = avg_render_elapsed * 0.9 + (time.time() - time0) * 0.1
             glfw.swap_buffers(self.win)
             glfw.poll_events()
             now = time.time()
             avg_elapsed = avg_elapsed * 0.9 + (now - prev) * 0.1
             prev = now
             if now - start >= 1.0:
                 print("%.1f fps, %.1f%% spent in render" % (1/avg_elapsed, 100*avg_render_elapsed/avg_elapsed))
                 start = now
     finally:
         glfw.destroy_window(self.win)
         glfw.terminate()
Example #37
0
 def close(self):
     """Close the window and uninitialize the resources
     """
     _hw_handle = None
     try:
         _hw_handle = self.win._hw_handle
         # We need to call this when closing a window, however the window
         # object is None at this point! So the GLFW window object lives on.
         win = glfw.get_window_user_pointer(self.winHandle)
         glfw.destroy_window(win)
     except Exception:
         pass
     # If iohub is running, inform it to stop looking for this win id
     # when filtering kb and mouse events (if the filter is enabled of
     # course)
     try:
         if IOHUB_ACTIVE and _hw_handle:
             from psychopy.iohub.client import ioHubConnection
             conn = ioHubConnection.ACTIVE_CONNECTION
             conn.unregisterWindowHandles(_hw_handle)
     except Exception:
         pass
Example #38
0
 def destroyGL(self):
     glfw.destroy_window(self.window)
     glfw.terminate()
Example #39
0
 def teardown(self):
     glfw.destroy_window(self.window)
     glfw.terminate()
Example #40
0
def main():
    global rotation_angle
    global d_x

    # Initialize the library
    if not glfw.init():
        print("library is not initialized")
        return
    # Create a windowed mode window and its OpenGL context
    window = glfw.create_window(640, 480, "Hello World", None, None)
    if not window:
        glfw.terminate()
        return

    # Make the window's context current
    glfw.make_context_current(window)

    print(glfw.__version__)



    glfw.set_key_callback(window, on_key)
    #glfw.set_mouse_button_callback(window, on_mouse)
    # Loop until the user closes the window
    while not glfw.window_should_close(window):
        # Render here, e.g. using pyOpenGL

        width, height = glfw.get_framebuffer_size(window)
        ratio = width / float(height)

        rotation_angle += 0.1

        # Set viewport
        gl.glViewport(0, 0, width, height)
        # Clear color buffer
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        # Select and setup the projection matrix
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.glOrtho(-ratio, ratio, -1, 1, 1, -1)

        # Select and setup the modelview matrix
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        gl.glRotatef(rotation_angle, 0, 0, 1)
        gl.glBegin(gl.GL_POLYGON)
        gl.glColor3f(color.red, color.green, color.blue)
        gl.glVertex3f(-0.5 + d_x, -0.5, 0)
        gl.glColor3f(color.red, color.green, color.blue)
        gl.glVertex3f(-0.5 + d_x, +0.5, 0)
        gl.glColor3f(color.red, color.green, color.blue)
        gl.glVertex3f( 0.5 + d_x, +0.5, 0)
        gl.glColor3f(color.red, color.green, color.blue)
        gl.glVertex3f( 0.5 + d_x, -0.5, 0)
        gl.glEnd()

        # Swap front and back buffers
        glfw.swap_buffers(window)

        # Poll for and process events
        glfw.poll_events()

    # terminating the whole proccess
    glfw.destroy_window(window)
    glfw.terminate()
Example #41
0
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glViewport(0, 0, window_width, window_height);

if __name__=='__main__':
    glfw.init()
    window_width = 640
    window_height = 480
    win = glfw.create_window(window_width , window_height,"GL", None, None)
    setGLFWOptions(win)

    matrixScene.window_width = window_width
    matrixScene.window_height = window_height

    time.actual_time = time.previous_time = glfw.get_time()

    showInfoAboutGl()


    app = Obj('./models/Cat.obj', 'shaders/13_vertex_shader.glsl', 'shaders/13_fragment_shader.glsl')
    app.setTexFiltering()

    while not glfw.window_should_close(win):
        time.previous_time = time.actual_time;
        time.actual_time = glfw.get_time();
        clearColorSetViewport(0.5,0.1,0.2)
        app.render()
        glfw.swap_buffers(win)
        glfw.poll_events()

    glfw.destroy_window(win)
    glfw.terminate()