Beispiel #1
0
def init():
    global theMesh, theLight, theCamera, theScreen
    initializeVAO()
    glEnable(GL_CULL_FACE)
    glEnable(GL_DEPTH_TEST)
    # Add our objects
    # LIGHT
    theLight = N.array((0.577, 0.577, 0.577, 0.0),dtype=N.float32)
    # OBJECT
    verts, elements = readOBJ("suzanne.obj")
    print verts[0:4]
    arrayBuffer = getArrayBuffer(verts)
    elementBuffer = getElementBuffer(elements)
    numElements = len(elements)
    phongShader = makeShader("phongshader.vert", "phongshader.frag")
    theMesh = coloredMesh(N.array((0,1,1,1),dtype=N.float32),
                          arrayBuffer,
                          elementBuffer,
                          numElements,
                          phongShader
                          )
    # CAMERA
    width, height = theScreen.get_size()
    aspectRatio = float(width)/float(height)
    near = 0.01
    far = 100.0
    lens = 4.0  # "longer" lenses mean more telephoto
    theCamera = Camera(lens, near, far, aspectRatio)
    theCamera.moveBack(3)
Beispiel #2
0
def init():
    global theMesh,  theLight, theCamera, \
           theScreen,    resolution
    initializeVAO()
    glEnable(GL_CULL_FACE)
    glEnable(GL_DEPTH_TEST)

    # Add our object
    # LIGHT
    theLight = N.array((-0.577, 0.577, 0.577, 0.0),dtype=N.float32)
    # OBJECT
    phongshader = makeShader("phongshader.vert","phongshader.frag")
    verts, elements = readOBJ("suzanne.obj")
    suzanneVerts = getArrayBuffer(verts)
    suzanneElements = getElementBuffer(elements)
    suzanneNum = len(elements)
    theMesh = coloredMesh(N.array((1.0, 0.5, 1.0, 1.0), dtype=N.float32),
                          suzanneVerts,
                          suzanneElements,
                          suzanneNum,
                          phongshader)

    # CAMERA
    width,height = theScreen.get_size()
    aspectRatio = float(width)/float(height)
    near = 0.01
    far = 100.0
    lens = 4.0  # "longer" lenses mean more telephoto
    theCamera = Camera(lens, near, far, aspectRatio)
    theCamera.moveBack(6)
Beispiel #3
0
def init():
    global theMesh, theTV, theLight, theCamera, \
           theScreen, theTVCamera, theFramebuffers
    initializeVAO()
    glEnable(GL_CULL_FACE)
    glEnable(GL_DEPTH_TEST)

    # FRAMEBUFFERS
    theFramebuffers = [getFramebuffer(512) for x in range(2)]

    # Add our objects
    # LIGHT
    theLight = N.array((0.577, 0.577, 0.577, 0.0),dtype=N.float32)
    # OBJECTS
    verts, elements = readOBJ("suzanne.obj")
    arrayBuffer = getArrayBuffer(verts)
    elementBuffer = getElementBuffer(elements)
    numElements = len(elements)
    phongShader = makeShader("phongshader.vert", "phongshader.frag")
    theMesh = coloredMesh(N.array((0,1,1,1),dtype=N.float32),
                          arrayBuffer,
                          elementBuffer,
                          numElements,
                          phongShader
                          )
    verts, elements = rectangle(2,2)
    arrayBuffer = getArrayBuffer(verts)
    elementBuffer = getElementBuffer(elements)
    numElements = len(elements)
    texturedShader = makeShader("flattextured.vert", "flattextured.frag")
    texture = loadTexture("grid.png")
    theTV = flatTexturedMesh(texture,
                             arrayBuffer,
                             elementBuffer,
                             numElements,
                             texturedShader,
                             fade=0.9)

    theTV.moveRight(2)
    theTV.yaw(-1)

    # CAMERA
    width, height = theScreen.get_size()
    aspectRatio = float(width)/float(height)
    near = 0.01
    far = 100.0
    lens = 4.0  # "longer" lenses mean more telephoto
    theCamera = Camera(lens, near, far, aspectRatio)
    theCamera.moveBack(10)

    # TV CAMERA
    theTVCamera = Camera(lens, near, far, 1.0)
    theTVCamera.yaw(-0.5)
    theTVCamera.moveBack(10)
