Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 453bd40

Browse files
committed
Initial revision
1 parent 6da6aeb commit 453bd40

18 files changed

Lines changed: 2990 additions & 0 deletions

Demo/sgi/gl/README

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
These demos run only on SGI machines and require the 'gl' built-in module.
2+
The demonstrate the abilities of SGI's GL library as well as the ease of
3+
GL programming in Python. Most demos require the Z-buffer (aka
4+
24-bitplane) option. Press ESC to get out of any of them.
5+
6+
backface.py Demonstrates the 'backface' GL function.
7+
8+
kites.py Show 3 flying kites. Demonstrates the rendering speed
9+
obtainable by Python programs.
10+
11+
mclock.py A colorful clock with more options than you can
12+
remember. Works on 8-bit machines, but allows more
13+
colors on 24-bit machines. See mclock.doc for more
14+
info.
15+
16+
mixing.py Demonstrates the effect of color mixing: through
17+
frequent color switching it gives the effect of white
18+
light.
19+
20+
nurbs.py A simple demonstration of the 'nurbs' GL functions.
21+
Press left mouse button to toggle surface trimming.
22+
23+
zrgb.py Displays a 3-D Gouraud-shaded figure which can be moved
24+
around with the mouse.
25+
26+
glstdwin/ This is quite different: a partial STDWIN emulation
27+
using GL! Requires only small changes to Python
28+
programs that use STDWIN. Some features not yet
29+
implemented, e.g., scroll bars.

Demo/sgi/gl/backface.py

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#! /usr/local/python
2+
3+
# backface
4+
#
5+
# draw a cube that can run with backface() turned on or off.
6+
# cube is moved when LEFTMOUSE is pressed and mouse itself is moved.
7+
8+
from gl import *
9+
from DEVICE import *
10+
from GL import *
11+
12+
CUBE_SIZE = 200.0
13+
CUBE_OBJ = 1
14+
15+
def main () :
16+
#
17+
x = 0
18+
y = 0
19+
moveit = 0
20+
#
21+
initialize()
22+
#
23+
while (1) :
24+
#
25+
while (qtest()) :
26+
dev, val = qread()
27+
#
28+
if dev == ESCKEY :
29+
backface(0)
30+
return
31+
#
32+
elif dev == REDRAW :
33+
reshapeviewport()
34+
drawcube(x,y)
35+
#
36+
elif dev == LEFTMOUSE :
37+
#
38+
# LEFTMOUSE down
39+
moveit = val
40+
#
41+
elif dev == BKEY :
42+
backface(1)
43+
drawcube(x,y)
44+
#
45+
elif dev == FKEY :
46+
backface(0)
47+
drawcube(x,y)
48+
#
49+
if moveit :
50+
x = getvaluator(MOUSEX)
51+
y = getvaluator(MOUSEY)
52+
drawcube(x,y)
53+
54+
55+
def initialize () :
56+
foreground ()
57+
keepaspect (1, 1)
58+
gid = winopen('backface')
59+
winset(gid)
60+
winconstraints()
61+
#
62+
doublebuffer()
63+
gconfig()
64+
shademodel(FLAT)
65+
#
66+
ortho(-1024.0, 1024.0, -1024.0, 1024.0, -1024.0, 1024.0)
67+
#
68+
qdevice(ESCKEY)
69+
qdevice(REDRAW)
70+
qdevice(LEFTMOUSE)
71+
qdevice(BKEY)
72+
qdevice(FKEY)
73+
qenter(REDRAW,gid)
74+
#
75+
backface(1)
76+
77+
#
78+
# define a cube
79+
def cube () :
80+
#
81+
# front face
82+
pushmatrix()
83+
translate(0.0,0.0,CUBE_SIZE)
84+
color(RED)
85+
rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
86+
popmatrix()
87+
#
88+
# right face
89+
pushmatrix()
90+
translate(CUBE_SIZE, 0.0, 0.0)
91+
rotate(900, 'y')
92+
color(GREEN)
93+
rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
94+
popmatrix()
95+
#
96+
# back face
97+
pushmatrix()
98+
translate(0.0, 0.0, -CUBE_SIZE)
99+
rotate(1800, 'y')
100+
color(BLUE)
101+
rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
102+
popmatrix()
103+
#
104+
# left face
105+
pushmatrix()
106+
translate(-CUBE_SIZE, 0.0, 0.0)
107+
rotate(-900, 'y')
108+
color(CYAN)
109+
rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
110+
popmatrix()
111+
#
112+
# top face
113+
pushmatrix()
114+
translate(0.0, CUBE_SIZE, 0.0)
115+
rotate(-900, 'x')
116+
color(MAGENTA)
117+
rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
118+
popmatrix()
119+
#
120+
# bottom face
121+
pushmatrix()
122+
translate(0.0, -CUBE_SIZE, 0.0)
123+
rotate(900, 'x')
124+
color(YELLOW)
125+
rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
126+
popmatrix()
127+
128+
def drawcube(x,y) :
129+
#
130+
pushmatrix()
131+
rotate(2*x, 'x')
132+
rotate(2*y, 'y')
133+
color(BLACK)
134+
clear()
135+
cube()
136+
popmatrix()
137+
swapbuffers()
138+
139+
140+
main ()

