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
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 mysphere = sphere(0.75, 32,16) sphereVertices = mysphere[0] sphereElements = mysphere[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)
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 mysphere = sphere(0.75, 128,64) sphereVertices = mysphere[0] sphereElements = mysphere[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)
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 mysphere = sphere(0.75, 64, 32) sphereVertices = mysphere[0] sphereElements = mysphere[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)