import pyglet from pyglet.gl import * class CustomGroup(pyglet.graphics.Group): def set_state(self): glEnable(texture.target) glBindTexture(texture.target, texture.id) def unset_state(self): glDisable(texture.target) window = pyglet.window.Window() custom_group = CustomGroup() batch = pyglet.graphics.Batch() vertex_list = batch.add(2, pyglet.gl.GL_LINES, custom_group, ('v2i', (10, 15, 30, 35)), ('c3B', (0, 0, 255, 0, 255, 0)) ) #To remove a vertex list from a batch, call VertexList.delete. @window.event def on_draw(): batch.draw() #The Batch ensures that the appropriate set_state and unset_state methods are called before and after the vertex lists that use them. @window.event def on_resize(width, height): #default glViewport(0, 0, width, height) glMatrixMode(gl.GL_PROJECTION) glLoadIdentity() glOrtho(0, width, 0, height, -1, 1) glMatrixMode(gl.GL_MODELVIEW) pyglet.app.run()