Beispiel #4
0
def init():
    global theMesh,  theLight, theCamera, \
           theScreen,  theFramebuffers, \
           theSquare, resolution
    initializeVAO()
    glEnable(GL_CULL_FACE)
    glEnable(GL_DEPTH_TEST)

    # FRAMEBUFFER
    # create a frame buffer and bind to it
    resolution = 512
    numBuffers = 8
    theFramebuffers = [getFramebuffer(resolution) for i in range(numBuffers)]

    # SQUARE IN NDC
    verts, elements = rectangle(2,2)
    arrayBuffer = getArrayBuffer(verts)
    elementBuffer = getElementBuffer(elements)
    numElements = len(elements)
    flatShader = makeShader("flattextured.vert", "motionblur.frag")
    texture = loadTexture("grid.png")
    textures = [texture for i in range(8)]
    theSquare = motionblurMesh(textures,
                               arrayBuffer,
                               elementBuffer,
                               numElements,
                               flatShader)

    # Add our object
    # LIGHT
    theLight = N.array((-0.577, 0.577, 0.577, 0.0),dtype=N.float32)
    # OBJECT
    phongshader = makeShader("phongshader.vert","phongshader.frag")
    verts, elements = readOBJ("suzanne.obj")
    suzanneVerts = getArrayBuffer(verts)
    suzanneElements = getElementBuffer(elements)
    suzanneNum = len(elements)
    theMesh = coloredMesh(N.array((1.0, 0.5, 1.0, 1.0), dtype=N.float32),
                          suzanneVerts,
                          suzanneElements,
                          suzanneNum,
                          phongshader)

    # CAMERA
    width,height = theScreen.get_size()
    aspectRatio = float(width)/float(height)
    near = 0.01
    far = 100.0
    lens = 4.0  # "longer" lenses mean more telephoto
    theCamera = Camera(lens, near, far, aspectRatio)
    theCamera.moveBack(6)
Beispiel #5
0
def init():
    global theMeshes, theLight, theCamera, theScreen
    initializeVAO()
    glEnable(GL_CULL_FACE)
    glEnable(GL_DEPTH_TEST)
    # Add our objects
    # LIGHT
    theLight = N.array((0.577, 0.577, 0.577, 0.0),dtype=N.float32)
    # OBJECTS
    theMeshes = []
    phongshader = makeShader("phong.vert","phong.frag")
    suzanne = readOBJ("suzanne.obj")
    for i in range(100):
        if i % 4 == 0:
            major = N.random.random()*2
            minor = major*0.25
            verts,elements = torus(major, minor, 64, 16)
        elif i % 4 == 1:
            radius = N.random.random()*2
            verts,elements = sphere(radius, 64, 32)
        elif i % 4 == 2:
            verts,elements = suzanne
        else:
            size = N.random.random()*4
            verts,elements = tetrahedron(size)            
        newmesh = coloredMesh(N.array((N.random.random(),
                                       N.random.random(),
                                       N.random.random(),
                                       1.0), dtype=N.float32),
                              getArrayBuffer(verts),
                              getElementBuffer(elements),
                              len(elements),
                              phongshader)
        x = N.random.random()*20-10
        y = N.random.random()*20-10
        z = N.random.random()*20-10
        newmesh.moveRight(x)
        newmesh.moveUp(y)
        newmesh.moveBack(z)
        newmesh.pitch(x)
        newmesh.yaw(y)
        newmesh.roll(z)
        theMeshes.append(newmesh)
    # CAMERA
    width, height = theScreen.get_size()
    aspectRatio = float(width)/float(height)
    near = 0.01
    far = 100.0
    lens = 4.0  # "longer" lenses mean more telephoto
    theCamera = Camera(lens, near, far, aspectRatio)
