How to use the glfw.window_should_close function in glfw

To help you get started, we’ve selected a few glfw examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nobuyuki83 / delfem2 / examples_py / 00_openwin_glfw.py View on Github external
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")
github Jerdak / opengl_tutorials_python / tutorial2.py View on Github external
1.0, -1.0, 0.0,
					0.0,  1.0, 0.0]

	vertex_buffer = glGenBuffers(1);
	
	# GLFloat = c_types.c_float
	array_type = GLfloat * len(vertex_data)

	# array_type = c_types.c_float_array_9 so unpack values of vertex array
	x = array_type(*vertex_data)


	glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer)
	glBufferData(GL_ARRAY_BUFFER, len(vertex_data) * 4, array_type(*vertex_data), GL_STATIC_DRAW)

	while glfw.get_key(window,glfw.KEY_ESCAPE) != glfw.PRESS and not glfw.window_should_close(window):
		glClear(GL_COLOR_BUFFER_BIT)

		glUseProgram(program_id)	

		# Bind vertex buffer data to the attribute 0 in our shader.
		# Note:  This can also be done in the VAO itself (see vao_test.py)

		# Enable the vertex attribute at element[0], in this case that's the triangle's vertices
		# this could also be color, normals, etc.  It isn't necessary to disable these
		#
		glEnableVertexAttribArray(0)
		glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
		glVertexAttribPointer(
			0,                  # attribute 0. No particular reason for 0, but must match the layout in the shader.
			3,                  # len(vertex_data)
			GL_FLOAT,           # type
github Jerdak / opengl_tutorials_python / tutorial7.py View on Github external
uv_data = objloader.generate_2d_ctypes(uv_data)

    # Load OBJ in to a VBO
    vertex_buffer = glGenBuffers(1)
    glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer)
    glBufferData(GL_ARRAY_BUFFER, len(vertex_data) * 4 * 3, vertex_data, GL_STATIC_DRAW)

    uv_buffer = glGenBuffers(1)
    array_type = GLfloat * len(uv_data)
    glBindBuffer(GL_ARRAY_BUFFER, uv_buffer)
    glBufferData(GL_ARRAY_BUFFER, len(uv_data) * 4 * 2, uv_data, GL_STATIC_DRAW)

    # vsync and glfw do not play nice.  when vsync is enabled mouse movement is jittery.
    common.disable_vsyc()
    
    while glfw.get_key(window,glfw.KEY_ESCAPE) != glfw.PRESS and not glfw.window_should_close(window):
        glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT)

        glUseProgram(program_id)

        controls.computeMatricesFromInputs(window)
        ProjectionMatrix = controls.getProjectionMatrix()
        ViewMatrix = controls.getViewMatrix()
        ModelMatrix = mat4.identity()
        mvp = ProjectionMatrix * ViewMatrix * ModelMatrix

        # Send our transformation to the currently bound shader, 
        # in the "MVP" uniform
        glUniformMatrix4fv(matrix_id, 1, GL_FALSE,mvp.data)
        
        # Bind our texture in Texture Unit 0
        glActiveTexture(GL_TEXTURE0)
github rlworkgroup / garage / src / garage / envs / dm_control / dm_control_viewer.py View on Github external
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()
github 3D-Printing-for-Microfluidics / OpenGL-STL-slicer / app.py View on Github external
glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL_TRUE)
        
    window = glfw.create_window(SCR_WIDTH, SCR_HEIGHT, 'STL Slicer', None, None)
    glfw.make_context_current(window)
    glfw.set_framebuffer_size_callback(window, framebuffer_size_callback)
    glfw.set_input_mode(window, glfw.CURSOR, glfw.CURSOR_NORMAL)
    
    loadMesh(stl_filename)
    glBindVertexArray(params.maskVAO)
    slicer_folder = os.path.dirname(os.path.abspath(__file__))
    sliceShader = OurShaderProgram(os.path.join(slicer_folder, 'shaders', 'slice.vert'), 
                                   os.path.join(slicer_folder, 'shaders', 'slice.frag'))
    prepareSlice()
    
    i, height = 0, 0.
    while not glfw.window_should_close(window):
        processInput(window)
        
        if height >= params.total_thickness - EPSILON:
            break
        else:
            height += layer_thickness
            i += 1
        
        draw(sliceShader, height-EPSILON)
        renderSlice(sliceShader, height-EPSILON, os.path.join(slice_save_path, 'out{:04d}.png'.format(i-1)))
        
        glfw.swap_buffers(window)
        glfw.poll_events()
    
    glfw.terminate()
