Exemple #1
0
def makeObjects(minFilter, magFilter, width, height, depth, useAniso):
    global theShader
    verts, elements = rectangle(width, depth)
    vertBuff = getArrayBuffer(verts)
    elemBuff = getElementBuffer(elements)
    numElems = len(elements)
    floorColor = loadTexture("KirksEntry-ColorMap.png",
                             minFilter,magFilter,useAniso=useAniso)
    floor = flatTexturedMesh(floorColor,
                             vertBuff,
                             elemBuff,
                             numElems,
                             theShader,
                             N.array((width, depth),dtype=N.float32))
    floor.pitch(1)
    floor.pitch(1)
    floor.moveBack(-height*0.5)
    ceilingColor = loadTexture("BorntoShine-ColorMap.png",
                               minFilter,magFilter,useAniso=useAniso)
    ceiling = flatTexturedMesh(ceilingColor,
                               vertBuff,
                               elemBuff,
                               numElems,
                               theShader,
                               N.array((width, depth),dtype=N.float32))
    ceiling.pitch(-1)
    ceiling.pitch(-1)
    ceiling.moveBack(-height*0.5)
    verts, elements = rectangle(depth,width)
    vertBuff = getArrayBuffer(verts)
    elemBuff = getElementBuffer(elements)
    numElems = len(elements)
    wallColor = loadTexture("AlternatingBrick-ColorMap.png",
                            minFilter,magFilter,useAniso=useAniso)
    wallLeft = flatTexturedMesh(wallColor,
                                vertBuff,
                                elemBuff,
                                numElems,
                                theShader,
                                N.array((depth,height), dtype=N.float32))
    wallLeft.yaw(-1)
    wallLeft.yaw(-1)
    wallLeft.moveBack(-width*0.5)
    wallRight = flatTexturedMesh(wallColor,
                             vertBuff,
                             elemBuff,
                             numElems,
                                 theShader,
                                 N.array((depth,height), dtype=N.float32))
    wallRight.yaw(1)
    wallRight.yaw(1)
    wallRight.moveBack(-width*0.5)

    return [ceiling, floor, wallLeft, wallRight]
Exemple #2
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)
Exemple #3
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)
Exemple #4
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)
Exemple #5
0
def init():
    global theMesh, theBox, theLight, theCamera, theScreen, theTextures
    initializeVAO()
    glEnable(GL_CULL_FACE)
    glEnable(GL_DEPTH_TEST)
    # Add our objects
    # OBJECT
    verts,elements = torus(1.0, 0.25, 64, 16)
    theMesh = coloredMesh(N.array((0,1,1,1),dtype=N.float32),
                          getArrayBuffer(verts),
                          getElementBuffer(elements),
                          len(elements),
                          makeShader("phongshader.vert", "phongshader.frag")
                          )
    # 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 = 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)