Demo/sgi/gl/glstdwin/fontchart.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import stdwingl
2+
3+
import stdwin
4+
from stdwinevents import *
5+
6+
def main():
7+
size = 12
8+
w = stdwin.open('Font chart ' + `size`)
9+
while 1:
10+
type, window, detail = stdwin.getevent()
11+
if type == WE_CLOSE:
12+
break
13+
if type == WE_DRAW:
14+
width, height = w.getwinsize()
15+
d = w.begindrawing()
16+
d.setsize(size)
17+
h, v = 0, 0
18+
for c in range(32, 256):
19+
ch = chr(c)
20+
chw = d.textwidth(ch)
21+
if h + chw > width:
22+
v = v + d.lineheight()
23+
h = 0
24+
if v >= height:
25+
break
26+
d.text((h, v), ch)
27+
h = h + chw
28+
del d
29+
if type == WE_MOUSE_UP:
30+
size = size + 1
31+
w.settitle('Font chart ' + `size`)
32+
w.change((0, 0), (2000, 2000))
33+
34+
main()

Demo/sgi/gl/glstdwin/glstdwdraw.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Define drawing operations for GL stdwin
2+
3+
import gl
4+
import fm
5+
from GL import LO_XOR, LO_SRC
6+
from glstdwin import MASK
7+
8+
class DrawingObject:
9+
#
10+
def _init(self, win):
11+
self.fg = win._fg
12+
self.bg = win._bg
13+
self.font = win._font
14+
self.size = win._size
15+
self.width, self.height = win._area[1]
16+
gl.winset(win._gid)
17+
gl.color(self.fg)
18+
return self
19+
#
20+
def setfont(self, fontname):
21+
self.font = fm.findfont(fontname).scalefont(self.size)
22+
#
23+
def setsize(self, size):
24+
ratio = float(size) / float(self.size)
25+
self.size = size
26+
self.font = self.font.scalefont(ratio)
27+
#
28+
def setfgcolor(self, color):
29+
self.fg = color
30+
gl.color(self.fg)
31+
#
32+
def setbgcolor(self, color):
33+
self.bg = color
34+
#
35+
def cliprect(self, area):
36+
#print 'cliprect', area
37+
(left, top), (right, bottom) = area
38+
gl.scrmask(left, right, self.height-bottom, self.height-top)
39+
#
40+
def noclip(self):
41+
#print 'noclip()'
42+
gl.scrmask(0, self.width, 0, self.height)
43+
#
44+
def paint(self, ((left, top), (right, bottom))):
45+
gl.rectf(left, top, right, bottom)
46+
#
47+
def box(self, ((left, top), (right, bottom))):
48+
#print 'box', ((left, top), (right, bottom))
49+
gl.rect(left, top, right, bottom)
50+
#
51+
def circle(self, ((h, v), radius)):
52+
gl.circ(h, v, radius)
53+
#
54+
def elarc(self, (center, (rh, rv), a1, a2)):
55+
pass # XXX
56+
#
57+
def erase(self, ((left, top), (right, bottom))):
58+
#print 'erase', ((left, top), (right, bottom))
59+
gl.color(self.bg)
60+
gl.rectf(left, top, right, bottom)
61+
gl.color(self.fg)
62+
#
63+
def invert(self, ((left, top), (right, bottom))):
64+
#print 'invert', ((h0, v0), (h1, v1))
65+
gl.logicop(LO_XOR)
66+
gl.color(self.bg)
67+
gl.rectf(left, top, right, bottom)
68+
gl.color(self.fg)
69+
gl.logicop(LO_SRC)
70+
#
71+
def line(self, ((h0, v0), (h1, v1))):
72+
#print 'line', ((h0, v0), (h1, v1))
73+
gl.bgnline()
74+
gl.v2i(h0, v0)
75+
gl.v2i(h1, v1)
76+
gl.endline()
77+
#
78+
def xorline(self, ((h0, v0), (h1, v1))):
79+
#print 'xorline', ((h0, v0), (h1, v1))
80+
gl.logicop(LO_XOR)
81+
gl.color(self.bg)
82+
gl.bgnline()
83+
gl.v2i(h0, v0)
84+
gl.v2i(h1, v1)
85+
gl.endline()
86+
gl.color(self.fg)
87+
gl.logicop(LO_SRC)
88+
#
89+
def point(self, (h, v)):
90+
#print 'point', (h, v)
91+
gl.bgnpoint()
92+
gl.v2i(h, v)
93+
gl.endpoint()
94+
#
95+
def text(self, ((h, v), string)):
96+
#print 'text', ((h, v), string)
97+
if h < 0:
98+
# If the point is outside the window
99+
# the whole string isn't drawn.
100+
# Skip the beginning of the string.
101+
# XXX What if the font is bigger than 20 pixels?
102+
i, n = 0, len(string)
103+
while h < -MASK and i < n:
104+
h = h + self.font.getstrwidth(string[i])
105+
i = i + 1
106+
string = string[i:]
107+
gl.cmov2(h, v + self.baseline())
108+
self.font.setfont()
109+
fm.prstr(string)
110+
#
111+
def shade(self, ((h, v), percent)):
112+
pass # XXX
113+
#
114+
def baseline(self):
115+
(printermatched, fixed_width, xorig, yorig, xsize, ysize, \
116+
height, nglyphs) = self.font.getfontinfo()
117+
return height - yorig
118+
#
119+
def lineheight(self):
120+
(printermatched, fixed_width, xorig, yorig, xsize, ysize, \
121+
height, nglyphs) = self.font.getfontinfo()
122+
return height
123+
#
124+
def textbreak(self, (string, width)):
125+
# XXX Slooooow!
126+
n = len(string)
127+
nwidth = self.textwidth(string[:n])
128+
while nwidth > width:
129+
n = n-1
130+
nwidth = self.textwidth(string[:n])
131+
return n
132+
#
133+
def textwidth(self, string):
134+
return self.font.getstrwidth(string)
135+
#

0 commit comments

Comments
 (0)