Beispiel #6
0
def makeObjects(n=32, area = 20):
    theMeshes = []
    phongshader = makeShader("phongshader.vert","phongshader.frag")
    verts, elements = torus(1,0.25,64,16)
    torusVerts = getArrayBuffer(verts)
    torusElements = getElementBuffer(elements)
    torusNum = len(elements)
    verts, elements = sphere(1,64,32)
    sphereVerts = getArrayBuffer(verts)
    sphereElements = getArrayBuffer(elements)
    sphereNum = len(elements)
    verts, elements = tetrahedron(2)
    tetraVerts = getArrayBuffer(verts)
    tetraElements = getElementBuffer(elements)
    tetraNum = len(elements)
    verts, elements = readOBJ("suzanne.obj")
    suzanneVerts = getArrayBuffer(verts)
    suzanneElements = getElementBuffer(elements)
    suzanneNum = len(elements)
    for i in range(n):
        if i % 4 == 0:
            verts, elements, num = torusVerts, torusElements, torusNum
        elif i % 4 == 1:
            verts,elements, num = sphereVerts, sphereElements, torusNum
        elif i % 4 == 2:
            verts, elements, num = suzanneVerts, suzanneElements, torusNum
        else:
            verts, elements = tetraVerts, tetraElements
        newmesh = coloredMesh(N.array((N.random.random(),
                                       N.random.random(),
                                       N.random.random(),
                                       1.0), dtype=N.float32),
                              verts,
                              elements,
                              num,
                              phongshader)
        x = N.random.random()*area - 0.5*area
        y = N.random.random()*area - 0.5*area
        z = N.random.random()*area - 0.5*area
        newmesh.moveRight(x)
        newmesh.moveUp(y)
        newmesh.moveBack(z)
        newmesh.pitch(x)
        newmesh.yaw(y)
        newmesh.roll(z)
        theMeshes.append(newmesh)
    return theMeshes
