root / PyOpenGL-Demo / tom / conechecker.py @ 2
Historique | Voir | Annoter | Télécharger (2,14 ko)
| 1 |
#!/usr/bin/python
|
|---|---|
| 2 |
|
| 3 |
# This is statement is required by the build system to query build info
|
| 4 |
if __name__ == '__build__': |
| 5 |
raise Exception |
| 6 |
|
| 7 |
|
| 8 |
import string |
| 9 |
__version__ = string.split('$Revision: 1.1.1.1 $')[1] |
| 10 |
__date__ = string.join(string.split('$Date: 2007/02/15 19:25:38 $')[1:3], ' ') |
| 11 |
__author__ = 'Tarn Weisner Burton <twburton@users.sourceforge.net>'
|
| 12 |
|
| 13 |
from OpenGL.GL import * |
| 14 |
from OpenGL.Tk import * |
| 15 |
from OpenGL.GLUT import * |
| 16 |
import sys |
| 17 |
|
| 18 |
def redraw_checker(o): |
| 19 |
glClearColor(1, 0, 1, 0) |
| 20 |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) |
| 21 |
glColor3f(0, 1, 0) |
| 22 |
#draw checkerboard
|
| 23 |
N = 4
|
| 24 |
glDisable(GL_LIGHTING) |
| 25 |
for x in range(-N, N): |
| 26 |
for y in range(-N, N): |
| 27 |
if (x + y) % 2 == 0: |
| 28 |
glColor3f(1, 1, 0) |
| 29 |
else:
|
| 30 |
glColor3f(0, 0, 0) |
| 31 |
glRectf(x, y, x + 1, y + 1) |
| 32 |
glEnable(GL_LIGHTING) |
| 33 |
|
| 34 |
glPushMatrix() |
| 35 |
glTranslatef(0., 0., 1.) |
| 36 |
glutSolidSphere(1.0,20,20) |
| 37 |
glPopMatrix() |
| 38 |
|
| 39 |
def init(): |
| 40 |
glMaterialfv(GL_FRONT, GL_AMBIENT, [0.2, 0.2, 0.2, 1.0]) |
| 41 |
glMaterialfv(GL_FRONT, GL_DIFFUSE, [0.8, 0.8, 0.8, 1.0]) |
| 42 |
glMaterialfv(GL_FRONT, GL_SPECULAR, [1.0, 0.0, 1.0, 1.0]) |
| 43 |
glMaterialfv(GL_FRONT, GL_SHININESS, 50.0)
|
| 44 |
glLightfv(GL_LIGHT0, GL_AMBIENT, [0.0, 1.0, 0.0, 1.0]) |
| 45 |
glLightfv(GL_LIGHT0, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0]) |
| 46 |
glLightfv(GL_LIGHT0, GL_SPECULAR, [1.0, 1.0, 1.0, 1.0]) |
| 47 |
glLightfv(GL_LIGHT0, GL_POSITION, [1.0, 1.0, 1.0, 0.0]); |
| 48 |
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, [0.2, 0.2, 0.2, 1.0]) |
| 49 |
glEnable(GL_LIGHTING) |
| 50 |
glEnable(GL_LIGHT0) |
| 51 |
glDepthFunc(GL_LESS) |
| 52 |
glEnable(GL_DEPTH_TEST) |
| 53 |
|
| 54 |
|
| 55 |
def redraw_cone(o): |
| 56 |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) |
| 57 |
glPushMatrix() |
| 58 |
glTranslatef(0, -1, 0) |
| 59 |
glRotatef(250, 1, 0, 0) |
| 60 |
glutSolidCone(1, 2, 50, 10) |
| 61 |
glPopMatrix() |
| 62 |
|
| 63 |
def main(): |
| 64 |
f = Frame() |
| 65 |
f.pack(side = TOP) |
| 66 |
o1 = Opengl(width = 200, height = 200, double = 1, depth = 1) |
| 67 |
glutInit([]) |
| 68 |
o1.redraw = redraw_checker |
| 69 |
quit = Button(f, text = 'Quit', command = sys.exit)
|
| 70 |
quit.pack(side = TOP, expand=YES, fill=BOTH) |
| 71 |
o1.pack(side = TOP, expand = YES, fill = BOTH) |
| 72 |
o1.set_eyepoint(20.)
|
| 73 |
|
| 74 |
o2 = Opengl(width = 200, height = 200, double = 1) |
| 75 |
o2.redraw = redraw_cone |
| 76 |
o2.autospin_allowed = 1
|
| 77 |
o2.pack(side = TOP, expand = YES, fill = BOTH) |
| 78 |
init() |
| 79 |
|
| 80 |
o1.mainloop() |
| 81 |
|
| 82 |
main() |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|