Example #1
0
def createTextureGPUShape(shape, pipeline, path):
    # Funcion Conveniente para facilitar la inicializacion de un GPUShape con texturas
    gpuShape = es.GPUShape().initBuffers()
    pipeline.setupVAO(gpuShape)
    gpuShape.fillBuffers(shape.vertices, shape.indices, GL_STATIC_DRAW)
    gpuShape.texture = es.textureSimpleSetup(path, GL_CLAMP_TO_EDGE,
                                             GL_CLAMP_TO_EDGE, GL_NEAREST,
                                             GL_NEAREST)
    return gpuShape
Example #2
0
    # 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()

        # 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)
Example #3
0
    # Creating shader program
    pipeline = es.SimpleTextureTransformShaderProgram()

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

    # Shape on CPU memory
    shapeTextureQuad = bs.createTextureQuad(1, 1)

    # Shapes on GPU memory
    gpuShapeWithoutMipmap = es.GPUShape().initBuffers()
    pipeline.setupVAO(gpuShapeWithoutMipmap)
    gpuShapeWithoutMipmap.fillBuffers(shapeTextureQuad.vertices,
                                      shapeTextureQuad.indices, GL_STATIC_DRAW)
    gpuShapeWithoutMipmap.texture = es.textureSimpleSetup(
        getAssetPath("red_woodpecker.jpg"), GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
        GL_LINEAR, GL_LINEAR)

    # Since we want to draw the same shape, but with mipmaps in its texture, there is no need to duplicate
    # the information in the GPU, we can just use the same buffers...
    gpuShapeWithMipmap = es.GPUShape()
    gpuShapeWithMipmap.vao = gpuShapeWithoutMipmap.vao
    gpuShapeWithMipmap.vbo = gpuShapeWithoutMipmap.vbo
    gpuShapeWithMipmap.ebo = gpuShapeWithoutMipmap.ebo
    gpuShapeWithMipmap.size = gpuShapeWithoutMipmap.size

    # ... but with a different texture
    textureWithMipmap = es.textureSimpleSetup(
        getAssetPath("red_woodpecker.jpg"), GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
        GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR)
    glGenerateMipmap(
Example #4
0
    # A simple shader program with position and texture coordinates as inputs.
    pipeline = es.SimpleTextureTransformShaderProgram()

    # Telling OpenGL to use our shader program
    glUseProgram(pipeline.shaderProgram)

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

    # Creating shapes on GPU memory
    shape = bs.createTextureQuad(2, 2)
    gpuShape = es.GPUShape().initBuffers()
    pipeline.setupVAO(gpuShape)
    gpuShape.fillBuffers(shape.vertices, shape.indices, GL_STATIC_DRAW)
    gpuShape.texture = es.textureSimpleSetup(getAssetPath("bricks.jpg"),
                                             GL_CLAMP_TO_EDGE,
                                             GL_CLAMP_TO_EDGE, GL_LINEAR,
                                             GL_LINEAR)

    while not glfw.window_should_close(window):
        # Using GLFW to check for input events
        glfw.poll_events()

        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)

        # Drawing the shapes
Example #5
0
    glUseProgram(pipeline.shaderProgram)

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

    # Enabling transparencies
    glEnable(GL_BLEND)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

    # Creating shapes on GPU memory
    shapeBoo = bs.createTextureQuad(1, 1)
    gpuBoo = GPUShape().initBuffers()
    pipeline.setupVAO(gpuBoo)
    gpuBoo.fillBuffers(shapeBoo.vertices, shapeBoo.indices, GL_STATIC_DRAW)
    gpuBoo.texture = es.textureSimpleSetup(getAssetPath("boo.png"),
                                           GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
                                           GL_NEAREST, GL_NEAREST)

    shapeQuestionBoxes = bs.createTextureQuad(10, 1)
    gpuQuestionBoxes = GPUShape().initBuffers()
    pipeline.setupVAO(gpuQuestionBoxes)
    gpuQuestionBoxes.fillBuffers(shapeQuestionBoxes.vertices,
                                 shapeQuestionBoxes.indices, GL_STATIC_DRAW)
    gpuQuestionBoxes.texture = es.textureSimpleSetup(
        getAssetPath("cg_box.png"), GL_REPEAT, GL_REPEAT, GL_NEAREST,
        GL_NEAREST)

    questionBoxesTransform = np.matmul(tr.translate(0, -0.8, 0),
                                       tr.scale(2, 0.2, 1))

    while not glfw.window_should_close(window):