Beispiel #7
0
def init():
    global theMeshes, theBox, theLight, theCamera, theScreen, theTextures
    initializeVAO()
    glEnable(GL_CULL_FACE)
    glEnable(GL_DEPTH_TEST)
    # Add our objects
    # OBJECTS
    theMeshes = []
    phongshader = makeShader("phong.vert", "phong.frag")
    for i in range(16):
        if i % 4 == 0:
            major = N.random.random() * 2
            minor = major * 0.25
            verts, elements = torus(major, minor, 64, 16)
        elif i % 4 == 1:
            radius = N.random.random() * 2
            verts, elements = sphere(radius, 64, 32)
        elif i % 4 == 2:
            verts, elements = readOBJ("suzanne.obj")
        else:
            size = N.random.random() * 4
            verts, elements = tetrahedron(size)
        newmesh = coloredMesh(
            N.array((N.random.random(), N.random.random(), N.random.random(), 1.0), dtype=N.float32),
            getArrayBuffer(verts),
            getElementBuffer(elements),
            len(elements),
            phongshader,
        )
        x = N.random.random() * 20 - 10
        y = N.random.random() * 20 - 10
        z = N.random.random() * 20 - 10
        newmesh.moveRight(x)
        newmesh.moveUp(y)
        newmesh.moveBack(z)
        newmesh.pitch(x)
        newmesh.yaw(y)
        newmesh.roll(z)
        theMeshes.append(newmesh)
    # LIGHT
    # put the light in a direction to agree with the skybox
    theLight = N.array((0.707, 0.707, 0.0, 0.0), dtype=N.float32)
    # TEXTURES
    theTextures = []
    images = ["figposx.png", "fignegx.png", "figposy.png", "fignegy.png", "figposz.png", "fignegz.png"]
    theTextures.append([loadTexture(img, magFilter=GL_LINEAR, wrapMode=GL_CLAMP_TO_EDGE) for img in images])
    images = [
        "terragenposx.png",
        "terragennegx.png",
        "terragenposy.png",
        "terragennegy.png",
        "terragenposz.png",
        "terragennegz.png",
    ]
    theTextures.append([loadTexture(img, magFilter=GL_LINEAR, wrapMode=GL_CLAMP_TO_EDGE) for img in images])
    # these images have Z backwards from opengl
    images = [
        "goldengateposx.jpg",
        "goldengatenegx.jpg",
        "goldengateposy.jpg",
        "goldengatenegy.jpg",
        "goldengatenegz.jpg",
        "goldengateposz.jpg",
    ]
    theTextures.append([loadTexture(img, magFilter=GL_LINEAR, wrapMode=GL_CLAMP_TO_EDGE) for img in images])
    # these images have X backwards from opengl
    images = [
        "lancellottiposx.jpg",
        "lancellottinegx.jpg",
        "lancellottiposy.jpg",
        "lancellottinegy.jpg",
        "lancellottinegz.jpg",
        "lancellottiposz.jpg",
    ]
    theTextures.append([loadTexture(img, magFilter=GL_LINEAR, wrapMode=GL_CLAMP_TO_EDGE) for img in images])

    # SKYBOX
    boxsize = 1.0
    skyboxShader = makeShader("flattextured.vert", "flattextured.frag")
    verts, elements = rectangle(boxsize, boxsize)
    vertBuff = getArrayBuffer(verts)
    elemBuff = getElementBuffer(elements)
    numElem = len(elements)
    posx = flatTexturedMesh(
        theTextures[0][0], vertBuff, elemBuff, numElem, skyboxShader, N.array((1.0, 1.0), dtype=N.float32)
    )
    negx = flatTexturedMesh(
        theTextures[0][1], vertBuff, elemBuff, numElem, skyboxShader, N.array((1.0, 1.0), dtype=N.float32)
    )
    posy = flatTexturedMesh(
        theTextures[0][2], vertBuff, elemBuff, numElem, skyboxShader, N.array((1.0, 1.0), dtype=N.float32)
    )
    negy = flatTexturedMesh(
        theTextures[0][3], vertBuff, elemBuff, numElem, skyboxShader, N.array((1.0, 1.0), dtype=N.float32)
    )
    posz = flatTexturedMesh(
        theTextures[0][4], vertBuff, elemBuff, numElem, skyboxShader, N.array((1.0, 1.0), dtype=N.float32)
    )
    negz = flatTexturedMesh(
        theTextures[0][5], vertBuff, elemBuff, numElem, skyboxShader, N.array((1.0, 1.0), dtype=N.float32)
    )

    backDistance = -boxsize * 0.5

    posx.yaw(-1)
    posx.yaw(-1)
    posx.moveBack(backDistance)

    negx.yaw(1)
    negx.yaw(1)
    negx.moveBack(backDistance)

    for i in range(2):
        posy.pitch(-1)
    posy.moveBack(backDistance)

    for i in range(2):
        negy.pitch(1)
    negy.moveBack(backDistance)

    for i in range(4):
        posz.yaw(1)
    posz.moveBack(backDistance)

    negz.moveBack(backDistance)

    theBox = [posx, negx, posy, negy, posz, negz]

    # CAMERA
    width, height = theScreen.get_size()
    aspectRatio = float(width) / float(height)
    near = 0.01
    far = 1000.0
    lens = 2.0  # A wide lens will minimize pixels in the background
    theCamera = Camera(lens, near, far, aspectRatio)
    theCamera.moveBack(10)
