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 = torus(10.0, 4.0, 128, 32) theMesh = proceduralMesh(N.array((1.0,0.5,0.25,1.0),dtype=N.float32), 100.0, getArrayBuffer(verts), getElementBuffer(elements), len(elements), makeShader("worley.vert", "worley.frag") ) # 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(50)
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") flatshader = makeShader("flattextured.vert","flattextured.frag") colorTexture = loadTexture("brickwork-texture.jpg") normalTexture = loadTexture("brickwork_normal-map.jpg") for i in range(100): if i % 3 == 0: major = N.random.random()*2 minor = major*0.25 verts = torus(major, minor, 64, 16) elif i % 3 == 1: radius = N.random.random()*2 verts = sphere(radius, 64, 32) else: size = N.random.random()*4 verts = tetrahedron(size) if i % 5 == 0: newmesh = flatTexturedMesh(colorTexture, getArrayBuffer(verts[0]), getElementBuffer(verts[1]), len(verts[1]), flatshader, N.array((0.5,0.5),dtype=N.float32)) else: newmesh = coloredMesh(N.array((N.random.random(), N.random.random(), N.random.random(), 1.0), dtype=N.float32), getArrayBuffer(verts[0]), getElementBuffer(verts[1]), len(verts[1]), 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)
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)
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
lightUnif = glGetUniformLocation(theShaders, "light") colorUnif = glGetUniformLocation(theShaders, "color") modelUnif = glGetUniformLocation(theShaders, "model") viewUnif = glGetUniformLocation(theShaders, "view") projUnif = glGetUniformLocation(theShaders, "projection") check("positionAttrib", positionAttrib) check("normalAttrib", normalAttrib) check("modelUnif", modelUnif) check("viewUnif", viewUnif) check("projUnif", projUnif) check("colorUnif", colorUnif) check("lightUnif", lightUnif) # Vertex Data, positions and normals and texture coords mytorus = torus(0.75, 0.4, 128, 32) torusVertices = mytorus[0] torusElements = mytorus[1] vertexComponents = 10 # 4 position, 4 normal, 2 texture # Ask the graphics card to create a buffer for our vertex data def getFloatBuffer(arr): buff = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, buff) glBufferData(GL_ARRAY_BUFFER, arr, GL_STATIC_DRAW) glBindBuffer(GL_ARRAY_BUFFER, 0) return buff def getElementBuffer(arr): buff = glGenBuffers(1) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buff)
check("positionAttrib", positionAttrib) check("normalAttrib", normalAttrib) check("tangentAttrib", tangentAttrib) check("bitangentAttrib", bitangentAttrib) check("uvAttrib", uvAttrib) check("modelUnif", modelUnif) check("viewUnif", viewUnif) check("projUnif", projUnif) check("lightUnif", lightUnif) check("scaleuvUnif", scaleuvUnif) check("colorUnif", colorUnif) # Vertex Data, positions and normals and texture coords mytorus = torus(0.5, 0.2, 32, 16) torusVertices = mytorus[0] torusElements = mytorus[1] vertexComponents = 18 # 4 position, 4 normal, 4 tangent, 4 bitangent, 2 texture # Ask the graphics card to create a buffer for our vertex data def getFloatBuffer(arr): buff = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, buff) glBufferData(GL_ARRAY_BUFFER, arr, GL_STATIC_DRAW) glBindBuffer(GL_ARRAY_BUFFER, 0) return buff def getElementBuffer(arr): buff = glGenBuffers(1) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buff)
projUnif = glGetUniformLocation(theShaders, "projection") colorSamplerUnif = glGetUniformLocation(theShaders, "colorsampler") normalSamplerUnif = glGetUniformLocation(theShaders, "normalsampler") colorUnif = glGetUniformLocation(theShaders, "color") check("positionAttrib", positionAttrib) check("normalAttrib", normalAttrib) check("modelUnif", modelUnif) check("viewUnif", viewUnif) check("projUnif", projUnif) check("lightUnif", lightUnif) check("colorUnif", colorUnif) # Vertex Data, positions and normals and texture coords mytorus = torus(0.5, 0.2, 64, 32) torusVertices = mytorus[0] torusElements = mytorus[1] vertexComponents = 18 # 4 position, 4 normal, 4 tangent, 4 bitangent, 2 texture # Ask the graphics card to create a buffer for our vertex data def getFloatBuffer(arr): buff = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, buff) glBufferData(GL_ARRAY_BUFFER, arr, GL_STATIC_DRAW) glBindBuffer(GL_ARRAY_BUFFER, 0) return buff def getElementBuffer(arr): buff = glGenBuffers(1) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buff)
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)
projUnif = glGetUniformLocation(theShaders, "projection") samplerUnif = glGetUniformLocation(theShaders, "sampler") check("positionAttrib", positionAttrib) check("normalAttrib", normalAttrib) check("uvAttrib", uvAttrib) check("modelUnif", modelUnif) check("viewUnif", viewUnif) check("projUnif", projUnif) check("lightUnif", lightUnif) check("samplerUnif", samplerUnif) # Vertex Data, positions and normals and texture coords mytorus = torus(0.5, 0.3, 64, 16) torusVertices = mytorus[0] torusElements = mytorus[1] vertexComponents = 18 # 4 position, 4 normal, 4 tangent, 4 bitangent, 2 texture print "Vertices:", len(torusVertices) / vertexComponents print "Triangles:", len(torusElements) / 3 # Ask the graphics card to create a buffer for our vertex data def getFloatBuffer(arr): buff = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, buff) glBufferData(GL_ARRAY_BUFFER, arr, GL_STATIC_DRAW) glBindBuffer(GL_ARRAY_BUFFER, 0) return buff
check("positionAttrib", positionAttrib) check("normalAttrib", normalAttrib) check("tangentAttrib", tangentAttrib) check("bitangentAttrib", bitangentAttrib) check("uvAttrib", uvAttrib) check("modelUnif", modelUnif) check("viewUnif", viewUnif) check("projUnif", projUnif) check("lightUnif", lightUnif) check("colorSamplerUnif", colorSamplerUnif) check("normalSamplerUnif", normalSamplerUnif) check("makeBumpUnif", makeBumpUnif) # Vertex Data, positions and normals and texture coords mytorus = torus(0.7, 0.3, 32,16) torusVertices = mytorus[0] torusElements = mytorus[1] vertexComponents = 18 # 4 position, 4 normal, 4 tangent, 4 bitangent, 2 texture # Ask the graphics card to create a buffer for our vertex data def getFloatBuffer(arr): buff = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, buff) glBufferData(GL_ARRAY_BUFFER, arr, GL_STATIC_DRAW) glBindBuffer(GL_ARRAY_BUFFER, 0) return buff def getElementBuffer(arr): buff = glGenBuffers(1) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buff)
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)