8 from OpenGL.GL import *
10 from PyQt4.Qt import QApplication, QMainWindow, QLabel
11 from PyQGLViewer import QGLViewer, Vec
13 from openalea.lpy import Lsystem
14 from openalea.plantgl.all import Discretizer, GLRenderer
17 class Viewer(QGLViewer):
18 def __init__(self, lfile):
19 QGLViewer.__init__(self)
21 center = Vec(0.16104, 0.00831, 2.53128)
22 position = Vec(4.74832, 4.66647, 8.79487)
24 self.discretizer = Discretizer()
25 self.renderer = GLRenderer(self.discretizer)
26 self.lsystem = Lsystem(lfile)
27 self.scene = self.lsystem.sceneInterpretation(self.lsystem.iterate())
29 camera = self.camera()
30 camera.setRevolveAroundPoint(center)
31 camera.setPosition(position)
32 camera.setUpVector(Vec(0,0,1))
34 camera.setSceneRadius(7)
37 light_pos = list(self.camera().position())+[1.0]
38 light_dir = list(self.camera().viewDirection())+[1.0]
43 glLightfv(GL_LIGHT0, GL_POSITION, light_pos)
44 glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light_dir)
45 glLightfv(GL_LIGHT0, GL_AMBIENT, (0.6,0.6,0.6,1.0))
46 glLightfv(GL_LIGHT0, GL_DIFFUSE, (1.0,1.0,1.0,1.0))
47 glLightfv(GL_LIGHT0, GL_SPECULAR, (1.0,1.0,1.0,1.0))
49 if self.renderer.beginSceneList():
50 glEnable(GL_RESCALE_NORMAL)
51 self.scene.apply(self.renderer)
52 self.renderer.endSceneList()
56 def __init__(self, args):
60 app = QApplication(self.args)
62 btn = QLabel("Hello, World");
64 win.setCentralWidget(btn)
72 def __init__(self, args):
76 app = QApplication(self.args)
78 view = Viewer("plant.lpy");
80 win.setCentralWidget(view)
87 for test in sys.argv[1:]:
93 if test == 'plantgl' or test == 'pgl':
94 pgl = TestPlantGL(sys.argv)