Beispiel #8
0
def init():
    global theMeshes, theBox, theLight, theCamera, theCameras, \
        theScreen, theTextures,\
        nonReflectors, theFramebuffers
    initializeVAO()
    glEnable(GL_CULL_FACE)
    glEnable(GL_DEPTH_TEST)
    # REFLECTOR CAMERAS AND FRAMEBUFFERS
    theFramebuffers = [getFramebuffer(512) for x in range(6)]
    theCameras = [Camera(1.0, 0.01, 1000.0, 1.0) for x in range(6)]
    # X
    theCameras[0].yaw(-1)
    theCameras[0].yaw(-1)
    theCameras[1].yaw(+1)
    theCameras[1].yaw(+1)
    # Y
    theCameras[2].pitch(-1)
    theCameras[2].pitch(-1)
    theCameras[3].pitch(+1)
    theCameras[3].pitch(+1)
    # Z
    theCameras[4].yaw(1)
    theCameras[4].yaw(1)
    theCameras[4].yaw(1)
    theCameras[4].yaw(1)
    # negZ camera already pointed

    # LIGHT
    # put the light in a direction to agree with the skybox
    theLight = N.array((0.707, 0.707, 0.0, 0.0),dtype=N.float32)
    # we need the textures to define our reflecting objects

    # NONREFLECTING OBJECTS
    nonReflectors = makeObjects(32)

    # TEXTURES
    theTextures = []
    images = ["figposx.png",
              "fignegx.png",
              "figposy.png",
              "fignegy.png",
              "figposz.png",
              "fignegz.png"]
    theTextures.append( [loadTexture(img,
                                     magFilter=GL_LINEAR,
                                     wrapMode=GL_CLAMP_TO_EDGE)
                         for img in images] )
    images = ["terragenposx.png",
              "terragennegx.png",
              "terragenposy.png",
              "terragennegy.png",
              "terragenposz.png",
              "terragennegz.png"]
    theTextures.append( [loadTexture(img,
                                     magFilter=GL_LINEAR,
                                     wrapMode=GL_CLAMP_TO_EDGE)
                         for img in images] )
    # these images have Z backwards from opengl
    images = ["goldengateposx.jpg",
              "goldengatenegx.jpg",
              "goldengateposy.jpg",
              "goldengatenegy.jpg",
              "goldengatenegz.jpg",
              "goldengateposz.jpg"]
    theTextures.append( [loadTexture(img,
                                     magFilter=GL_LINEAR,
                                     wrapMode=GL_CLAMP_TO_EDGE)
                         for img in images] )
    # these images have X backwards from opengl
    images = ["lancellottiposx.jpg",
              "lancellottinegx.jpg",
              "lancellottiposy.jpg",
              "lancellottinegy.jpg",
              "lancellottinegz.jpg",
              "lancellottiposz.jpg"]
    theTextures.append( [loadTexture(img,
                                     magFilter=GL_LINEAR,
                                     wrapMode=GL_CLAMP_TO_EDGE)
                         for img in images] )
    

    # REFLECTING OBJECTS
    theMeshes = []
    verts,elements = torus(2.0, 0.75, 64, 16)
    theMeshes.append(
        reflectorMesh(theTextures[0][0],
                      theTextures[0][1],
                      theTextures[0][2],
                      theTextures[0][3],
                      theTextures[0][4],
                      theTextures[0][5],
                      getArrayBuffer(verts),
                      getElementBuffer(elements),
                      len(elements),
                      makeShader("reflector.vert",
                                 "reflector.frag")
                  )
    )
    verts,elements = sphere(2.0, 64, 32)
    theMeshes.append(
        reflectorMesh(theTextures[0][0],
                      theTextures[0][1],
                      theTextures[0][2],
                      theTextures[0][3],
                      theTextures[0][4],
                      theTextures[0][5],
                      getArrayBuffer(verts),
                      getElementBuffer(elements),
                      len(elements),
                      makeShader("reflector.vert",
                                 "reflector.frag")
                  )
    )
    verts,elements = tetrahedron(4.0)
    theMeshes.append(
        reflectorMesh(theTextures[0][0],
                      theTextures[0][1],
                      theTextures[0][2],
                      theTextures[0][3],
                      theTextures[0][4],
                      theTextures[0][5],
                      getArrayBuffer(verts),
                      getElementBuffer(elements),
                      len(elements),
                      makeShader("reflector.vert",
                                 "reflector.frag")
                  )
    )
    verts,elements = readOBJ("suzanne.obj")
    theMeshes.append(
        reflectorMesh(theTextures[0][0],
                      theTextures[0][1],
                      theTextures[0][2],
                      theTextures[0][3],
                      theTextures[0][4],
                      theTextures[0][5],
                      getArrayBuffer(verts),
                      getElementBuffer(elements),
                      len(elements),
                      makeShader("reflector.vert",
                                 "reflector.frag")
                  )
    )

    # SKYBOX
    boxsize = 100.0
    skyboxShader = makeShader("flattextured.vert","flattextured.frag")
    verts,elements = rectangle(boxsize, boxsize)
    vertBuff = getArrayBuffer(verts)
    elemBuff = getElementBuffer(elements)
    numElems = len(elements)
    posx = flatTexturedMesh(theTextures[0][0],
                            vertBuff,
                            elemBuff,
                            numElems,
                            skyboxShader,
                            N.array((1.0,1.0),dtype=N.float32))
    negx = flatTexturedMesh(theTextures[0][1],
                            vertBuff,
                            elemBuff,
                            numElems,
                            skyboxShader,
                            N.array((1.0,1.0),dtype=N.float32))
    posy = flatTexturedMesh(theTextures[0][2],
                            vertBuff,
                            elemBuff,
                            numElems,
                            skyboxShader,
                            N.array((1.0,1.0),dtype=N.float32))
    negy = flatTexturedMesh(theTextures[0][3],
                            vertBuff,
                            elemBuff,
                            numElems,
                            skyboxShader,
                            N.array((1.0,1.0),dtype=N.float32))
    posz =  flatTexturedMesh(theTextures[0][4],
                            vertBuff,
                            elemBuff,
                            numElems,
                             skyboxShader,
                             N.array((1.0,1.0),dtype=N.float32))
    negz =  flatTexturedMesh(theTextures[0][5],
                            vertBuff,
                            elemBuff,
                            numElems,
                             skyboxShader,
                             N.array((1.0,1.0),dtype=N.float32))

    backDistance = -boxsize*0.5

    posx.yaw(-1)
    posx.yaw(-1)
    posx.moveBack(backDistance)

    negx.yaw(1)
    negx.yaw(1)
    negx.moveBack(backDistance)

    for i in range(2):
        posy.pitch(-1)
    posy.moveBack(backDistance)

    for i in range(2):
        negy.pitch(1)
    negy.moveBack(backDistance)

    for i in range(4):
        posz.yaw(1)
    posz.moveBack(backDistance)

    negz.moveBack(backDistance)

    theBox = [posx, negx, posy, negy, posz, negz]

    # CAMERA
    width, height = theScreen.get_size()
    aspectRatio = float(width)/float(height)
    near = 0.01
    far = 1000.0
    lens = 2.0  # A wide lens will minimize pixels in the background
    theCamera = Camera(lens, near, far, aspectRatio)
    theCamera.moveBack(10)
