gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz/gfx demo/irregular2.py librenderables/rende...


From: Janne V. Kujala
Subject: [Gzz-commits] gzz/gfx demo/irregular2.py librenderables/rende...
Date: Mon, 16 Sep 2002 12:35:16 -0400

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Janne V. Kujala <address@hidden>        02/09/16 12:35:15

Modified files:
        gfx/demo       : irregular2.py 
        gfx/librenderables: renderables.py 

Log message:
        Round the corners of IrregularQuad (by just snapping a triangle off of 
each corner; try "c" in irregu2)

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/irregular2.py.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/librenderables/renderables.py.diff?tr1=1.33&tr2=1.34&r1=text&r2=text

Patches:
Index: gzz/gfx/demo/irregular2.py
diff -c gzz/gfx/demo/irregular2.py:1.2 gzz/gfx/demo/irregular2.py:1.3
*** gzz/gfx/demo/irregular2.py:1.2      Mon Sep 16 10:39:27 2002
--- gzz/gfx/demo/irregular2.py  Mon Sep 16 12:35:15 2002
***************
*** 3,20 ****
  
  tex = GZZGL.createTexture()
  tex.shade(128, 128, 0, 4, "RGBA", "RGBA",
!           "fnoise", ["scale", "0.05", "freq", "4", "df", "4", "bias", "0.5"])
  
  class IrreguScene:
      def __init__(self):
          print "Texture id:", tex.getTexId()
!       self.iq = GZZGL.createIrregularQuad(-1, -1, 1, 1, 1.2, """
                  PushAttrib ENABLE_BIT
                  Enable ALPHA_TEST
!                 AlphaFunc GREATER 0.2
                  BindTexture TEXTURE_2D %s
                  Enable TEXTURE_2D
!                 Enable REGISTER_COMBINERS_NV
                  CombinerParameterNV NUM_GENERAL_COMBINERS_NV 1
                  CombinerInputNV COMBINER0_NV ALPHA VARIABLE_A_NV ZERO 
UNSIGNED_INVERT_NV ALPHA
                  CombinerInputNV COMBINER0_NV ALPHA VARIABLE_B_NV TEXTURE0 
SIGNED_NEGATE_NV ALPHA
--- 3,27 ----
  
  tex = GZZGL.createTexture()
  tex.shade(128, 128, 0, 4, "RGBA", "RGBA",
!           "fnoise", ["scale", "0.05", "freq", "8", "df", "4", "bias", "0.5"])
  
  class IrreguScene:
      def __init__(self):
          print "Texture id:", tex.getTexId()
! 
!         self.combiners = "Enable"
!         self.initirregu()
!         self.x1, self.y1 = 600, 450
!         self.combiners = "Enable"
! 
!     def initirregu(self):
!       self.iq = GZZGL.createIrregularQuad(-1, -1, 1, 1, .5, """
                  PushAttrib ENABLE_BIT
                  Enable ALPHA_TEST
!                 AlphaFunc GREATER 0.0
                  BindTexture TEXTURE_2D %s
                  Enable TEXTURE_2D
!                 %s REGISTER_COMBINERS_NV
                  CombinerParameterNV NUM_GENERAL_COMBINERS_NV 1
                  CombinerInputNV COMBINER0_NV ALPHA VARIABLE_A_NV ZERO 
UNSIGNED_INVERT_NV ALPHA
                  CombinerInputNV COMBINER0_NV ALPHA VARIABLE_B_NV TEXTURE0 
SIGNED_NEGATE_NV ALPHA
***************
*** 26,34 ****
                  FinalCombinerInputNV VARIABLE_C_NV ZERO UNSIGNED_IDENTITY_NV 
RGB
                  FinalCombinerInputNV VARIABLE_D_NV PRIMARY_COLOR_NV 
UNSIGNED_IDENTITY_NV RGB
                  FinalCombinerInputNV VARIABLE_G_NV SPARE0_NV 
UNSIGNED_IDENTITY_NV ALPHA
!                 """ % tex.getTexId())
! 
!         self.x1, self.y1 = 600, 450
  
      def key(self, k):
          if 0: pass
--- 33,39 ----
                  FinalCombinerInputNV VARIABLE_C_NV ZERO UNSIGNED_IDENTITY_NV 
RGB
                  FinalCombinerInputNV VARIABLE_D_NV PRIMARY_COLOR_NV 
UNSIGNED_IDENTITY_NV RGB
                  FinalCombinerInputNV VARIABLE_G_NV SPARE0_NV 
UNSIGNED_IDENTITY_NV ALPHA
!                 """ % (tex.getTexId(), self.combiners))
  
      def key(self, k):
          if 0: pass
***************
*** 36,48 ****
          elif k == "Down": self.y1 += 50
          elif k == "Left": self.x1 -= 50
          elif k == "Right": self.x1 += 50
        pass
      
      def scene(self, vs):
        putnoc(vs, background((0.1,0.4,0.5)))
  
          cs1 = vs.coords.affineCoordsys(0, "1", 10, self.x1, self.y1, 100, 0, 
0, 100)
!         cs2 = vs.coords.affineCoordsys(0, "2", 10, 600, 450, 100, 0, 0, 100)
          vs.map.put(self.iq, cs1, cs2)
  
  currentScene = IrreguScene()
--- 41,59 ----
          elif k == "Down": self.y1 += 50
          elif k == "Left": self.x1 -= 50
          elif k == "Right": self.x1 += 50