Exemple #6
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)
Exemple #7
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)
Exemple #8
0
def init():
    global theMeshes, theLight, theCamera, theScreen, skyColor
    initializeVAO()
    glEnable(GL_DEPTH_TEST)

    # Add our objects

    # LIGHT
    theLight = N.array((0.577, 0.577, 0.577, 0.0),dtype=N.float32)

    # OBJECTS
    islandHeight = 5.0
    surroundingLandHeight = 1.0
    moatDepth = -10.0
    islandRadius = 50.0
    moatInnerRadius = 65.0
    moatOuterRadius = 90.0
    outerShoreRadius = 100.0
    terrainXZMax = 400.0
    terrainNumSamples = 400

    tRadius = 6.0
    tThickness = 1.0
    height = 15.0
    crenHeight = 2.0

    wThickness = 1.0

    castleRadius = islandRadius - tRadius + 1
    
    pi = N.pi
    qtrpi = N.pi/4

    skyColor = (0.0, 0.47, 0.67, 0.0)
    
    towerList = [
        #radius, height, numArcs, crenWidth, crenHeight, moveBackUnits, moveRightUnits
        (tRadius, height, 128, tThickness, 8, crenHeight,
         castleRadius*(-N.sin(pi*19/12)), castleRadius*(N.cos(pi*19/12))),

        (tRadius, height, 128, tThickness, 8, crenHeight,
         castleRadius*(-N.sin(pi*17/12)), castleRadius*(N.cos(pi*17/12))),

        (tRadius, height, 128, tThickness, 8, crenHeight,
         castleRadius*(-N.sin(pi*7/6)), castleRadius*(N.cos(pi*7/6))),

        (tRadius, height, 128, tThickness, 8, crenHeight,
         castleRadius*(-N.sin(pi*5/6)), castleRadius*(N.cos(pi*5/6))),

        (tRadius, height, 128, tThickness, 8, crenHeight,
         castleRadius*(-N.sin(pi*2/3)), castleRadius*(N.cos(pi*2/3))),

        (tRadius, height, 128, tThickness, 8, crenHeight,
         castleRadius*(-N.sin(pi/3)), castleRadius*(N.cos(pi/3))),

        (tRadius, height, 128, tThickness, 8, crenHeight,
         castleRadius*(-N.sin(pi/6)), castleRadius*(N.cos(pi/6))),

        (tRadius, height, 128, tThickness, 8, crenHeight,
         castleRadius*(-N.sin(pi*11/6)), castleRadius*(N.cos(pi*11/6))),

        (12.0, 35.0, 256, tThickness*2, 16, crenHeight*2, 0.0, 0.0)
        ]

    wallList = [
        #wallWidth, wallHeight, wallThickness,
        #numCren, crenHeight, moveBackUnits, moveRightUnits, yawUnits
        (castleRadius*(N.cos(pi*19/12)-N.cos(pi*17/12))-tRadius*2,
         height, wThickness, 3, crenHeight,
         (-N.sin(pi*17/12)), 0.0, 0.0),
        
        (castleRadius*(2*N.sin((pi*17/12-pi*7/6)/2))-tRadius*2,
         height, wThickness, 4, crenHeight,
         ((-N.sin(pi*17/12)-N.sin(pi*7/6))/2),
         ((N.cos(pi*17/12)+N.cos(pi*7/6))/2),
         ((pi*3/2) - ((pi*17/12)-(((pi*17/12)-(pi*7/6))/2)))/-qtrpi),

        (castleRadius*(2*N.sin((pi*7/6-pi*5/6)/2))-tRadius*2,
         height, wThickness, 5, crenHeight,
         ((-N.sin(pi*7/6)-N.sin(pi*5/6))/2),
         ((N.cos(pi*7/6)+N.cos(pi*5/6))/2),
         ((pi*3/2) - ((pi*7/6)-(((pi*7/6)-(pi*5/6))/2)))/-qtrpi),

        (castleRadius*(2*N.sin((pi*5/6-pi*2/3)/2))-tRadius*2,
         height, wThickness, 3, crenHeight,
         ((-N.sin(pi*5/6)-N.sin(pi*2/3))/2),
         ((N.cos(pi*5/6)+N.cos(pi*2/3))/2),
         ((pi*3/2) - ((pi*5/6)-(((pi*5/6)-(pi*2/3))/2)))/-qtrpi),

        (castleRadius*(2*N.sin((pi*2/3-pi/3)/2))-tRadius*2,
         height, wThickness, 5, crenHeight,
         ((-N.sin(pi*2/3)-N.sin(pi/3))/2),
         ((N.cos(pi*2/3)+N.cos(pi/3))/2),
         ((pi*3/2) - ((pi*2/3)-(((pi*2/3)-(pi/3))/2)))/-qtrpi),

        (castleRadius*(2*N.sin((pi/3-pi/6)/2))-tRadius*2,
         height, wThickness, 3, crenHeight,
         ((-N.sin(pi/3)-N.sin(pi/6))/2),
         ((N.cos(pi/3)+N.cos(pi/6))/2),
         ((pi*3/2) - ((pi/3)-(((pi/3)-(pi/6))/2)))/-qtrpi),

        (castleRadius*(1.0)-tRadius*2,
         height, wThickness, 5, crenHeight,
         ((-N.sin(pi/6)-N.sin(pi*11/6))/2),
         ((N.cos(pi/6)+N.cos(pi*11/6))/2),
         -6.0),

        (castleRadius*(2*N.sin((pi*11/6-pi*19/12)/2))-tRadius*2,
         height, wThickness, 4, crenHeight,
         ((-N.sin(pi*11/6)-N.sin(pi*19/12))/2),
         ((N.cos(pi*11/6)+N.cos(pi*19/12))/2),
         -6.0 - (2.0-((pi*3/2) - ((pi*11/6)-(((pi*11/6)-(pi*19/12))/2)))/-qtrpi))
        ]
    
    theMeshes = []

    #towers
    for tower in towerList:
        (towerRadius, towerHeight, nArcs,
         towerThickness, crenWidth, crenHeight,
         moveBackUnits, moveRightUnits) = tower

        #create tower
        verts,elements = cylinder(towerRadius,
                                  towerHeight,
                                  nArcs)
        theMeshes.append(proceduralMesh(N.array((0.373,0.361,0.314,1.0),dtype=N.float32),
                                        N.array((0.475,0.475,0.475,1.0),dtype=N.float32),
                                        100.0,
                                        getArrayBuffer(verts),
                                        getElementBuffer(elements),
                                        len(elements),
                                        makeShader("worley.vert", "worley.frag")
                                        ))
        theMeshes[-1].moveBack(moveBackUnits)
        theMeshes[-1].moveRight(moveRightUnits)
        theMeshes[-1].moveUp(islandHeight)
        
        verts,elements = reflectedSurface(verts,
                                          elements)
        theMeshes.append(proceduralMesh(N.array((0.373,0.361,0.314,1.0),dtype=N.float32),
                                        N.array((0.475,0.475,0.475,1.0),dtype=N.float32),
                                        100.0,
                                        getArrayBuffer(verts),
                                        getElementBuffer(elements),
                                        len(elements),
                                        makeShader("worley.vert", "worleyinverted.frag")
                                        ))
        theMeshes[-1].moveBack(moveBackUnits)
        theMeshes[-1].moveRight(moveRightUnits)
        theMeshes[-1].moveUp(-islandHeight)

        #create inside wall of tower
        verts,elements = cylinder(-towerRadius+towerThickness,
                                  towerHeight,
                                  nArcs)
        theMeshes.append(proceduralMesh(N.array((0.373,0.361,0.314,1.0),dtype=N.float32),
                                        N.array((0.475,0.475,0.475,1.0),dtype=N.float32),
                                        100.0,
                                        getArrayBuffer(verts),
                                        getElementBuffer(elements),
                                        len(elements),
                                        makeShader("worley.vert", "worley.frag")
                                        ))
        theMeshes[-1].moveBack(moveBackUnits)
        theMeshes[-1].moveRight(moveRightUnits)
        theMeshes[-1].moveUp(islandHeight)
        
        verts,elements = reflectedSurface(verts,
                                          elements)
        theMeshes.append(proceduralMesh(N.array((0.373,0.361,0.314,1.0),dtype=N.float32),
                                        N.array((0.475,0.475,0.475,1.0),dtype=N.float32),
                                        100.0,
                                        getArrayBuffer(verts),
                                        getElementBuffer(elements),
                                        len(elements),
                                        makeShader("worley.vert", "worleyinverted.frag")
                                        ))
        theMeshes[-1].moveBack(moveBackUnits)
        theMeshes[-1].moveRight(moveRightUnits)
        theMeshes[-1].moveUp(-islandHeight)

        #create top for tower
        verts,elements = cylinderTop(towerRadius, towerThickness, nArcs)
        theMeshes.append(proceduralMesh(N.array((0.373,0.361,0.314,1.0),dtype=N.float32),
                                        N.array((0.475,0.475,0.475,1.0),dtype=N.float32),
                                        100.0,
                                        getArrayBuffer(verts),
                                        getElementBuffer(elements),
                                        len(elements),
                                        makeShader("worley.vert", "worley.frag")
                                        ))
        theMeshes[-1].moveBack(moveBackUnits)
        theMeshes[-1].moveRight(moveRightUnits)
        theMeshes[-1].moveUp(towerHeight)
        theMeshes[-1].moveUp(islandHeight)

        verts,elements = reflectedSurface(verts, elements)
        theMeshes.append(proceduralMesh(N.array((0.373,0.361,0.314,1.0),dtype=N.float32),
                                        N.array((0.475,0.475,0.475,1.0),dtype=N.float32),
                                        100.0,
                                        getArrayBuffer(verts),
                                        getElementBuffer(elements),
                                        len(elements),
                                        makeShader("worley.vert", "worleyinverted.frag")
                                        ))
        theMeshes[-1].moveBack(moveBackUnits)
        theMeshes[-1].moveRight(moveRightUnits)
        theMeshes[-1].moveUp(-towerHeight)
        theMeshes[-1].moveUp(-islandHeight)
        
        #add crenellations to tower
        vertsList, elementsList = cylinderCrenellations(towerRadius,
                                                        towerHeight,
                                                        nArcs,
                                                        crenWidth,
                                                        crenHeight)
        for verts,elements in zip(vertsList,elementsList):
            theMeshes.append(proceduralMesh(N.array((0.373,0.361,0.314,1.0),dtype=N.float32),
                                            N.array((0.475,0.475,0.475,1.0),dtype=N.float32),
                                            100.0,
                                            getArrayBuffer(verts),
                                            getElementBuffer(elements),
                                            len(elements),
                                            makeShader("worley.vert", "worley.frag")
                                            ))
            theMeshes[-1].moveBack(moveBackUnits)
            theMeshes[-1].moveRight(moveRightUnits)
            theMeshes[-1].moveUp(islandHeight)
            theMeshes[-1].moveUp(towerHeight-0.01)
            
            verts,elements = reflectedSurface(verts, elements)
            theMeshes.append(proceduralMesh(N.array((0.373,0.361,0.314,1.0),dtype=N.float32),
                                            N.array((0.475,0.475,0.475,1.0),dtype=N.float32),
                                            100.0,
                                            getArrayBuffer(verts),
                                            getElementBuffer(elements),
                                            len(elements),
                                            makeShader("worley.vert", "worleyinverted.frag")
                                            ))
            theMeshes[-1].moveBack(moveBackUnits)
            theMeshes[-1].moveRight(moveRightUnits)
            theMeshes[-1].moveUp(-islandHeight)
            theMeshes[-1].moveUp(-towerHeight+0.01)

    #walls
    for wall in wallList:
        (wallWidth, wallHeight, wallThickness, numCren, crenHeight,
         moveBackUnits, moveRightUnits, yawUnits) = wall

        #create outside wall
        verts,elements = rectangle(wallWidth, wallHeight)
        theMeshes.append(proceduralMesh(N.array((0.373,0.361,0.314,1.0),dtype=N.float32),
                                        N.array((0.475,0.475,0.475,1.0),dtype=N.float32),
                                        100.0,
                                        getArrayBuffer(verts),
                                        getElementBuffer(elements),
                                        len(elements),
                                        makeShader("worley.vert", "worley.frag")
                                        ))
        theMeshes[-1].moveBack((moveBackUnits) * (castleRadius+(wallThickness/2)))
        theMeshes[-1].moveRight((moveRightUnits) * (castleRadius+(wallThickness/2)))
        theMeshes[-1].moveUp(wallHeight/2)
        theMeshes[-1].moveUp(islandHeight)
        yawCopy = yawUnits
        while (yawCopy < -1.0):
            theMeshes[-1].yaw(-1.0)
            yawCopy += 1.0
        theMeshes[-1].yaw(yawCopy)
        
        verts,elements = reflectedSurface(verts, elements)
        theMeshes.append(proceduralMesh(N.array((0.373,0.361,0.314,1.0),dtype=N.float32),
                                        N.array((0.475,0.475,0.475,1.0),dtype=N.float32),
                                        100.0,
                                        getArrayBuffer(verts),
                                        getElementBuffer(elements),
                                        len(elements),
                                        makeShader("worley.vert", "worleyinverted.frag")
                                        ))
        theMeshes[-1].moveBack((moveBackUnits) * (castleRadius+(wallThickness/2)))
        theMeshes[-1].moveRight((moveRightUnits) * (castleRadius+(wallThickness/2)))
        theMeshes[-1].moveUp(-wallHeight/2)
        theMeshes[-1].moveUp(-islandHeight)
        yawCopy = yawUnits
        while (yawCopy < -1.0):
            theMeshes[-1].yaw(-1.0)
            yawCopy += 1.0
        theMeshes[-1].yaw(yawCopy)

        #add crenellations to wall
        verts,elements,xcenters = rectangleCrenellation(wallWidth, numCren, crenHeight)
        rverts,relements = reflectedSurface(verts, elements)
        for i in range(numCren):
            theMeshes.append(proceduralMesh(N.array((0.373,0.361,0.314,1.0),dtype=N.float32),
                                        N.array((0.475,0.475,0.475,1.0),dtype=N.float32),
                                        100.0,
                                        getArrayBuffer(verts),
                                        getElementBuffer(elements),
                                        len(elements),
                                        makeShader("worley.vert", "worley.frag")
                                        ))
            theMeshes[-1].moveBack((moveBackUnits) * (castleRadius+(wallThickness/2)))
            theMeshes[-1].moveRight((moveRightUnits) * (castleRadius+(wallThickness/2)))
            theMeshes[-1].moveUp(crenHeight/2 + wallHeight)
            theMeshes[-1].moveUp(islandHeight)
            yawCopy = yawUnits
            while (yawCopy < -1.0):
                theMeshes[-1].yaw(-1.0)
                yawCopy += 1.0
            theMeshes[-1].yaw(yawCopy)
            theMeshes[-1].moveRight(xcenters[i] - wallWidth/2)
        
            theMeshes.append(proceduralMesh(N.array((0.373,0.361,0.314,1.0),dtype=N.float32),
                                        N.array((0.475,0.475,0.475,1.0),dtype=N.float32),
                                        100.0,
                                        getArrayBuffer(rverts),
                                        getElementBuffer(relements),
                                        len(relements),
                                        makeShader("worley.vert", "worleyinverted.frag")
                                        ))
            theMeshes[-1].moveBack((moveBackUnits) * (castleRadius+(wallThickness/2)))
            theMeshes[-1].moveRight((moveRightUnits) * (castleRadius+(wallThickness/2)))
            theMeshes[-1].moveUp(-crenHeight/2 - wallHeight)
            theMeshes[-1].moveUp(-islandHeight)
            yawCopy = yawUnits
            while (yawCopy < -1.0):
                theMeshes[-1].yaw(-1.0)
                yawCopy += 1.0
            theMeshes[-1].yaw(yawCopy)
            theMeshes[-1].moveRight(xcenters[i] - wallWidth/2)

        #create top of wall
        yout = N.square(((moveBackUnits) * (castleRadius+(wallThickness/2))))
        xout = N.square(((moveRightUnits) * (castleRadius+(wallThickness/2))))
        rout = N.sqrt(yout + xout)
        yin  = N.square(((moveBackUnits) * (castleRadius-(wallThickness/2))))
        xin  = N.square(((moveRightUnits) * (castleRadius-(wallThickness/2))))
        rin  = N.sqrt(yin + xin)
        wallTopThickness = rout - rin
        verts,elements = rectangle(wallWidth, wallTopThickness)
        theMeshes.append(proceduralMesh(N.array((0.373,0.361,0.314,1.0),dtype=N.float32),
                                        N.array((0.475,0.475,0.475,1.0),dtype=N.float32),
                                        100.0,
                                        getArrayBuffer(verts),
                                        getElementBuffer(elements),
                                        len(elements),
                                        makeShader("worley.vert", "worley.frag")
                                        ))
        theMeshes[-1].moveBack(moveBackUnits*castleRadius)
        theMeshes[-1].moveRight(moveRightUnits*castleRadius)
        theMeshes[-1].moveUp(wallHeight)
        theMeshes[-1].moveUp(islandHeight)
        yawCopy = yawUnits
        while (yawCopy < -1.0):
            theMeshes[-1].yaw(-1.0)
            yawCopy += 1.0
        theMeshes[-1].yaw(yawCopy)
        for i in range(2):
            theMeshes[-1].pitch(1.0)
        
        verts,elements = reflectedSurface(verts, elements)
        theMeshes.append(proceduralMesh(N.array((0.373,0.361,0.314,1.0),dtype=N.float32),
                                        N.array((0.475,0.475,0.475,1.0),dtype=N.float32),
                                        100.0,
                                        getArrayBuffer(verts),
                                        getElementBuffer(elements),
                                        len(elements),
                                        makeShader("worley.vert", "worleyinverted.frag")
                                        ))
        theMeshes[-1].moveBack(moveBackUnits*castleRadius)
        theMeshes[-1].moveRight(moveRightUnits*castleRadius)
        theMeshes[-1].moveUp(-wallHeight)
        theMeshes[-1].moveUp(-islandHeight)
        yawCopy = yawUnits
        while (yawCopy < -1.0):
            theMeshes[-1].yaw(-1.0)
            yawCopy += 1.0
        theMeshes[-1].yaw(yawCopy)
        for i in range(2):
            theMeshes[-1].pitch(1.0)
        
        #create inside wall
        verts,elements = rectangle(wallWidth, wallHeight)
        theMeshes.append(proceduralMesh(N.array((0.373,0.361,0.314,1.0),dtype=N.float32),
                                        N.array((0.475,0.475,0.475,1.0),dtype=N.float32),
                                        100.0,
                                        getArrayBuffer(verts),
                                        getElementBuffer(elements),
                                        len(elements),
                                        makeShader("worley.vert", "worley.frag")
                                        ))
        theMeshes[-1].moveBack((moveBackUnits) * (castleRadius-(wallThickness/2)))
        theMeshes[-1].moveRight((moveRightUnits) * (castleRadius-(wallThickness/2)))
        theMeshes[-1].moveUp(wallHeight/2)
        theMeshes[-1].moveUp(islandHeight)
        yawCopy = yawUnits
        while (yawCopy < -1.0):
            theMeshes[-1].yaw(-1.0)
            yawCopy += 1.0
        theMeshes[-1].yaw(yawCopy)
        for i in range(4):
            theMeshes[-1].yaw(-1.0)
        
        verts,elements = reflectedSurface(verts, elements)
        theMeshes.append(proceduralMesh(N.array((0.373,0.361,0.314,1.0),dtype=N.float32),
                                        N.array((0.475,0.475,0.475,1.0),dtype=N.float32),
                                        100.0,
                                        getArrayBuffer(verts),
                                        getElementBuffer(elements),
                                        len(elements),
                                        makeShader("worley.vert", "worleyinverted.frag")
                                        ))
        theMeshes[-1].moveBack((moveBackUnits) * (castleRadius-(wallThickness/2)))
        theMeshes[-1].moveRight((moveRightUnits) * (castleRadius-(wallThickness/2)))
        theMeshes[-1].moveUp(-wallHeight/2)
        theMeshes[-1].moveUp(-islandHeight)
        yawCopy = yawUnits
        while (yawCopy < -1.0):
            theMeshes[-1].yaw(-1.0)
            yawCopy += 1.0
        theMeshes[-1].yaw(yawCopy)
        for i in range(4):
            theMeshes[-1].yaw(-1.0)
       
    #add terrain
    verts,elements = islandAndMoat(islandHeight, surroundingLandHeight,
                                   moatDepth, islandRadius,
                                   moatInnerRadius, moatOuterRadius, outerShoreRadius,
                                   terrainXZMax, terrainNumSamples,
                                   noiseY = True, noiseVariance = 2.0, noiseScale = 0.2)
    theMeshes.append(flatTexturedMesh(loadTexture("grass.jpg", magFilter=GL_LINEAR),
                                      getArrayBuffer(verts),
                                      getElementBuffer(elements),
                                      len(elements),
                                      makeShader("flattextured.vert", "flattextured.frag"),
                                      scaleuv = N.array((32.0,32.0),dtype=N.float32),
                                      useFog = True,
                                      fogColor = N.array(skyColor,dtype=N.float32),
                                      fogStart = 300.0,
                                      fogEnd = 325.0
                                      ))
    verts,elements = reflectedSurface(verts, elements)
    theMeshes.append(flatTexturedMesh(loadTexture("grass.jpg", magFilter=GL_LINEAR),
                                      getArrayBuffer(verts),
                                      getElementBuffer(elements),
                                      len(elements),
                                      makeShader("flattextured.vert", "flattexturedinverted.frag"),
                                      scaleuv = N.array((32.0,32.0),dtype=N.float32),
                                      useFog = True,
                                      fogColor = N.array(skyColor,dtype=N.float32),
                                      fogStart = 300.0,
                                      fogEnd = 325.0
                                      ))
    
    # CAMERA
    width, height = theScreen.get_size()
    aspectRatio = float(width)/float(height)
    near = 0.01
    far = 325.0
    lens = 4.0  # "longer" lenses mean more telephoto
    theCamera = Camera(lens, near, far, aspectRatio)
    
    theCamera.moveBack(180.0)
    theCamera.moveUp(40.0)
    theCamera.moveRight(-40.0)
    theCamera.yaw(-.25)
    theCamera.pitch(.20)
Exemple #9
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)