import sys, time, math, os, random from pyglet.gl import * window = pyglet.window.Window() class TexMesh: def __init__(self, cols, rows, width, height, texturefile): if texturefile: self.texture = pyglet.image.load(texturefile).get_texture() else: self.texture = None self.vlists = [] for i in range(0,rows-1): verts = [] texcoords = [] for j in range(0,cols): x = (j/(cols-1.0))*width y = (i/(rows-1.0))*height s = j/(cols-1.0) t = i/(rows-1.0) verts += [x, y] texcoords += [s, t] t = (i+1)/(rows-1.0) y = ((i+1)/(rows-1.0))*height verts += [x, y] texcoords += [s, t] self.vlists.append(pyglet.graphics.vertex_list(cols*2, ('v2f', verts), ('t2f', texcoords))) def draw(self): # glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) if self.texture: glEnable(GL_TEXTURE_2D) glBindTexture(GL_TEXTURE_2D, self.texture.id) glColor4f(1,1,1,1) for v in self.vlists: v.draw(GL_TRIANGLE_STRIP) if self.texture: glDisable(GL_TEXTURE_2D) glBindTexture(GL_TEXTURE_2D, 0) objects = [ TexMesh(10, 10, 600.0, 400.0, 'flower1.png') ] @window.event def on_draw(): glClearColor(0, 0.3, 0.5, 0) glLineWidth(3) glClear(GL_COLOR_BUFFER_BIT) for o in objects: o.draw() @window.event def on_key_press(key, modifiers): pass def update(dummy): pass pyglet.clock.schedule_interval(update,1/60.0) pyglet.app.run()