root / PyOpenGL-Demo / GLUT / tom / conechecker.py @ 2
Historique | Voir | Annoter | Télécharger (2,02 ko)
| 1 |
"""GLUT replacement for the original conechecker.py demonstration code
|
|---|---|
| 2 |
|
| 3 |
Note:
|
| 4 |
Has no navigation code ATM. Rather than creating two contexts,
|
| 5 |
it creates two viewports in the same context and renders into them
|
| 6 |
using the display functions from the other demo modules.
|
| 7 |
"""
|
| 8 |
|
| 9 |
# This is statement is required by the build system to query build info
|
| 10 |
if __name__ == '__build__': |
| 11 |
raise Exception |
| 12 |
|
| 13 |
__version__='$Revision: 1.1.1.1 $'[11:-2] |
| 14 |
__date__ = '$Date: 2007/02/15 19:25:11 $'[6:-2] |
| 15 |
|
| 16 |
import OpenGL |
| 17 |
OpenGL.ERROR_ON_COPY = True
|
| 18 |
|
| 19 |
from OpenGL.GL import * |
| 20 |
from OpenGL.GLU import * |
| 21 |
from OpenGL.GLUT import * |
| 22 |
import time, sys |
| 23 |
import cone, checker |
| 24 |
|
| 25 |
def display( ): |
| 26 |
"""Callback function for displaying the scene
|
| 27 |
|
| 28 |
This defines a unit-square environment in which to draw,
|
| 29 |
i.e. width is one drawing unit, as is height
|
| 30 |
"""
|
| 31 |
glClearColor(0.5, 0.5, 0.5, 0) |
| 32 |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) |
| 33 |
width,height = glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT) |
| 34 |
halfHeight = int(height/2.0) |
| 35 |
glViewport(0,halfHeight,width, halfHeight+1) |
| 36 |
# glClear doesn't restrict itself to the viewport,
|
| 37 |
# so we have to tell the child viewports not to use it...
|
| 38 |
checker.display( swap=0, clear=0) |
| 39 |
glViewport(0,0,width, halfHeight) |
| 40 |
cone.display( swap=1, clear=0) |
| 41 |
glViewport(0,0,width, height) |
| 42 |
|
| 43 |
def idle( ): |
| 44 |
glutPostRedisplay() |
| 45 |
|
| 46 |
starttime = time.time() |
| 47 |
|
| 48 |
def rotation( period = 10): |
| 49 |
"""Do rotation of the scene at given rate"""
|
| 50 |
angle = (((time.time()-starttime)%period)/period)* 360
|
| 51 |
glRotate( angle, 0,1,0) |
| 52 |
return angle
|
| 53 |
def key_pressed(*args): |
| 54 |
# If escape is pressed, kill everything.
|
| 55 |
if args[0] == '\033': |
| 56 |
sys.exit() |
| 57 |
|
| 58 |
if __name__ == "__main__": |
| 59 |
print """You should see two OpenGL viewports, in the top, a sphere+checker-board |
| 60 |
and in the bottom, a rotating cone."""
|
| 61 |
import sys |
| 62 |
glutInit(sys.argv) |
| 63 |
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) |
| 64 |
glutCreateWindow('Two-scene Demo (Cone Checker)')
|
| 65 |
glutDisplayFunc(display) |
| 66 |
glutKeyboardFunc(key_pressed) |
| 67 |
glutIdleFunc(display) |
| 68 |
# note need to do this to properly render faceted geometry
|
| 69 |
glutMainLoop() |