root / PyOpenGL-Demo / broken / tom / fog.py
Historique | Voir | Annoter | Télécharger (2,45 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.GLUT import * |
| 15 |
from OpenGL.Tk import * |
| 16 |
|
| 17 |
class Fog: |
| 18 |
def __init__(self): |
| 19 |
self.o = Opengl(width = 250, height = 140, double = 1, depth = 1) |
| 20 |
self.o.redraw = self.redraw |
| 21 |
self.o.pack(side = 'top', expand = 1, fill = 'both') |
| 22 |
self.mode = IntVar(self.o) |
| 23 |
self.mode.set(GL_EXP)
|
| 24 |
r1 = Radiobutton(text='GL_LINEAR', anchor=W, variable=self.mode, |
| 25 |
value=GL_LINEAR, command=self.selectFog)
|
| 26 |
r1.pack(side = 'top', expand = 1, fill = 'both') |
| 27 |
r2 = Radiobutton(text='GL_EXP', anchor=W, variable=self.mode, |
| 28 |
value=GL_EXP, command=self.selectFog)
|
| 29 |
r2.pack(side = 'top', expand = 1, fill = 'both') |
| 30 |
|
| 31 |
def run(self): |
| 32 |
self.init()
|
| 33 |
self.o.mainloop()
|
| 34 |
|
| 35 |
def selectFog(self): |
| 36 |
val = self.mode.get()
|
| 37 |
if val == GL_LINEAR:
|
| 38 |
glFogf(GL_FOG_START, 1.0)
|
| 39 |
glFogf(GL_FOG_END, 5.0)
|
| 40 |
glFogi(GL_FOG_MODE, val) |
| 41 |
elif val == GL_EXP:
|
| 42 |
glFogi(GL_FOG_MODE, val) |
| 43 |
self.o.tkRedraw()
|
| 44 |
|
| 45 |
def init(self): |
| 46 |
glutInit( [] ) |
| 47 |
glDisable(GL_DITHER) |
| 48 |
glEnable(GL_DEPTH_TEST) |
| 49 |
glDepthFunc(GL_LESS) |
| 50 |
glLightfv(GL_LIGHT0, GL_POSITION, [0.0, 3.0, 3.0, 0.0]) |
| 51 |
glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 0.0)
|
| 52 |
glFrontFace(GL_CW) |
| 53 |
glEnable(GL_LIGHTING) |
| 54 |
glEnable(GL_LIGHT0) |
| 55 |
glEnable(GL_AUTO_NORMAL) |
| 56 |
glEnable(GL_NORMALIZE) |
| 57 |
glEnable(GL_FOG) |
| 58 |
fogColor = [0.5, 0.5, 0.5, 1.0] |
| 59 |
glFogi(GL_FOG_MODE, GL_EXP) |
| 60 |
glFogfv(GL_FOG_COLOR, fogColor) |
| 61 |
glFogf(GL_FOG_DENSITY, 0.35)
|
| 62 |
glHint(GL_FOG_HINT, GL_DONT_CARE) |
| 63 |
glClearColor(0.5, 0.5, 0.5, 1.0) |
| 64 |
|
| 65 |
def drawTorus(self, x, y, z): |
| 66 |
glPushMatrix(); |
| 67 |
glTranslatef(x, y, z); |
| 68 |
glMaterialfv(GL_FRONT, GL_AMBIENT, [0.1745, 0.01175, 0.01175, 1.0]) |
| 69 |
glMaterialfv(GL_FRONT, GL_DIFFUSE, [0.61424, 0.04136, 0.04136, 1.0]) |
| 70 |
glMaterialfv(GL_FRONT, GL_SPECULAR, [0.727811, 0.626959, 0.626959, 1.0]) |
| 71 |
glMaterialfv(GL_FRONT, GL_SHININESS, 0.6 * 128.0) |
| 72 |
glutSolidTorus(0.275, 0.85, 20, 20) |
| 73 |
glPopMatrix() |
| 74 |
|
| 75 |
def redraw(self, o): |
| 76 |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) |
| 77 |
self.drawTorus(-4.0, -0.5, -1.0) |
| 78 |
self.drawTorus(-2.0, -0.5, -2.0) |
| 79 |
self.drawTorus(0.0, -0.5, -3.0) |
| 80 |
self.drawTorus(2.0, -0.5, -4.0) |
| 81 |
self.drawTorus(4.0, -0.5, -5.0) |
| 82 |
|
| 83 |
def main(): |
| 84 |
f = Fog() |
| 85 |
f.run() |
| 86 |
|
| 87 |
main() |