from pyglet.gl import * import Image window = pyglet.window.Window() glEnable(GL_DEPTH_TEST) glEnable(GL_TEXTURE_2D) heightmap = Image.open('andes-height.png') width, height = heightmap.size vlists = [] for row in range(height-1): vl = pyglet.graphics.vertex_list(width*2, ('v3f', [0]*3*width*2), ('t2f', [0]*2*width*2)) i = 0 j = 0 for col in range(width): vl.vertices[i] = (col/(width-1.0) - 0.5) * 100.0 vl.vertices[i+2] = (row/(height-1.0) - 0.5) * 100.0 vl.vertices[i+1] = heightmap.getpixel((col,row))/255.0 * 50.0 vl.vertices[i+3] = (col/(width-1.0) - 0.5) * 100.0 vl.vertices[i+5] = ((row+1)/(height-1.0) - 0.5) * 100.0 vl.vertices[i+4] = heightmap.getpixel((col,row+1))/255.0 * 50.0 i += 6 vl.tex_coords[j] = col/(width-1.0) vl.tex_coords[j+1] = row/(height-1.0) vl.tex_coords[j+2] = col/(width-1.0) vl.tex_coords[j+3] = (row+1)/(height-1.0) j += 4 vlists.append(vl) texture = pyglet.image.load('andes-left.png').get_texture() rotAngle = 0 @window.event def on_draw(): glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(60.0, float(window.width)/window.height, 1, 1000) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glTranslatef(0, -30, -100) glRotatef(-rotAngle, 0, 1, 0) glBindTexture(GL_TEXTURE_2D, texture.id) for v in vlists: v.draw(GL_TRIANGLE_STRIP) def update(dt): global rotAngle rotAngle += 90*dt pyglet.clock.schedule_interval(update,1/60.0) pyglet.app.run()