1 |
|
# (c) Tuomas J. Lukka |
2 |
|
# |
3 |
# A gl demo framework that can reload the given file at will. |
# A gl demo framework that can reload the given file at will. |
4 |
# |
# |
5 |
# The target size for demos is 1024x768, since that is |
# The target size for demos is 1024x768, since that is |
8 |
# Our demo animations will also be in that size. |
# Our demo animations will also be in that size. |
9 |
# |
# |
10 |
# The current screen size can be queried from the vobscene |
# The current screen size can be queried from the vobscene |
11 |
# and the user is free to resize the window; demos shouldn't. |
# and the user is free to resize the window; demos shouldn't |
12 |
|
# automatically resize the window. |
13 |
|
# |
14 |
|
# The demos should make an effort to adapt to any window size. |
15 |
|
|
16 |
import sys |
import sys |
17 |
# Unfortunate debianisms XXX |
# Unfortunate debianisms XXX |
31 |
import gzz |
import gzz |
32 |
import traceback |
import traceback |
33 |
|
|
34 |
|
from gfx.util.misc import * |
35 |
|
|
36 |
System.setProperty("gzzclient", "gl") |
System.setProperty("gzzclient", "gl") |
37 |
|
|
38 |
print "ARGV:",sys.argv |
print "ARGV:",sys.argv |
45 |
if o in gzz.util.dbg.all: |
if o in gzz.util.dbg.all: |
46 |
gzz.util.dbg.option(o,a) |
gzz.util.dbg.option(o,a) |
47 |
|
|
|
def background(rgb): |
|
|
return gzz.vob.vobs.SolidBgVob(java.awt.Color(float(rgb[0]), float(rgb[1]), float(rgb[2]))) |
|
|
|
|
|
def texbindcode(texid): |
|
|
if texid: |
|
|
return "BindTexture TEXTURE_2D %s"%texid |
|
|
return "" |
|
|
|
|
|
def coloredQuad(rgb, texid=None, texcoord1 = 1): |
|
|
texcode = texbindcode(texid) |
|
|
r,g,b = rgb |
|
|
return getDList(""" |
|
|
PushAttrib TEXTURE_BIT |
|
|
"""+texcode+""" |
|
|
Color %(r)s %(g)s %(b)s |
|
|
Begin QUADS |
|
|
TexCoord 0 0 |
|
|
Vertex 0 0 |
|
|
TexCoord 0 %(texcoord1)s |
|
|
Vertex 0 1 |
|
|
TexCoord %(texcoord1)s %(texcoord1)s |
|
|
Vertex 1 1 |
|
|
TexCoord %(texcoord1)s 0 |
|
|
Vertex 1 0 |
|
|
End |
|
|
PopAttrib |
|
|
"""%locals()) |
|
|
|
|
|
def quad(texid=None): |
|
|
texcode = texbindcode(texid) |
|
|
return getDList(""" |
|
|
PushAttrib TEXTURE_BIT |
|
|
"""+texcode+""" |
|
|
Begin QUADS |
|
|
TexCoord 0 0 |
|
|
Vertex 0 0 |
|
|
TexCoord 0 1 |
|
|
Vertex 0 1 |
|
|
TexCoord 1 1 |
|
|
Vertex 1 1 |
|
|
TexCoord 1 0 |
|
|
Vertex 1 0 |
|
|
End |
|
|
PopAttrib |
|
|
""") |
|
|
|
|
|
def partialquad(x0, y0, x1, y1, texid = None): |
|
|
texcode = texbindcode(texid) |
|
|
return getDList(""" |
|
|
PushAttrib TEXTURE_BIT |
|
|
"""+texcode+""" |
|
|
Begin QUADS |
|
|
TexCoord %(x0)s %(y0)s |
|
|
Vertex -1 -1 |
|
|
TexCoord %(x0)s %(y1)s |
|
|
Vertex -1 1 |
|
|
TexCoord %(x1)s %(y1)s |
|
|
Vertex 1 1 |
|
|
TexCoord %(x1)s %(y0)s |
|
|
Vertex 1 -1 |
|
|
End |
|
|
PopAttrib |
|
|
""" % locals()) |
|
|
|
|
|
textstyle = None |
|
|
|
|
|
def getText(text): |
|
|
global textstyle |
|
|
if not textstyle: |
|
|
textstyle = GLTextStyle.create("sans", 0, 1) |
|
|
return TextVob(textstyle, text, 1) |
|
|
|
|
|
def putText(vs, cs1, text, color = None, x = 0, y = 0, z = 0, h = 1, key = None): |
|
|
if color != None: |
|
|
putnoc(vs, getDListNocoords("Color " + js(color))) |
|
|
putnoc(vs, getDListNocoords(""" |
|
|
PushAttrib ENABLE_BIT |
|
|
Disable ALPHA_TEST |
|
|
Disable DEPTH_TEST |
|
|
Enable TEXTURE_2D |
|
|
Enable BLEND |
|
|
BlendFunc SRC_ALPHA ONE_MINUS_SRC_ALPHA |
|
|
""")) |
|
|
|
|
|
t = getText(text) |
|
|
|
|
|
cs = vs.coords.ortho(cs1, z, x, y-h, h, h) |
|
|
vs.matcher.addSub(cs1, cs, key or str(text)) |
|
|
|
|
|
vs.map.put(t, cs) |
|
|
|
|
|
putnoc(vs, getDListNocoords(""" |
|
|
PopAttrib |
|
|
""")) |
|
|
|
|
|
|
|
|
def js(list): |
|
|
return " ".join([str(el) for el in list]) |
|
|
|
|
|
def rotatelist(list): |
|
|
list.append(list.pop(0)) |
|
|
|
|
|
def getDList(s): |
|
|
return GLCache.getCallListCoorded(s) |
|
|
|
|
|
def getDListNocoords(s): |
|
|
return GLCache.getCallList(s) |
|
|
|
|
|
imgs = { } |
|
|
texs = { } |
|
|
def getTex(s): |
|
|
global w |
|
|
if not imgs.has_key(s): |
|
|
print "Load image ",s |
|
|
imgs[s] = GL.createImage(s) |
|
|
texs[s] = GL.createTexRect(imgs[s]) |
|
|
return texs[s] |
|
|
|
|
|
if not locals().has_key("textures"): |
|
|
textures = {} |
|
|
|
|
|
def retexture(): |
|
|
global textures |
|
|
textures = {} |
|
|
|
|
|
# XXX naming |
|
|
def getTexture(*args): |
|
|
key = str(args) |
|
|
if not textures.has_key(key): |
|
|
textures[key] = GL.createTexture() |
|
|
print "Generating texture: ", args |
|
|
res = textures[key].shade(*args) |
|
|
print "SHADER: ", res |
|
|
return textures[key] |
|
|
|
|
|
|
|
|
|
|
|
def floats(start, end, n): |
|
|
return [float(x) * (end-start) / n + start |
|
|
for x in range(0,n+1)] |
|
|
def putAffine(vs, vob, key, d, x, y, xx, xy, yx, yy): |
|
|
cs = vs.coords.affineCoordsys(key, |
|
|
0, x, y, xx, xy, yx, yy) |
|
|
vs.map.put(vob, cs) |
|
|
|
|
|
transmap = { } |
|
|
|
|
|
transpush = None |
|
|
|
|
|
def transaffine(vs, key, x, y, xx, xy, yx, yy): |
|
|
cs = vs.coords.affineCoordsys(key, |
|
|
0, x, y, xx, xy, yx, yy) |
|
|
global transpush |
|
|
if transpush == None: |
|
|
transpush = GLRen.createGLTransformPush1() |
|
|
vs.map.put(transpush, cs) |
|
|
transmap[key] = cs |
|
|
|
|
|
rotatepush = None |
|
|
|
|
|
def rotate(vs, key, angle, x, y, z): |
|
|
cs = vs.coords.affineCoordsys(key, |
|
|
0, angle, x, y, 0, 0, z) |
|
|
global rotatepush |
|
|
if rotatepush == None: |
|
|
rotatepush = GLRen.createGLTransformRotatePush() |
|
|
vs.map.put(rotatepush, cs) |
|
|
transmap[key] = cs |
|
|
|
|
|
expscalepush = None |
|
|
def expscale(vs, key, scale): |
|
|
cs = vs.coords.affineCoordsys(key, |
|
|
scale, 0, 0, 0, 0, 0, 0) |
|
|
global expscalepush |
|
|
if expscalepush == None: |
|
|
expscalepush = GLRen.createGLExpScalePush() |
|
|
vs.map.put(expscalepush, cs) |
|
|
transmap[key] = cs |
|
|
|
|
|
|
|
|
def poptrans(vs, key): |
|
|
vs.map.put(getDList("PopMatrix\n"), transmap[key]) |
|
|
|
|
|
def putnoc(vs, noc): |
|
|
vs.put(noc, "NOCKEY", 10, 0, 0, 1, 1) |
|
|
|
|
48 |
|
|
49 |
currentScene = None |
currentScene = None |
50 |
|
|
128 |
# b = Bindings() |
# b = Bindings() |
129 |
# w.registerBinder(b) |
# w.registerBinder(b) |
130 |
# def |
# def |
131 |
|
|
132 |
class Show(AbstractShower): |
class Show(AbstractShower): |
133 |
def generate(self): |
def generate(self): |
134 |
# print "GENERATE" |
# print "GENERATE" |
|
vs = w.createVobScene() |
|
135 |
if not currentScene: |
if not currentScene: |
136 |
print "No scene\n" |
print "No scene\n" |
137 |
return vs |
return vs |
140 |
vs = replacingScene |
vs = replacingScene |
141 |
replacingScene = None |
replacingScene = None |
142 |
else: |
else: |
143 |
|
vs = w.createVobScene() |
144 |
currentScene.scene(vs) |
currentScene.scene(vs) |
145 |
return vs |
return vs |
146 |
|
|