github mdcutone / psychxr / demo / rift / libovr_headtracking.py View on Github external
GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0)

    mirrorFbo = GL.GLuint()
    GL.glGenFramebuffers(1, ctypes.byref(mirrorFbo))
    createMirrorTexture(800, 600, mirrorOptions=MIRROR_OPTION_DEFAULT)

    frame_index = 0

    projectionMatrix = []
    for eye in range(EYE_COUNT):
         projectionMatrix.append(getEyeProjectionMatrix(eye))

    planePose = LibOVRPose((0., 0., -2.))

    # begin application loop
    while not glfw.window_should_close(window):
        waitToBeginFrame(frame_index)

        abs_time = getPredictedDisplayTime(frame_index)

        tracking_state = getTrackingState(abs_time, True)

        calcEyePoses(tracking_state.headPose.thePose)

        beginFrame(frame_index)

        GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, fboId)

        _, swapIdx = getTextureSwapChainCurrentIndex(TEXTURE_SWAP_CHAIN0)
        _, tex_id = getTextureSwapChainBufferGL(TEXTURE_SWAP_CHAIN0, swapIdx)

        GL.glFramebufferTexture2D(
github totex / PyOpenGL_tutorials / video_06_quad.py View on Github external
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 24, indices, GL_STATIC_DRAW)

    position = glGetAttribLocation(shader, "position")
    glVertexAttribPointer(position, 3, GL_FLOAT, GL_FALSE, 24, ctypes.c_void_p(0))
    glEnableVertexAttribArray(position)

    color = glGetAttribLocation(shader, "color")
    glVertexAttribPointer(color, 3, GL_FLOAT, GL_FALSE, 24, ctypes.c_void_p(12))
    glEnableVertexAttribArray(color)


    glUseProgram(shader)

    glClearColor(0.2, 0.3, 0.2, 1.0)

    while not glfw.window_should_close(window):
        glfw.poll_events()

        glClear(GL_COLOR_BUFFER_BIT)

        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, None)

        glfw.swap_buffers(window)

    glfw.terminate()
github tangrams / tangram-es / swig / examples / demo.py View on Github external
def loop(self):
        self.running = True

        lastTime = glfw.get_time()

        while not glfw.window_should_close(self.window) and self.running:
            currentTime = glfw.get_time()
            delta = currentTime - lastTime
            lastTime = currentTime

            tangram.poke_network_queue()

            self.m.update(delta)
            self.m.render()

            glfw.swap_buffers(self.window)
            # glfw.poll_events()
            glfw.wait_events()
github totex / PyOpenGL_tutorials / video_07_cube.py View on Github external
position = glGetAttribLocation(shader, "position")
    glVertexAttribPointer(position, 3, GL_FLOAT, GL_FALSE, 24, ctypes.c_void_p(0))
    glEnableVertexAttribArray(position)

    color = glGetAttribLocation(shader, "color")
    glVertexAttribPointer(color, 3, GL_FLOAT, GL_FALSE, 24, ctypes.c_void_p(12))
    glEnableVertexAttribArray(color)


    glUseProgram(shader)

    glClearColor(0.2, 0.3, 0.2, 1.0)
    glEnable(GL_DEPTH_TEST)
    #glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

    while not glfw.window_should_close(window):
        glfw.poll_events()

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        rot_x = pyrr.Matrix44.from_x_rotation(0.5 * glfw.get_time() )
        rot_y = pyrr.Matrix44.from_y_rotation(0.8 * glfw.get_time() )

        transformLoc = glGetUniformLocation(shader, "transform")
        glUniformMatrix4fv(transformLoc, 1, GL_FALSE, rot_x * rot_y)

        glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, None)

        glfw.swap_buffers(window)

    glfw.terminate()
github nobuyuki83 / delfem2 / pydelfem2 / gl / _glfw.py View on Github external
def draw_loop(self):
    """
    Enter the draw loop

    render -- a function to render
    """
    glfw.set_mouse_button_callback(self.win, self.mouse)
    glfw.set_cursor_pos_callback(self.win, self.motion)
    glfw.set_key_callback(self.win, self.keyinput)
#    glfw.set_window_size_callback(self.win, self.window_size)
    while not glfw.window_should_close(self.win):
      gl.glClearColor(self.color_bg[0], self.color_bg[1], self.color_bg[2], 1.0)
      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)
      self.wm.camera.set_gl_camera()
      for func_step_time in self.list_func_step_time:
        func_step_time()
      for draw_func in self.list_func_draw:
        draw_func()
      glfw.swap_buffers(self.win)
      glfw.poll_events()
      if self.wm.isClose:
        break
    self.close()