python_opengl

使用python调用opengl进行渲染 import glfw from OpenGL.GL import * def main(): # Initialize the library if not glfw.init(): 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) count =0; # Loop until the user closes the window while not glfw.window_should_close(window): # Render here, e.g. using pyOpenGL glClearColor(0.2, 0.3, 0.3, 1.0) glClear(GL_COLOR_BUFFER_BIT) glColor3f(1.0, 1.0, 1.0) glBegin(GL_TRIANGLES) glVertex3f(-0.5, -0.5, 0.0) glVertex3f(0.5, -0.5, 0.0) glVertex3f(0.0, 0.5, 0.0) glEnd() # Swap front and back buffers glfw.swap_buffers(window) # Poll for and process events glfw.poll_events() glfw.terminate() if __name__ == "__main__": main()

四月 26, 2025