[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz/gfx demo/irregular2.py libutil/effects.py l...
From: |
Janne V. Kujala |
Subject: |
[Gzz-commits] gzz/gfx demo/irregular2.py libutil/effects.py l... |
Date: |
Mon, 04 Nov 2002 05:38:57 -0500 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Janne V. Kujala <address@hidden> 02/11/04 05:38:55
Modified files:
gfx/demo : irregular2.py
gfx/libutil : effects.py
gfx/librenderables: renderables.py
Log message:
Added IrregularEllipse to effects.py, test with irregular2 demo
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/irregular2.py.diff?tr1=1.22&tr2=1.23&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libutil/effects.py.diff?tr1=1.23&tr2=1.24&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/librenderables/renderables.py.diff?tr1=1.127&tr2=1.128&r1=text&r2=text
Patches:
Index: gzz/gfx/demo/irregular2.py
diff -u gzz/gfx/demo/irregular2.py:1.22 gzz/gfx/demo/irregular2.py:1.23
--- gzz/gfx/demo/irregular2.py:1.22 Sat Sep 28 06:03:16 2002
+++ gzz/gfx/demo/irregular2.py Mon Nov 4 05:38:55 2002
@@ -10,6 +10,7 @@
self.mode = 255
self.combiners = "Enable"
+ self.type = "square"
self.period = 1.0
self.border = 0.2
self.w, self.h = 2, 1.5
@@ -21,12 +22,10 @@
self.xs, self.ys = 1, 1
self.a1 = 0
self.scale = 1
+ self.distort = 1
def initirregu(self):
- self.white = getDListNocoords("Color 1 1 1")
- self.black = getDListNocoords("Color 0 0 0")
-
w = self.w
h = self.h
self.mask = getDList("""
@@ -38,7 +37,8 @@
End
""" % locals())
- self.irreguframe = IrreguFrame(-w, -h, w, h, self.border, self.period)
+ self.irreguframe = IrreguFrame(-w, -h, w, h, self.border, self.period,
+ type = self.type)
def key(self, k):
if 0: pass
@@ -73,6 +73,15 @@
elif "1" <= k <= "9":
self.mode ^= 1 << (int(k)-1)
print "mode=", [ (".","X")[(self.mode >> i) & 1] for i in range(0,
9) ]
+ elif k == "t":
+ if self.type == "square":
+ self.type = "ellipse"
+ else:
+ self.type = "square"
+ self.initirregu()
+ elif k == "d":
+ self.distort = not self.distort
+
pass
def scene(self, vs):
@@ -81,9 +90,18 @@
#putnoc(vs, getDListNocoords("Translate -1000 -1000 0\nScale 4 4 4\n"))
#cs2 = vs.coords.affineCoordsys(0, 10, self.x1, self.y1, self.xs, 0,
0, self.ys)
- cs2 = vs.coords.affineCoordsys(0, 0, self.x1, self.y1,
- self.xs * cos(self.a1), -self.xs * sin(self.a1),
self.ys*sin(self.a1), self.ys*cos(self.a1))
+
+ cs2 = vs.coords.affineCoordsys(
+ 0, 0, self.x1, self.y1,
+ self.xs * cos(self.a1), self.ys * -sin(self.a1),
+ self.xs * sin(self.a1), self.ys * cos(self.a1) )
+
vs.matcher.add(cs2, "2")
+
+ if self.type == "square":
+ cs2 = vs.coords.affineCoordsys(cs2, 0, -1, -1, 2, 0, 0, 2 )
+ vs.matcher.add(cs2, "2box")
+
cs1 = vs.coords.affineCoordsys(0, 10, 600, 450,
self.scale * 150,
self.scale * 32.3,
@@ -94,7 +112,7 @@
cs1_d = vs.coords.distort(cs1, 0, 0, 0.1, 0.1, 10, 0.5)
vs.matcher.add(cs1_d, "1_d")
- if 1:
+ if self.distort:
cs1 = cs1_d
#vs.map.put(self.mask, cs2)
@@ -102,11 +120,9 @@
vs.map.put(self.mask, cs1)
if self.mode & 1:
- putnoc(vs, self.black);
vs.map.put(self.irreguframe.frame, cs1, cs2)
if self.mode & 2:
- putnoc(vs, self.white);
vs.map.put(self.irreguframe.content, cs1, cs2)
currentScene = IrreguScene()
Index: gzz/gfx/librenderables/renderables.py
diff -u gzz/gfx/librenderables/renderables.py:1.127
gzz/gfx/librenderables/renderables.py:1.128
--- gzz/gfx/librenderables/renderables.py:1.127 Mon Nov 4 03:29:35 2002
+++ gzz/gfx/librenderables/renderables.py Mon Nov 4 05:38:55 2002
@@ -1140,7 +1140,8 @@
"RenderCode" : """
DBG(dbg) << "IrregularEllipse\\n";
- int n = 20;
+ // XXX: TODO: use coords1.nonlinearity()
+ int n = (int)(36 * dicefactor);
std::vector<ZPt> vert(n+1);
std::vector<ZVec> norm(n+1);
@@ -1182,6 +1183,20 @@
coords1.vertex(p - norm);
glSecondaryColor3fEXT(0,0,0);
coords1.vertex(p + norm);
+ }
+ glEnd();
+
+ glDisable(GL_TEXTURE_2D);
+ glDisable(GL_REGISTER_COMBINERS_NV);
+ float col[4];
+ glGetFloatv(GL_CONSTANT_COLOR0_NV, col);
+ glColor4fv(col);
+ glBegin(GL_POLYGON);
+ for (int i = 0; i <= n; i++) {
+ ZPt p = vert[i];
+ ZVec norm = (vert[(i+1) % n] - vert[(i+n-1) %
n]).cw90().normalize();
+ norm *= 0.5 * ripple_scale * texscale;
+ coords1.vertex(p - norm);
}
glEnd();
Index: gzz/gfx/libutil/effects.py
diff -u gzz/gfx/libutil/effects.py:1.23 gzz/gfx/libutil/effects.py:1.24
--- gzz/gfx/libutil/effects.py:1.23 Mon Nov 4 02:53:15 2002
+++ gzz/gfx/libutil/effects.py Mon Nov 4 05:38:55 2002
@@ -4,7 +4,8 @@
import gzz
import java
import math
-
+from gfx.libutil.nvcode import combinercode
+from gfx.libpaper.texcache import getCachedTexture
class IrreguFrame(IrregularFrame):
dicefactor = 0.8
@@ -17,13 +18,24 @@
# "scale", "0.2", "freq", "1", "df", "2",
# "scale2", "0.05", "freq2", "12", "df2", "1.5"])
+ ripple_scale = 0.25
+ tex2 = getCachedTexture([256, 256, 0, 4, "RGBA", "RGBA",
+ "irregu", ["radius", "2",
+ "ripple_scale", str(ripple_scale),
+ "angle", "0",
+ "angles", "3",
+ "eps", ".125",
+ "scaling", "const"]],
+ shade_all_levels = 1)
+
boxtex = GL.createTexture()
combiners = "Enable"
def __init__(self, x0, y0, x1, y1, border, ripple,
contentColor=java.awt.Color.white,
- frameColor=java.awt.Color.black):
+ frameColor=java.awt.Color.black,
+ type = "square"):
print "Texture id:", self.tex.getTexId()
def code(color):
@@ -73,13 +85,71 @@
"comb" : self.combiners,
"color" : gzz.util.ColorUtil.colorGLString(color)}
+ def code2(color):
+ return combinercode("""
+ PushAttrib ENABLE_BIT TEXTURE_BIT
+
+ CombinerParameterNV CONSTANT_COLOR0_NV %(color)s 1
+
+ Enable REGISTER_COMBINERS_NV
+ CombinerParameterNV NUM_GENERAL_COMBINERS_NV 2
+
+ # SPARE0 <- TEXTURE0 . COLOR
+ CI0 RGB A TEXTURE0 UNSIGNED_IDENTITY_NV RGB
+ CI0 RGB B PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
+ CO0 RGB SPARE0_NV DISCARD_NV DISCARD_NV NONE NONE TRUE FALSE
FALSE
+
+ # SPARE0.alpha <- TEXTURE0.alpha * COLOR.alpha + SEC_COLOR.b
+ CI0 ALPHA A TEXTURE0 UNSIGNED_IDENTITY_NV ALPHA
+ CI0 ALPHA B PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV ALPHA
+ CI0 ALPHA C SECONDARY_COLOR_NV UNSIGNED_IDENTITY_NV BLUE
+ CI0 ALPHA D ZERO UNSIGNED_INVERT_NV ALPHA
+ CO0 ALPHA DISCARD_NV DISCARD_NV SPARE0_NV NONE NONE FALSE
FALSE FALSE
+
+ # SPARE0.alpha <- SPARE0 + SPARE0.alpha
+ CI1 ALPHA A SPARE0_NV UNSIGNED_IDENTITY_NV BLUE
+ CI1 ALPHA B ZERO UNSIGNED_INVERT_NV ALPHA
+ CI1 ALPHA C SPARE0_NV UNSIGNED_IDENTITY_NV ALPHA
+ CI1 ALPHA D ZERO UNSIGNED_INVERT_NV ALPHA
+ CO1 ALPHA DISCARD_NV DISCARD_NV SPARE0_NV NONE NONE FALSE
FALSE FALSE
+
+ # color <- CONTANT_COLOR0
+ # alpha <- SPARE0.alpha
+ FCI A ZERO UNSIGNED_IDENTITY_NV RGB
+ FCI B ZERO UNSIGNED_IDENTITY_NV RGB
+ FCI C ZERO UNSIGNED_IDENTITY_NV RGB
+ FCI D CONSTANT_COLOR0_NV UNSIGNED_IDENTITY_NV RGB
+ FCI G SPARE0_NV UNSIGNED_IDENTITY_NV ALPHA
+
+ BindTexture TEXTURE_2D %(tex)s
+ TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR
+ TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR
+ Enable TEXTURE_2D
- self._content = GLRen.createIrregularQuad(
+ Enable ALPHA_TEST
+ AlphaFunc GEQUAL 1.0
+ """) % {"tex" : self.tex2.getTexId(),
+ "color" : gzz.util.ColorUtil.colorGLString(color)}
+
+ if type == "square":
+ self._content = GLRen.createIrregularQuad(
x0, y0, x1, y1, border, ripple, 0,
code(contentColor), self.dicefactor)
- self._frame = GLRen.createIrregularQuad(
+ self._frame = GLRen.createIrregularQuad(
x0, y0, x1, y1, border, ripple, 1,
code(frameColor), self.dicefactor)
+ elif type == "ellipse":
+ texscale = ripple
+ ripple_scale = border / ripple
+
+ ratio = float(ripple_scale) / self.ripple_scale
+ if ratio < 3./4 or ratio > 4./3:
+ print "WARNING: anisotropy ratio", round(ratio,2), "is far
from one"
+
+ self._content = GLRen.createIrregularEllipse(
+ texscale, ripple_scale, 0, code2(contentColor), 1)
+ self._frame = GLRen.createIrregularEllipse(
+ texscale, ripple_scale, 1, code2(frameColor), 1)
def getContent(self): return self._content
def getFrame(self): return self._frame
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] gzz/gfx demo/irregular2.py libutil/effects.py l...,
Janne V. Kujala <=