+         elif k == "c":
+             if self.combiners == "Enable":
+                 self.combiners = "Disable"
+             else:
+                 self.combiners = "Enable"
+             self.initirregu()
        pass
      
      def scene(self, vs):
        putnoc(vs, background((0.1,0.4,0.5)))
  
          cs1 = vs.coords.affineCoordsys(0, "1", 10, self.x1, self.y1, 100, 0, 
0, 100)
!         cs2 = vs.coords.affineCoordsys(0, "2", 10, 600, 450, 150, 0, 0, 150)
          vs.map.put(self.iq, cs1, cs2)
  
  currentScene = IrreguScene()
Index: gzz/gfx/librenderables/renderables.py
diff -c gzz/gfx/librenderables/renderables.py:1.33 
gzz/gfx/librenderables/renderables.py:1.34
*** gzz/gfx/librenderables/renderables.py:1.33  Mon Sep 16 10:39:27 2002
--- gzz/gfx/librenderables/renderables.py       Mon Sep 16 12:35:15 2002
***************
*** 707,712 ****
--- 707,716 ----
                            inv[2] * v.x + inv[3] * v.y/*,
                            v.z*/);
              }
+             Pt lerp(float f, Pt a, Pt b) {
+                 return Pt((1 - f) * a.x + f * b.x,
+                           (1 - f) * a.y + f * b.y);
+             }
      """,
      "RenderCode" : """
          DBG(dbg) << "Irregular quad\\n";
***************
*** 723,737 ****
          float wy = (y1b - y0b) / (y1 - y0);
  
  
!         Pt sides[4][4] = { { Pt(x0,y0), Pt(x1, y0), Pt(x1b, y0b), Pt(x0b, 
y0b) },
!                            { Pt(x0,y1), Pt(x1, y1), Pt(x1b, y1b), Pt(x0b, 
y1b) },
!                            { Pt(x0,y0), Pt(x0, y1), Pt(x0b, y1b), Pt(x0b, 
y0b) },
!                            { Pt(x1,y0), Pt(x1, y1), Pt(x1b, y1b), Pt(x1b, 
y0b) } };
  
          glBegin(GL_QUADS);
          for (int i = 0; i < 4; i++) {
!             Pt tex0 = invtransform(coords2, coords1.transform(sides[i][0]));
!             Pt tex1 = invtransform(coords2, coords1.transform(sides[i][1]));
  
              glSecondaryColor3fEXT(1, 1, 1);
  
--- 727,746 ----
          float wy = (y1b - y0b) / (y1 - y0);
  
  
!         Pt sides[4][4] = { { Pt(x0,y0), Pt(x1, y0), Pt(x1, y0b), Pt(x0, y0b) 
},
!                            { Pt(x0,y1), Pt(x1, y1), Pt(x1, y1b), Pt(x0, y1b) 
},
!                            { Pt(x0,y0), Pt(x0, y1), Pt(x0b, y1), Pt(x0b, y0) 
},
!                            { Pt(x1,y0), Pt(x1, y1), Pt(x1b, y1), Pt(x1b, y0) 
} };
! 
!         /* The distance (as a fraction of border) from the square where the 
1D texture slice is taken.
!          * Smaller number lowers the frequency of the corner pieces
!          */
!         float texf = 0.5;
  
          glBegin(GL_QUADS);
          for (int i = 0; i < 4; i++) {
!             Pt tex0 = invtransform(coords2, coords1.transform(lerp(texf, 
sides[i][0], sides[i][3])));
!             Pt tex1 = invtransform(coords2, coords1.transform(lerp(texf, 
sides[i][1], sides[i][2])));
  
              glSecondaryColor3fEXT(1, 1, 1);
  
***************
*** 744,749 ****
--- 753,759 ----
              glSecondaryColor3fEXT(0, 0, 0);
  
              float w = (i & 2) ? wy : wx;
+             w = 1;
  
              glTexCoord4f(tex1.x * w, tex1.y * w, 0, w);
              coords1.vertex(sides[i][2]);
***************
*** 756,761 ****
--- 766,801 ----
              //cout << tex1 << w << coords1.transform(sides[i][2]) << "\\n";
              //cout << tex0 << w << coords1.transform(sides[i][3]) << "\\n";
          }
+         glEnd();
+ 
+         Pt corners[4][4] = { { Pt(x0, y0), Pt(x0b, y0), Pt(x0, y0b), Pt(x0b, 
y0b) },
+                              { Pt(x1, y0), Pt(x1b, y0), Pt(x1, y0b), Pt(x1b, 
y0b) },
+                              { Pt(x0, y1), Pt(x0b, y1), Pt(x0, y1b), Pt(x0b, 
y1b) },
+                              { Pt(x1, y1), Pt(x1b, y1), Pt(x1, y1b), Pt(x1b, 
y1b) } };
+ 
+         float w = 1E-4;
+         glBegin(GL_QUADS);
+         for (int i = 0; i < 4; i++) {
+            Pt tex0 = invtransform(coords2, coords1.transform(lerp(texf, 
corners[i][0], corners[i][1])));
+            Pt tex1 = invtransform(coords2, coords1.transform(lerp(texf, 
corners[i][0], corners[i][2])));
+ 
+            glSecondaryColor3fEXT(1, 1, 1);
+ 
+            glTexCoord4f(tex1.x * w, tex1.y * w, 0, w);
+            coords1.vertex(corners[i][0]);
+ 
+            glTexCoord4f(tex0.x * w, tex0.y * w, 0, w);
+            coords1.vertex(corners[i][0]);
+ 
+            glSecondaryColor3fEXT(0, 0, 0);
+ 
+            glTexCoord2f(tex0.x, tex0.y);
+            coords1.vertex(corners[i][1]);
+ 
+            glTexCoord2f(tex1.x, tex1.y);
+            coords1.vertex(corners[i][2]);
+ 
+          }
          glEnd();
          GLERR;
  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]