Beispiel #9
0
def init():
    global theMesh, theTV, theLight, theCamera, \
           theScreen, theTVCamera, theFramebuffer
    initializeVAO()
    glEnable(GL_CULL_FACE)
    glEnable(GL_DEPTH_TEST)

    # FRAMEBUFFER
    # create a frame buffer and bind to it
    theFramebuffer = glGenFramebuffers(1)
    glBindFramebuffer(GL_FRAMEBUFFER, theFramebuffer)
    # create a texture to render into and bind to it
    theRenderedTexture = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, theRenderedTexture)
    # fill with empty pixels (the last "0")
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
                 512, 512, 0, GL_RGB,
                 GL_UNSIGNED_BYTE, c_void_p(0))
    # poor filtering, needed
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    # now create a depth buffer and bind to it
    theDepthBuffer = glGenRenderbuffers(1)
    glBindRenderbuffer(GL_RENDERBUFFER, theDepthBuffer)
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, 512, 512)
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
                              GL_RENDERBUFFER, theDepthBuffer)
    # finally, configure our framebuffer
    glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                         theRenderedTexture, 0)
    theDrawBuffers = [GL_COLOR_ATTACHMENT0]
    glDrawBuffers(1, theDrawBuffers)
    # check errors, necessary with pyopengl?
    if glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE:
        raise StandardError("Frame buffer status no good.")
    

    # Add our objects
    # LIGHT
    theLight = N.array((-0.577, 0.577, 0.577, 0.0),dtype=N.float32)
    # OBJECTS
    verts, elements = readOBJ("suzanne.obj")
    arrayBuffer = getArrayBuffer(verts)
    elementBuffer = getElementBuffer(elements)
    numElements = len(elements)
    phongShader = makeShader("phongshader.vert", "phongshader.frag")
    theMesh = coloredMesh(N.array((0,1,1,1),dtype=N.float32),
                          arrayBuffer,
                          elementBuffer,
                          numElements,
                          phongShader
                          )
    width, height = theScreen.get_size()
    aspectRatio = float(width)/float(height)
    verts, elements = rectangle(2*aspectRatio,2)
    arrayBuffer = getArrayBuffer(verts)
    elementBuffer = getElementBuffer(elements)
    numElements = len(elements)
    texturedShader = makeShader("flattextured.vert", "flattextured.frag")
    texture = loadTexture("grid.png")
    theTV = flatTexturedMesh(texture,
                             arrayBuffer,
                             elementBuffer,
                             numElements,
                             texturedShader,
                             fade=0.9)
    
    theTV.moveRight(2)
    theTV.yaw(-1)
    
    # CAMERA
    near = 0.01
    far = 100.0
    lens = 4.0  # "longer" lenses mean more telephoto
    theCamera = Camera(lens, near, far, aspectRatio)
    theCamera.moveBack(10)

    # TV CAMERA
    theTVCamera = Camera(lens, near, far, float(width)/float(height))
    theTVCamera.yaw(-0.5)
    theTVCamera.moveBack(10)
