Advertisement
thenewboston

[source code] Pygame (Python Game Development) Tutorial 97

Nov 15th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. import pygame
  2. from pygame.locals import *
  3.  
  4. from OpenGL.GL import *
  5. from OpenGL.GLU import *
  6.  
  7. verticies = (
  8.     (1, -1, -1),
  9.     (1, 1, -1),
  10.     (-1, 1, -1),
  11.     (-1, -1, -1),
  12.     (1, -1, 1),
  13.     (1, 1, 1),
  14.     (-1, -1, 1),
  15.     (-1, 1, 1),
  16.     )
  17.  
  18. edges = (
  19.     (0,1),
  20.     (0,3),
  21.     (0,4),
  22.     (2,1),
  23.     (2,3),
  24.     (2,7),
  25.     (6,3),
  26.     (6,4),
  27.     (6,7),
  28.     (5,1),
  29.     (5,4),
  30.     (5,7),
  31.     )
  32.  
  33.  
  34.  
  35. def Draw_Cube():
  36.     glBegin(GL_LINES)
  37.     for edge in edges:
  38.         for vertex in edge:
  39.             glVertex3fv(verticies[vertex])
  40.     glEnd()
  41.  
  42.  
  43. def main():
  44.     pygame.init()
  45.     display = (800,600)
  46.  
  47.     pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
  48.  
  49.    
  50.     #
  51.     gluPerspective(45.0, (display[0]/display[1]), 0.1, 50)
  52.  
  53.     # moving back.
  54.     glTranslatef(0.0,0.0,-5.0)
  55.  
  56.     # where we might be
  57.     glRotatef(40, 20, 20, 0)
  58.  
  59.     while True:
  60.  
  61.         for event in pygame.event.get():
  62.             if event.type == pygame.QUIT:
  63.                 pygame.quit()
  64.                 quit()
  65.  
  66.             if event.type == pygame.MOUSEBUTTONDOWN:
  67.                 print(event)
  68.                 print(event.button)
  69.  
  70.  
  71.         glRotatef(1, 3, 1, 1)
  72.         glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
  73.         Draw_Cube()
  74.         pygame.display.flip()
  75.         pygame.time.wait(10)
  76.  
  77. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement