3 # *** This only works correctly on a 24 bit-plane machine. ***
5 # A simple Python program that tests the some parts of the
6 # GL library. It shows the speed that can be obtained when
7 # doing simple graphics.
9 # The bottleneck in this program is NOT Python but the graphics
10 # engine; i.e Python can feed the graphics pipeline fast enough
13 # This program show 3 kites flying around the screen. It uses
15 # * bgnpolygon, endpolygon
22 # MOUSE3 -> freeze toggle
23 # MOUSE2 -> one step (use this in freeze state)
31 # viewobj : sets the rotation, translation and scaling
32 # set appropiate material, call drawobject()
34 def viewobj (r
, s
, t
, mat
) :
39 scale (s
[0], s
[1], s
[2])
40 translate (t
[0], t
[1], t
[2])
46 # makeobj : the constructor of the object
53 n0
= (sqrt(2.0)/2.0, sqrt(2.0)/2.0, 0.0)
54 vn
= ((v0
, n0
), (v1
, n0
), (v2
, n0
), (v3
, n0
))
59 # the object itself as an array of vertices and normals
64 # drawobject : draw a triangle. with bgnpolygon
75 idmat
=[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
78 # the rgb-value of light-blue
80 LightBlue
= (43,169,255)
83 # the different materials.
85 m1
=[SPECULAR
,0.0,0.0,0.6,DIFFUSE
,0.0,0.0,0.8,SHININESS
,20.0,LMNULL
]
86 m2
=[SPECULAR
,0.8,0.0,0.1,DIFFUSE
,0.8,0.0,0.3,SHININESS
,120.0,LMNULL
]
87 m3
=[SPECULAR
,0.0,1.0,0.0,DIFFUSE
,0.0,0.6,0.0,SHININESS
,120.0,LMNULL
]
92 light1
= [LCOLOR
,1.0,1.0,1.0,POSITION
,15.0,15.0,0.0,1.0,LMNULL
]
93 light2
= [LCOLOR
,1.0,1.0,1.0,POSITION
,-15.0,15.0,0.0,1.0,LMNULL
]
98 model
= [AMBIENT
,0.2,0.2,0.2,LMNULL
]
101 # initgl : opens the window, configures the pipeline to 2buf and zbuf,
102 # sets the viewing, defines and binds the materials
110 prefposition (100, 500, 100, 500)
111 w
= winopen ('PYTHON lights')
115 # configure pipeline (zbuf, 2buf, GOURAUD and RGBmode)
123 # define and bind materials (set perspective BEFORE loadmat !)
126 perspective (900, 1.0, 1.0, 20.0)
128 lmdef(DEFMATERIAL
, 1, m1
)
129 lmdef(DEFMATERIAL
, 2, m2
)
130 lmdef(DEFMATERIAL
, 3, m3
)
131 lmdef(DEFLIGHT
, 1, light1
)
132 lmdef(DEFLIGHT
, 2, light2
)
133 lmdef(DEFLMODEL
, 1, model
)
140 lookat (0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0)
142 # ask for the REDRAW and ESCKEY events
144 qdevice(DEVICE
.MOUSE3
)
145 qdevice(DEVICE
.MOUSE2
)
146 qdevice(DEVICE
.REDRAW
)
147 qdevice(DEVICE
.ESCKEY
)
150 # GoForIT : use 2buf to redraw the object 2n times. index i is used as
151 # the (smoothly changing) rotation angle
159 # clear z-buffer and clear background to light-blue
165 # draw the 3 traiangles scaled above each other.
167 viewobj(float(i
),[1.0,1.0,1.0],[1.0,1.0,1.0],1)
168 viewobj(float(i
),[0.75,0.75,0.75],[0.0,2.0,2.0],2)
169 viewobj(float(i
),[0.5,0.5,0.5],[0.0,4.0,4.0],3)
175 if dev
== DEVICE
.ESCKEY
:
177 elif dev
== DEVICE
.REDRAW
:
179 elif dev
== DEVICE
.MOUSE3
and val
<> 0 :
181 elif dev
== DEVICE
.MOUSE2
and val
<> 0 :