Example #1
0
    mvpPipeline = es.SimpleModelViewProjectionShaderProgram()
    texture2dPipeline = es.SimpleTextureTransformShaderProgram()

    # Setting up the clear screen color
    glClearColor(0.25, 0.25, 0.25, 1.0)

    # 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)
    # Setting up the clear screen color
    glClearColor(0.15, 0.15, 0.15, 1.0)

    # 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)

    # 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()
    # Setting up the clear screen color
    glClearColor(0.85, 0.85, 0.85, 1.0)

    # 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)

    # Convenience function to ease initialization
    def createGPUShape(pipeline, 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(mvpPipeline, bs.createAxis(4))

    # Note: the vertex attribute layout (stride) is the same for the 3 lighting pipelines in
    # this case: flatPipeline, gouraudPipeline and phongPipeline. Hence, the VAO setup can
    # be the same.
    gpuRedCube = createGPUShape(gouraudPipeline, bs.createColorNormalsCube(1,0,0))
    gpuGreenCube = createGPUShape(gouraudPipeline, bs.createColorNormalsCube(0,1,0))
    gpuBlueCube = createGPUShape(gouraudPipeline, bs.createColorNormalsCube(0,0,1))
    gpuYellowCube = createGPUShape(gouraudPipeline, bs.createColorNormalsCube(1,1,0))
    gpuRainbowCube = createGPUShape(gouraudPipeline, bs.createRainbowNormalsCube())


    t0 = glfw.get_time()
    camera_theta = np.pi/4

    while not glfw.window_should_close(window):
    # Setting up the clear screen color
    glClearColor(0.85, 0.85, 0.85, 1.0)

    # 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)

    # Convenience function to ease initialization
    def createGPUShape(pipeline, 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(colorPipeline, bs.createAxis(4))

    # Note: the vertex attribute layout (stride) is the same for the 3 lighting pipelines in
    # this case: flatPipeline, gouraudPipeline and phongPipeline. Hence, the VAO setup can
    # be the same.
    shapeDice = createDice()
    gpuDice = createGPUShape(textureGouraudPipeline, shapeDice)
    gpuDice.texture = es.textureSimpleSetup(getAssetPath("dice.jpg"),
                                            GL_REPEAT, GL_REPEAT, GL_LINEAR,
                                            GL_LINEAR)

    # Since the only difference between both dices is the texture, we can just use the same
    # GPU data, but with another texture.
    # copy.deepcopy generate a true copy, so if we change gpuDiceBlue.texture (or any other
    # member), we will not change gpuDice.texture
    gpuDiceBlue = copy.deepcopy(gpuDice)