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