Beispiel #10
0
def init():
    global theMeshes, theLight, theCamera, theScreen
    initializeVAO()
    glEnable(GL_CULL_FACE)
    glEnable(GL_DEPTH_TEST)
    # Add our objects
    # LIGHT
    theLight = N.array((0.577, 0.577, 0.577, 0.0),dtype=N.float32)
    # OBJECTS
    theMeshes = []
    phongshader = makeShader("phongshader.vert","phongshader.frag")
    verts, elements = torus(1,0.25,64,16)
    torusVerts = getArrayBuffer(verts)
    torusElements = getElementBuffer(elements)
    torusNum = len(elements)
    verts, elements = sphere(1,64,32)
    sphereVerts = getArrayBuffer(verts)
    sphereElements = getArrayBuffer(elements)
    sphereNum = len(elements)
    verts, elements = tetrahedron(2)
    tetraVerts = getArrayBuffer(verts)
    tetraElements = getElementBuffer(elements)
    tetraNum = len(elements)
    verts, elements = readOBJ("suzanne.obj")
    suzanneVerts = getArrayBuffer(verts)
    suzanneElements = getElementBuffer(elements)
    suzanneNum = len(elements)
    for i in range(32):
        if i % 4 == 0:
            verts, elements, num = torusVerts, torusElements, torusNum
        elif i % 4 == 1:
            verts,elements, num = sphereVerts, sphereElements, torusNum
        elif i % 4 == 2:
            verts, elements, num = suzanneVerts, suzanneElements, torusNum
        else:
            verts, elements = tetraVerts, tetraElements
        newmesh = coloredMesh(N.array((N.random.random(),
                                       N.random.random(),
                                       N.random.random(),
                                       1.0), dtype=N.float32),
                              verts,
                              elements,
                              num,
                              phongshader)
        x = N.random.random()*20-10
        y = N.random.random()*20-10
        z = N.random.random()*20-10
        newmesh.moveRight(x)
        newmesh.moveUp(y)
        newmesh.moveBack(z)
        newmesh.pitch(x)
        newmesh.yaw(y)
        newmesh.roll(z)
        theMeshes.append(newmesh)
    # CAMERA
    width, height = theScreen.get_size()
    aspectRatio = float(width)/float(height)
    near = 0.01
    far = 100.0
    lens = 4.0  # "longer" lenses mean more telephoto
    theCamera = Camera(lens, near, far, aspectRatio)
