Beispiel #1
0
	def __init__(self):
		self.sun = Sun()
		self.moon = Moon()


		vertices, vnormals, f, self.vertexCount = \
				graphics.loadObj("data/model/skydome.obj")

		xMax = xMin = vertices[0][0]
		zMax = zMin = vertices[0][2]
		for i in vertices:
			if i[0] < xMin: xMin = i[0]
			elif i[0] > xMax: xMax = i[0]

			if i[2] < zMin: zMin = i[2]
			elif i[2] > zMax: zMax = i[2]

		sizeX = xMax - xMin
		sizeY = zMax - zMin

		texCoords = Numeric.zeros((self.vertexCount, 2), 'f')
		nightTexCoords = Numeric.zeros((self.vertexCount, 2), 'f')

		self.textureId, textureWidthRatio, textureHeightRatio = \
				graphics.loadTexture("data/image/cl.jpg")

		nIndex = 0
		for i in vertices:
			texCoords[nIndex, 0] = (i[0]-xMin) / sizeX * textureWidthRatio
			texCoords[nIndex, 1] = (i[2]-zMin) / sizeY * textureHeightRatio
			nIndex += 1

		self.nightTextureId, textureWidthRatio, textureHeightRatio = \
				graphics.loadTexture("data/image/nightsky.jpg")
		nIndex = 0
		for i in vertices:
			nightTexCoords[nIndex, 0] = (i[0]-xMin) / sizeX * textureWidthRatio
			nightTexCoords[nIndex, 1] = (i[2]-zMin) / sizeY * textureHeightRatio
			nIndex += 1

		self.nightTexCoordsId = glGenBuffersARB(1)
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.nightTexCoordsId)
		glBufferDataARB(GL_ARRAY_BUFFER_ARB, nightTexCoords, GL_STATIC_DRAW_ARB)

		self.verticesId, self.normalsId, self.texCoordsId = \
				graphics.createVBO("skydome", vertices, vnormals, texCoords)

		self.vertices = vertices
		self.normals = vnormals
Beispiel #2
0
	def setBackground(self, path):
		self.backgroundTextureId, textureWidthRatio, textureHeightRatio = \
				graphics.loadTexture(path)

		if self.verticesId == None:
			vertices = Numeric.zeros((4, 3), 'f')
			vertices[1, 0] = 640
			vertices[2, 0] = 640
			vertices[2, 1] = 480
			vertices[3, 1] = 480
			self.verticesId = glGenBuffersARB(1)

			glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.verticesId)
			glBufferDataARB(GL_ARRAY_BUFFER_ARB, vertices, GL_STATIC_DRAW_ARB)

		if self.texCoordsId == None:
			texCoords = Numeric.zeros((4, 2), 'f')
			texCoords[1, 0] = 1.0*textureWidthRatio
			texCoords[2, 0] = 1.0*textureWidthRatio
			texCoords[2, 1] = 1.0*textureHeightRatio
			texCoords[3, 1] = 1.0*textureHeightRatio

			self.texCoordsId = glGenBuffersARB(1)
			glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.texCoordsId)
			glBufferDataARB(GL_ARRAY_BUFFER_ARB, texCoords, GL_STATIC_DRAW_ARB)

		glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0)

		self.hasBackground = True