Commits

pygame  committed 2512dea

added glcube example

  • Participants
  • Parent commits 308bd10

Comments (0)

Files changed (6)

-Pygame Version 1.0
+Pygame Version 1.0.1
 April 4th, 2001
 
 Python Game Development
 # BUG   = fixed a bug that was crashing
 
 Apr 18, 2001
-	added opengl support
+	added opengl support (with example)
 	fixed display.get_init()
 	current music is free'd when mixer is quit
 	better thread sharing in various video calls
+	fixed GCC compiler error in constants.c
 
 Apr 10, 2001
 	mixer now uses the requested sample format/size

File examples/Readme.txt

 	BlitzBasic gaming language. Nonetheless, it demonstrates a quick
 	8-bit setup (with colormap).
 
+glcube.py - Using PyOpenGL and Pygame, this creates a spinning 3D
+	multicolored cube.
+
+
 data/ - directory with the resources for the examples
 sdllogos.zip - zipfile with unofficial sdl logos
 

File examples/glcube.py

+#!/usr/bin/env python
+
+"""Draw a cube on the screen. every frame we orbit
+the camera around by a small amount and it appears
+the object is spinning. note i've setup some simple
+data structures here to represent a multicolored cube,
+we then go through a semi-unopimized loop to draw
+the cube points onto the screen. opengl does all the
+hard work for us. :]
+"""
+
+import pygame
+from pygame.locals import *
+
+try:
+    from OpenGL.GL import *
+    from OpenGL.GLU import *
+except:
+    print 'The GLCUBE example requires PyOpenGL'
+    raise SystemExit
+
+
+
+#some simple data for a colored cube
+#here we have the 3D point position and color
+#for each corner. then we have a list of indices
+#that describe each face, and a list of indieces
+#that describes each edge
+
+
+CUBE_POINTS = (
+    (0.5, -0.5, -0.5),  (0.5, 0.5, -0.5),
+    (-0.5, 0.5, -0.5),  (-0.5, -0.5, -0.5),
+    (0.5, -0.5, 0.5),   (0.5, 0.5, 0.5),
+    (-0.5, -0.5, 0.5),  (-0.5, 0.5, 0.5)
+)
+
+#colors are 0-1 floating values
+CUBE_COLORS = (
+    (1, 0, 0),          (1, 1, 0),
+    (0, 1, 0),          (0, 0, 0),
+    (1, 0, 1),          (1, 1, 1),
+    (0, 0, 1),          (0, 1, 1)
+)
+
+CUBE_QUAD_VERTS = (
+    (0, 1, 2, 3), (3, 2, 7, 6), (6, 7, 5, 4),
+    (4, 5, 1, 0), (1, 5, 7, 2), (4, 0, 3, 6)
+)
+
+CUBE_EDGES = (
+    (0,1), (0,3), (0,4), (2,1), (2,3), (2,7),
+    (6,3), (6,4), (6,7), (5,1), (5,4), (5,7),
+)
+
+
+
+def drawcube():
+    "draw the cube"
+    allpoints = zip(CUBE_POINTS, CUBE_COLORS)
+
+    glBegin(GL_QUADS)
+    for face in CUBE_QUAD_VERTS:
+        for vert in face:
+            pos, color = allpoints[vert]
+            glColor3(color)
+            glVertex3(pos)
+    glEnd()
+
+    glColor3((1.0, 1.0, 1.0))
+    glBegin(GL_LINES)
+    for line in CUBE_EDGES:
+        for vert in line:
+            pos, color = allpoints[vert]
+            glVertex3(pos)
+
+    glEnd()
+
+
+def main():
+    "run the demo"
+    #initialize pygame and setup an opengl display
+    pygame.init()
+    pygame.display.set_mode((640,480), OPENGL|DOUBLEBUF)
+    glEnable(GL_DEPTH_TEST)        #use our zbuffer
+
+    #setup the camera
+    glMatrixMode(GL_PROJECTION)
+    gluPerspective(45.0,640/480.0,0.1,100.0)    #setup lens
+    glTranslate(0.0, 0.0, -3.0)                 #move back
+    glRotate(25, 1, 0, 0)                       #orbit higher
+
+
+    while 1:
+        #check for quit'n events
+        event = pygame.event.poll()
+        if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
+            break
+
+        #clear screen and move camera
+        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
+
+        #orbit camera around by 1 degree
+        glRotate(1, 0, 1, 0)                    
+
+        drawcube()
+        pygame.display.flip()
+        pygame.time.delay(10)
+
+
+if __name__ == '__main__': main()

File lib/version.py

 releases. (hmm, until we get to versions > 10)
 """
 
-ver = '1.0'
+ver = '1.0.1'
 
 def __hiddendummyfunc():
     """pygame.version.ver 
 
 METADATA = {
     "name":             "pygame",
-    "version":          "1.0",
+    "version":          "1.0.1",
     "license":          "LGPL",
     "url":              "http://pygame.seul.org",
     "author":           "Pete Shinners",