Beispiel #11
0
def init():
    global theMeshes, theTV, theTV2, theLight, theCamera, \
           theScreen, theTVCamera, theFramebuffer, theFramebuffer2,\
           resolution
    initializeVAO()
    glEnable(GL_CULL_FACE)
    glEnable(GL_DEPTH_TEST)

    # FRAMEBUFFER
    # create a frame buffer and bind to it
    resolution = 512
    theFramebuffer = getFramebuffer(resolution)    
    theFramebuffer2 = getFramebuffer(resolution)    

    # Add our objects
    # LIGHT
    theLight = N.array((-0.577, 0.577, 0.577, 0.0),dtype=N.float32)
    # OBJECTS
    theMeshes = []
    phongshader = makeShader("phongshader.vert","phongshader.frag")
    verts, elements = torus(2.0,0.2,64,16)
    torusVerts = getArrayBuffer(verts)
    torusElements = getElementBuffer(elements)
    torusNum = len(elements)
    verts, elements = sphere(2.0,64,32)
    sphereVerts = getArrayBuffer(verts)
    sphereElements = getArrayBuffer(elements)
    sphereNum = len(elements)
    verts, elements = tetrahedron(4)
    tetraVerts = getArrayBuffer(verts)
    tetraElements = getElementBuffer(elements)
    tetraNum = len(elements)
    verts, elements = readOBJ("suzanne.obj")
    suzanneVerts = getArrayBuffer(verts)
    suzanneElements = getElementBuffer(elements)
    suzanneNum = len(elements)
    for i in range(16):
        if i % 4 == 0:
            verts, elements, num = torusVerts, torusElements, torusNum
        elif i % 4 == 1:
            verts,elements, num = sphereVerts, sphereElements, torusNum
        elif i % 4 == 2:
            verts, elements, num = suzanneVerts, suzanneElements, torusNum
        else:
            verts, elements = tetraVerts, tetraElements
        newmesh = coloredMesh(N.array((N.random.random(),
                                       N.random.random(),
                                       N.random.random(),
                                       1.0), dtype=N.float32),
                              verts,
                              elements,
                              num,
                              phongshader)
        x = N.random.random()*10-5
        y = N.random.random()*10-5
        z = N.random.random()*10-5
        newmesh.moveRight(x)
        newmesh.moveUp(y)
        newmesh.moveBack(z)
        newmesh.pitch(x)
        newmesh.yaw(y)
        newmesh.roll(z)
        theMeshes.append(newmesh)    

    # TVs
    width, height = theScreen.get_size()
    aspectRatio = float(width)/float(height)
    verts, elements = rectangle(20*aspectRatio,20)
    arrayBuffer = getArrayBuffer(verts)
    elementBuffer = getElementBuffer(elements)
    numElements = len(elements)
    texturedShader = makeShader("flattextured.vert", "flattextured.frag")
    texture = loadTexture("grid.png")
    theTV = flatTexturedMesh(texture,
                             arrayBuffer,
                             elementBuffer,
                             numElements,
                             texturedShader,
                             fade=0.9)
    
    theTV.moveRight(10)
    theTV.yaw(-1)
    theTV2 = flatTexturedMesh(texture,
                              arrayBuffer,
                              elementBuffer,
                              numElements,
                              texturedShader,
                              fade=0.9)
    
    theTV2.moveRight(-10)
    theTV2.yaw(1)
    
    # CAMERA
    near = 0.01
    far = 100.0
    lens = 4.0  # "longer" lenses mean more telephoto
    theCamera = Camera(lens, near, far, aspectRatio)
    theCamera.moveBack(50)

    # TV CAMERA
    theTVCamera = Camera(lens, near, far, float(width)/float(height))
    theTVCamera.yaw(-0.5)
    theTVCamera.moveBack(50)