# and which one is at the back glEnable(GL_DEPTH_TEST) # Creating shapes on GPU memory shapeTriangle = bs.createRainbowTriangle() gpuTriangle = es.GPUShape().initBuffers() pipeline.setupVAO(gpuTriangle) gpuTriangle.fillBuffers(shapeTriangle.vertices, shapeTriangle.indices, GL_STATIC_DRAW) shapeQuad = bs.createRainbowQuad() gpuQuad = es.GPUShape().initBuffers() pipeline.setupVAO(gpuQuad) gpuQuad.fillBuffers(shapeQuad.vertices, shapeQuad.indices, GL_STATIC_DRAW) shapeCube = bs.createRainbowCube() gpuCube = es.GPUShape().initBuffers() pipeline.setupVAO(gpuCube) gpuCube.fillBuffers(shapeCube.vertices, shapeCube.indices, GL_STATIC_DRAW) shapeCircle = bs.createRainbowCircle(20) gpuCircle = es.GPUShape().initBuffers() pipeline.setupVAO(gpuCircle) gpuCircle.fillBuffers(shapeCircle.vertices, shapeCircle.indices, GL_STATIC_DRAW) while not glfw.window_should_close(window): # Using GLFW to check for input events glfw.poll_events() if (controller.fillPolygon):
# As we work in 3D, we need to check which part is in front, # and which one is at the back glEnable(GL_DEPTH_TEST) # Enabling transparencies glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) # Creating shapes on GPU memory cpuAxis = bs.createAxis(7) gpuAxis = es.GPUShape().initBuffers() mvpPipeline.setupVAO(gpuAxis) gpuAxis.fillBuffers(cpuAxis.vertices, cpuAxis.indices, GL_STATIC_DRAW) rainbowCube = bs.createRainbowCube() gpuRainbowCube = es.GPUShape().initBuffers() mvpPipeline.setupVAO(gpuRainbowCube) gpuRainbowCube.fillBuffers(rainbowCube.vertices, rainbowCube.indices, GL_STATIC_DRAW) shapeBoo = bs.createTextureQuad(1,1) gpuBoo = es.GPUShape().initBuffers() texture2dPipeline.setupVAO(gpuBoo) gpuBoo.fillBuffers(shapeBoo.vertices, shapeBoo.indices, GL_STATIC_DRAW) gpuBoo.texture = es.textureSimpleSetup( getAssetPath("boo.png"), GL_REPEAT, GL_REPEAT, GL_NEAREST, GL_NEAREST) while not glfw.window_should_close(window): # Using GLFW to check for input events glfw.poll_events()
# Convenience function to ease initialization def createGPUShape(shape): gpuShape = es.GPUShape().initBuffers() pipeline.setupVAO(gpuShape) gpuShape.fillBuffers(shape.vertices, shape.indices, GL_STATIC_DRAW) return gpuShape # Creating shapes on GPU memory gpuAxis = createGPUShape(bs.createAxis(7)) gpuRedCube = createGPUShape(bs.createColorCube(1, 0, 0)) gpuGreenCube = createGPUShape(bs.createColorCube(0, 1, 0)) gpuBlueCube = createGPUShape(bs.createColorCube(0, 0, 1)) gpuYellowCube = createGPUShape(bs.createColorCube(1, 1, 0)) gpuCyanCube = createGPUShape(bs.createColorCube(0, 1, 1)) gpuPurpleCube = createGPUShape(bs.createColorCube(1, 0, 1)) gpuRainbowCube = createGPUShape(bs.createRainbowCube()) t0 = glfw.get_time() camera_theta = np.pi / 4 while not glfw.window_should_close(window): # Using GLFW to check for input events glfw.poll_events() # Getting the time difference from the previous iteration t1 = glfw.get_time() dt = t1 - t0 t0 = t1 if (glfw.get_key(window, glfw.KEY_LEFT) == glfw.PRESS): camera_theta -= 2 * dt