Advertisement
thenewboston

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

Nov 15th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 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. surfaces = (
  34.     (0,1,2,3),
  35.     (3,2,7,6),
  36.     (6,7,5,4),
  37.     (4,5,1,0),
  38.     (1,5,7,2),
  39.     (4,0,3,6)    
  40.     )
  41.  
  42.  
  43.  
  44.  
  45. def Draw_Cube():
  46.  
  47.     glBegin(GL_QUADS)
  48.     for surface in surfaces:
  49.         for vertex in surface:
  50.             glColor3fv((0,1,1))
  51.             glVertex3fv(verticies[vertex])
  52.    
  53.     glEnd()
  54.  
  55.  
  56.    
  57.     glBegin(GL_LINES)
  58.     for edge in edges:
  59.         for vertex in edge:
  60.             glColor3fv((0,0,0))
  61.             glVertex3fv(verticies[vertex])
  62.     glEnd()
  63.  
  64.  
  65. def main():
  66.     pygame.init()
  67.     display = (800,600)
  68.  
  69.     pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
  70.  
  71.    
  72.     #
  73.     gluPerspective(90.0, (display[0]/display[1]), 0.1, 50)
  74.  
  75.     # moving back.
  76.     glTranslatef(0.0,0.0,-5.0)
  77.  
  78.     # where we might be
  79.     glRotatef(20, 2, 0, 0)
  80.  
  81.     while True:
  82.  
  83.         for event in pygame.event.get():
  84.             if event.type == pygame.QUIT:
  85.                 pygame.quit()
  86.                 quit()
  87.  
  88.             if event.type == pygame.MOUSEBUTTONDOWN:
  89.                 print(event)
  90.                 print(event.button)
  91.  
  92.                 if event.button == 4:
  93.                     glTranslatef(0.0,0.0,1.0)
  94.                 elif event.button == 5:
  95.                     glTranslatef(0.0,0.0,-1.0)
  96.  
  97.                    
  98.  
  99.  
  100.         glRotatef(1, 3, 1, 1)
  101.         glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
  102.         Draw_Cube()
  103.         pygame.display.flip()
  104.         pygame.time.wait(10)
  105.  
  106. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement