Guest User

opengl.py

a guest
Oct 14th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. import pyglet
  2. from pyglet.gl import *
  3. class CustomGroup(pyglet.graphics.Group):
  4.     def set_state(self):
  5.         glEnable(texture.target)
  6.         glBindTexture(texture.target, texture.id)
  7.     def unset_state(self):
  8.         glDisable(texture.target)
  9. window = pyglet.window.Window()
  10. custom_group = CustomGroup()
  11. batch = pyglet.graphics.Batch()
  12. vertex_list = batch.add(2, pyglet.gl.GL_LINES, custom_group,
  13.     ('v2i', (10, 15, 30, 35)),
  14.     ('c3B', (0, 0, 255, 0, 255, 0))
  15. )
  16. #To remove a vertex list from a batch, call VertexList.delete.
  17.  
  18. @window.event
  19. def on_draw():
  20.     batch.draw()
  21.     #The Batch ensures that the appropriate set_state and unset_state methods are called before and after the vertex lists that use them.
  22. @window.event
  23. def on_resize(width, height):
  24.     #default
  25.     glViewport(0, 0, width, height)
  26.     glMatrixMode(gl.GL_PROJECTION)
  27.     glLoadIdentity()
  28.     glOrtho(0, width, 0, height, -1, 1)
  29.     glMatrixMode(gl.GL_MODELVIEW)
  30. pyglet.app.run()
Advertisement
Add Comment
Please, Sign In to add comment