while not glfw.window_should_close(window): # Using GLFW to check for input events glfw.poll_events() # Filling or not the shapes depending on the controller state if (controller.fillPolygon): glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) else: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) # Clearing the screen in both, color and depth glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) theta = glfw.get_time() Rx = tr.rotationX(np.pi / 3) Ry = tr.rotationY(theta) transform = np.matmul(Rx, Ry) # Drawing the Cube glUniformMatrix4fv( glGetUniformLocation(pipeline.shaderProgram, "transform"), 1, GL_TRUE, transform) pipeline.drawCall(gpuCube) # Once the drawing is rendered, buffers are swap so an uncomplete drawing is never seen. glfw.swap_buffers(window) # freeing GPU memory gpuCube.clear() glfw.terminate()
if (controller.shape == SP_TRIANGLE): glUniformMatrix4fv( glGetUniformLocation(pipeline.shaderProgram, "transform"), 1, GL_TRUE, transform) pipeline.drawCall(gpuTriangle) elif (controller.shape == SP_QUAD): glUniformMatrix4fv( glGetUniformLocation(pipeline.shaderProgram, "transform"), 1, GL_TRUE, transform) pipeline.drawCall(gpuQuad) elif (controller.shape == SP_CUBE): Rx = tr.rotationX(np.pi / 3) Ry = tr.rotationY(np.pi / 3) transform = tr.matmul([Ry, Rx, transform]) glUniformMatrix4fv( glGetUniformLocation(pipeline.shaderProgram, "transform"), 1, GL_TRUE, transform) pipeline.drawCall(gpuCube) elif (controller.shape == SP_CIRCLE): glUniformMatrix4fv( glGetUniformLocation(pipeline.shaderProgram, "transform"), 1, GL_TRUE, transform) pipeline.drawCall(gpuCircle) else: # This should never happen raise Exception()
if (controller.fillPolygon): glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) else: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) if controller.showAxis: glUniformMatrix4fv( glGetUniformLocation(mvpPipeline.shaderProgram, "model"), 1, GL_TRUE, tr.identity()) mvpPipeline.drawCall(gpuAxis, GL_LINES) # Moving the red car and rotating its wheels redCarNode.transform = tr.translate(3 * np.sin(glfw.get_time()), 0, 0.5) redWheelRotationNode = sg.findNode(redCarNode, "wheelRotation") redWheelRotationNode.transform = tr.rotationY(-10 * glfw.get_time()) # Uncomment to print the red car position on every iteration #print(sg.findPosition(redCarNode, "car")) # Drawing the Car sg.drawSceneGraphNode(redCarNode, mvpPipeline, "model") sg.drawSceneGraphNode(blueCarNode, mvpPipeline, "model") # Once the render is done, buffers are swapped, showing only the complete scene. glfw.swap_buffers(window) # freeing GPU memory gpuAxis.clear() redCarNode.clear() blueCarNode.clear()