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) projection = tr.perspective(30, float(width)/float(height),0.1, 100) view = tr.lookAt( np.array([5,5,2]), np.array([0,0,0]), np.array([0,0,1]) ) theta = glfw.get_time() axis = np.array([1,-1,1]) axis = axis / np.linalg.norm(axis) model = tr.rotationA(theta, axis) # Drawing axes and cube in a 3D world glUseProgram(mvpPipeline.shaderProgram) glUniformMatrix4fv(glGetUniformLocation(mvpPipeline.shaderProgram, "projection"), 1, GL_TRUE, projection) glUniformMatrix4fv(glGetUniformLocation(mvpPipeline.shaderProgram, "view"), 1, GL_TRUE, view) glUniformMatrix4fv(glGetUniformLocation(mvpPipeline.shaderProgram, "model"), 1, GL_TRUE, tr.identity()) mvpPipeline.drawCall(gpuAxis, GL_LINES)
# Creating shapes on GPU memory ####################### rainbowCube = bs.createRainbowCube() gpuRainbowCube = es.GPUShape().initBuffers() colorShaderProgram.setupVAO(gpuRainbowCube) gpuRainbowCube.fillBuffers(rainbowCube.vertices, rainbowCube.indices, GL_STATIC_DRAW) shapeQuad = bs.createTextureQuad(1, 1) gpuQuad = es.GPUShape().initBuffers() textureShaderProgram.setupVAO(gpuQuad) gpuQuad.fillBuffers(shapeQuad.vertices, shapeQuad.indices, GL_STATIC_DRAW) gpuQuad.texture = textureColorbuffer # <--- Here is where the magic happens! # Setting up the scene view = tr.lookAt(np.array([1.0, 1.0, 1.0]), np.array([0.0, 0.0, 0.0]), np.array([0.0, 0.0, 1.0])) projection = tr.ortho(-1, 1, -1, 1, 0.1, 100) while not glfw.window_should_close(window): # Using GLFW to check for input events glfw.poll_events() # Using the time as the theta parameter theta = glfw.get_time() # Rendering to a texture ####################### glBindFramebuffer(GL_FRAMEBUFFER, framebuffer) #glBindFramebuffer(GL_FRAMEBUFFER, 0) glEnable(GL_DEPTH_TEST) glClearColor(0.15, 0.15, 0.15, 1.0)
if (glfw.get_key(window, glfw.KEY_LEFT) == glfw.PRESS): camera_theta -= 2 * dt if (glfw.get_key(window, glfw.KEY_RIGHT) == glfw.PRESS): camera_theta += 2* dt # Setting up the view transform camX = 10 * np.sin(camera_theta) camY = 10 * np.cos(camera_theta) viewPos = np.array([camX, camY, 10]) view = tr.lookAt( viewPos, np.array([0,0,5]), np.array([0,0,1]) ) glUniformMatrix4fv(glGetUniformLocation(pipeline.shaderProgram, "view"), 1, GL_TRUE, view) # Setting up the projection transform projection = tr.perspective(60, float(width)/float(height), 0.1, 100) glUniformMatrix4fv(glGetUniformLocation(pipeline.shaderProgram, "projection"), 1, GL_TRUE, projection) # Clearing the screen in both, color and depth glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glUniformMatrix4fv(glGetUniformLocation(pipeline.shaderProgram, "model"), 1, GL_TRUE, tr.identity()) pipeline.drawCall(gpuAxis, GL_LINES)
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) projection = tr.ortho(-1, 1, -1, 1, 0.1, 100) view = tr.lookAt(np.array([10, 10, 5]), np.array([0, 0, 0]), np.array([0, 0, 1])) theta = glfw.get_time() axis = np.array([1, -1, 1]) axis = axis / np.linalg.norm(axis) model = tr.rotationA(theta, axis) # Drawing axes (no texture) glUseProgram(colorShaderProgram.shaderProgram) glUniformMatrix4fv( glGetUniformLocation(colorShaderProgram.shaderProgram, "projection"), 1, GL_TRUE, projection) glUniformMatrix4fv( glGetUniformLocation(colorShaderProgram.shaderProgram, "view"), 1, GL_TRUE, view) glUniformMatrix4fv(