import sys, time, math, Image from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * import os startDir = os.getcwd() + os.sep startTime = time.time() def draw(): glClearColor(0.5, 0.7, 1, 0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glEnable(GL_TEXTURE_2D) drawFloor() glBindTexture(GL_TEXTURE_2D, texture1) glTranslatef(0, 7*abs(math.sin(time.time())), -5) glutSolidTeapot(2.0) texture1 = 0 texture2 = 0 angle = 0 def drawFloor(): glMatrixMode(GL_TEXTURE) glPushMatrix() glLoadIdentity() glRotatef(angle, 0, 0, 1) glMatrixMode(GL_MODELVIEW) glEnable(GL_TEXTURE_2D) glBindTexture(GL_TEXTURE_2D, texture2) glColor4f(1,1,1,1) glBegin(GL_QUADS) glTexCoord2f(-1,-1) glVertex3f(-10, 0, -10) glTexCoord2f(1,-1) glVertex3f(10, 0, -10) glTexCoord2f(1,1) glVertex3f(10, 0, 10) glTexCoord2f(-1,1) glVertex3f(-10, 0, 10) glEnd() glMatrixMode(GL_TEXTURE) glPopMatrix() glMatrixMode(GL_MODELVIEW) def initTexture(filename): img = Image.open(startDir + filename) img = img.transpose(Image.FLIP_TOP_BOTTOM) img = img.convert('RGB') textureID = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, textureID) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img.size[0], img.size[1], 0, GL_RGB, GL_UNSIGNED_BYTE, img.tostring()) glBindTexture(GL_TEXTURE_2D, 0) return textureID def update(): global angle, startTime angle = (time.time()-startTime)*10 texture1 = initTexture("clouds.jpg") texture2 = initTexture("panda.jpg")