Example #6
0
    gpuText3DTexture = tx.toOpenGLTexture(textBitsTexture)

    # Testing text 3D texture. Check the terminal!
    for char in "hi!":
        print(textBitsTexture[:, :, ord(char)].transpose() * 255)
        print()

    # Creating shapes on GPU memory
    backgroundShape = bs.createTextureQuad(1, 1)
    bs.scaleVertices(backgroundShape, 5, [2, 2, 1])
    gpuBackground = es.GPUShape().initBuffers()
    texturePipeline.setupVAO(gpuBackground)
    gpuBackground.fillBuffers(backgroundShape.vertices,
                              backgroundShape.indices, GL_STATIC_DRAW)
    gpuBackground.texture = es.textureSimpleSetup(
        getAssetPath("torres-del-paine-sq.jpg"), GL_CLAMP_TO_EDGE,
        GL_CLAMP_TO_EDGE, GL_LINEAR, GL_LINEAR)

    headerText = "Torres del Paine"
    headerCharSize = 0.1
    headerCenterX = headerCharSize * len(headerText) / 2
    headerShape = tx.textToShape(headerText, headerCharSize, headerCharSize)
    gpuHeader = es.GPUShape().initBuffers()
    textPipeline.setupVAO(gpuHeader)
    gpuHeader.fillBuffers(headerShape.vertices, headerShape.indices,
                          GL_STATIC_DRAW)
    gpuHeader.texture = gpuText3DTexture
    headerTransform = tr.matmul([
        tr.translate(0.9, -headerCenterX, 0),
        tr.rotationZ(np.pi / 2),
    ])
Example #7
0
    colorShaderProgram = es.SimpleModelViewProjectionShaderProgram()

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

    # Creating shapes on GPU memory
    shapeDice = createDice()
    gpuDice = es.GPUShape().initBuffers()
    textureShaderProgram.setupVAO(gpuDice)
    gpuDice.fillBuffers(shapeDice.vertices, shapeDice.indices, GL_STATIC_DRAW)
    gpuDice.texture = es.textureSimpleSetup(getAssetPath("dice_blue.jpg"),
                                            GL_REPEAT, GL_REPEAT, GL_LINEAR,
                                            GL_LINEAR)

    cpuAxis = bs.createAxis(2)
    gpuAxis = es.GPUShape().initBuffers()
    colorShaderProgram.setupVAO(gpuAxis)
    gpuAxis.fillBuffers(cpuAxis.vertices, cpuAxis.indices, GL_STATIC_DRAW)

    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:
Example #8
0
    glfw.set_cursor_pos_callback(window, cursor_pos_callback)

    # A simple shader program with position and texture coordinates as inputs.
    pipeline = DoubleTextureTransformShaderProgram()
    
    # Telling OpenGL to use our shader program

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

    # Creating shapes on GPU memory
    shape = bs.createTextureQuad(1, 1)
    gpuShape = TexGPUShape().initBuffers()
    pipeline.setupVAO(gpuShape)
    gpuShape.fillBuffers(shape.vertices, shape.indices, GL_STATIC_DRAW)
    gpuShape.texture = es.textureSimpleSetup(
        getAssetPath("bricks.jpg"), GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_LINEAR, GL_LINEAR)
    gpuShape.texture2 = es.textureSimpleSetup(
        getAssetPath("boo.png"), GL_REPEAT, GL_REPEAT, GL_NEAREST, GL_NEAREST)

    currentMousePos = [width/2, height/2]

    while not glfw.window_should_close(window):
        # Using GLFW to check for input events
        glfw.poll_events()

        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
    # A simple shader program with position and texture coordinates as inputs.
    pipeline = DoubleTextureTransformShaderProgram()

    # Telling OpenGL to use our shader program

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

    # Creating shapes on GPU memory
    shape = bs.createTextureQuad(1, 1)
    gpuShape = TexGPUShape().initBuffers()
    pipeline.setupVAO(gpuShape)
    gpuShape.fillBuffers(shape.vertices, shape.indices, GL_STATIC_DRAW)
    gpuShape.texture = es.textureSimpleSetup(
        getAssetPath("torres-del-paine-sq.jpg"), GL_CLAMP_TO_EDGE,
        GL_CLAMP_TO_EDGE, GL_LINEAR, GL_LINEAR)
    gpuShape.texture2 = es.textureSimpleSetup(
        getAssetPath("red_woodpecker.jpg"), GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
        GL_LINEAR, GL_LINEAR)

    currentMousePos = [width / 2, height / 2]

    while not glfw.window_should_close(window):
        # Using GLFW to check for input events
        glfw.poll_events()

        if (controller.fillPolygon):
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        else:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
        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.
    meshPyramid = createPyramidMesh()
    shapePyramid = toShape(meshPyramid, color=(0.6, 0.1, 0.1), verbose=True)
    gpuPyramid = createGPUShape(lightingPipeline, shapePyramid)

    meshTexturedPyramid = createPyramidMesh(True)
    shapeTexturedPyramid = toShape(meshTexturedPyramid, textured=True, verbose=False)
    gpuTexturedPyramid = createGPUShape(texturePipeline, shapeTexturedPyramid)
    gpuTexturedPyramid.texture = es.textureSimpleSetup(
        getAssetPath("bricks.jpg"), GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_LINEAR, GL_LINEAR)
    
    #print(shapeTexturedPyramid)

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

    def setupLightingDefaults(pipeline):
        glUseProgram(pipeline.shaderProgram)

        # White light in all components: ambient, diffuse and specular.
        glUniform3f(glGetUniformLocation(pipeline.shaderProgram, "La"), 1.0, 1.0, 1.0)
        glUniform3f(glGetUniformLocation(pipeline.shaderProgram, "Ld"), 1.0, 1.0, 1.0)
        glUniform3f(glGetUniformLocation(pipeline.shaderProgram, "Ls"), 1.0, 1.0, 1.0)

        # Object is barely visible at only ambient. Bright white for diffuse and specular components.