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: Tue, 17 Sep 2002 09:13:38 -0400

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Janne V. Kujala <address@hidden>        02/09/17 09:13:38

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

Log message:
        Add border to IrregularQuad; the inside of the rectangle needs to be 
drawn for the border, too, because otherwise there will be no border when the 
paper ends at the middle of cs1

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/irregular2.py.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/librenderables/renderables.py.diff?tr1=1.39&tr2=1.40&r1=text&r2=text

Patches:
Index: gzz/gfx/demo/irregular2.py
diff -c gzz/gfx/demo/irregular2.py:1.7 gzz/gfx/demo/irregular2.py:1.8
*** gzz/gfx/demo/irregular2.py:1.7      Tue Sep 17 07:14:05 2002
--- gzz/gfx/demo/irregular2.py  Tue Sep 17 09:13:38 2002
***************
*** 13,25 ****
      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):
!         w = 2
  
          # Setup texgen for TEXTURE1 so that [-w,w]x[-1,1] in cs2 is mapped
          # into [.25,75]^2 (center box of a 4x4 texture)
--- 13,28 ----
      def __init__(self):
          print "Texture id:", tex.getTexId()
  
+         self.mode = 255
          self.combiners = "Enable"
          self.initirregu()
          self.x1, self.y1 = 600, 450
  
      def initirregu(self):
!         w = 1
! 
!         self.white = getDListNocoords("Color 1 1 1")
!         self.black = getDListNocoords("Color 0 0 0")
  
          # Setup texgen for TEXTURE1 so that [-w,w]x[-1,1] in cs2 is mapped
          # into [.25,75]^2 (center box of a 4x4 texture)
***************
*** 41,47 ****
              End
          """ % locals())
  
!       self.iq = GZZGL.createIrregularQuad(.2, """
                  PushAttrib ENABLE_BIT TEXTURE_BIT CURRENT_BIT
                  Enable ALPHA_TEST
                  AlphaFunc GREATER 0.0
--- 44,50 ----
              End
          """ % locals())
  
!         code = """
                  PushAttrib ENABLE_BIT TEXTURE_BIT CURRENT_BIT
                  Enable ALPHA_TEST
                  AlphaFunc GREATER 0.0
***************
*** 52,62 ****
                  TexImage2D TEXTURE_2D 0 ALPHA 4 4 0 ALPHA 0 0 0 0 0 1 1 0 0 1 
1 0 0 0 0 0
                  TexParameter TEXTURE_2D TEXTURE_BASE_LEVEL 0
                  TexParameter TEXTURE_2D TEXTURE_MAX_LEVEL 0
!               TexParameter TEXTURE_2D TEXTURE_WRAP_S CLAMP
!               TexParameter TEXTURE_2D TEXTURE_WRAP_T CLAMP
                TexParameter TEXTURE_2D TEXTURE_MIN_FILTER NEAREST
                TexParameter TEXTURE_2D TEXTURE_MAG_FILTER NEAREST
  
                  ActiveTexture TEXTURE0
                  
                  BindTexture TEXTURE_2D %s
--- 55,70 ----
                  TexImage2D TEXTURE_2D 0 ALPHA 4 4 0 ALPHA 0 0 0 0 0 1 1 0 0 1 
1 0 0 0 0 0
                  TexParameter TEXTURE_2D TEXTURE_BASE_LEVEL 0
                  TexParameter TEXTURE_2D TEXTURE_MAX_LEVEL 0
!               #TexParameter TEXTURE_2D TEXTURE_WRAP_S CLAMP
!               #TexParameter TEXTURE_2D TEXTURE_WRAP_T CLAMP
                TexParameter TEXTURE_2D TEXTURE_MIN_FILTER NEAREST
                TexParameter TEXTURE_2D TEXTURE_MAG_FILTER NEAREST
  
+                 TexGen S TEXTURE_GEN_MODE OBJECT_LINEAR
+                 Enable TEXTURE_GEN_S
+                 TexGen T TEXTURE_GEN_MODE OBJECT_LINEAR
+                 Enable TEXTURE_GEN_T
+ 
                  ActiveTexture TEXTURE0
                  
                  BindTexture TEXTURE_2D %s
***************
*** 74,80 ****
                  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
!                 """ % (boxtex.getTexId(), tex.getTexId(), self.combiners))
  
      def key(self, k):
          if 0: pass
--- 82,92 ----
                  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
!         """ % (boxtex.getTexId(), tex.getTexId(), self.combiners)
! 
! 
!       self.iq = GZZGL.createIrregularQuad(.2, 0, code)
!       self.iq2 = GZZGL.createIrregularQuad(.2, 1, code)
  
      def key(self, k):
          if 0: pass
***************
*** 88,93 ****
--- 100,108 ----
              else:
                  self.combiners = "Enable"
              self.initirregu()
+         elif k >= "1" and k <= "9":
+             self.mode ^= 1 << (int(k)-1)
+             print "mode=", self.mode
        pass
      
      def scene(self, vs):
***************
*** 97,102 ****
          cs1 = vs.coords.affineCoordsys(0, "1", 10, self.x1, self.y1, 200, 0, 
0, 100)
          cs2 = vs.coords.affineCoordsys(0, "2", 10, 600, 450, 150, 32.3, 
-14.2, 150)
          vs.map.put(self.mask, cs2)
!         vs.map.put(self.iq, cs1, cs2)
  
  currentScene = IrreguScene()
--- 112,124 ----
          cs1 = vs.coords.affineCoordsys(0, "1", 10, self.x1, self.y1, 200, 0, 
0, 100)
          cs2 = vs.coords.affineCoordsys(0, "2", 10, 600, 450, 150, 32.3, 
-14.2, 150)
          vs.map.put(self.mask, cs2)
! 
!         if self.mode & 1:
!             putnoc(vs, self.black);
!             vs.map.put(self.iq2, cs1, cs2)
! 
!         if self.mode & 2:
!             putnoc(vs, self.white);
!             vs.map.put(self.iq, cs1, cs2)
  
  currentScene = IrreguScene()
Index: gzz/gfx/librenderables/renderables.py
diff -c gzz/gfx/librenderables/renderables.py:1.39 
gzz/gfx/librenderables/renderables.py:1.40
*** gzz/gfx/librenderables/renderables.py:1.39  Tue Sep 17 07:14:05 2002
--- gzz/gfx/librenderables/renderables.py       Tue Sep 17 09:13:38 2002
***************
*** 656,667 ****
  {
      "Type" : "2",
      "Name": "IrregularQuad",
!     "Data": "float border; CallGLCode setup;",
      "Params" : """
!           float border, String setupcode
        """,
      "ParamCode" : """
              this->border = border;
              setup = CallGLCode(string(setupcode.begin(), 
setupcode.end()).c_str());
        """,
      "ExtraClass" : """
--- 656,668 ----
  {
      "Type" : "2",
      "Name": "IrregularQuad",
!     "Data": "float border; int mode; CallGLCode setup;",
      "Params" : """
!           float border, int mode, String setupcode
        """,
      "ParamCode" : """
              this->border = border;
+             this->mode = mode;
              setup = CallGLCode(string(setupcode.begin(), 
setupcode.end()).c_str());
        """,
      "ExtraClass" : """
***************
*** 679,687 ****
          AffineCoords cs1inv = coords1.getInverse();
          AffineCoords cs2inv = coords2.getInverse();
  
          // Normalize unit vectors inside coords2 to get border widths
!         float bx = border * 
cs1inv.transform(coords2.transform(cs2inv.transform(coords1.transform(Vec(1,0))).normalize())).length();
!         float by = border * 
cs1inv.transform(coords2.transform(cs2inv.transform(coords1.transform(Vec(0,1))).normalize())).length();
  
          const float x0 = 1;
          const float x1 = 1 - bx;
--- 680,693 ----
          AffineCoords cs1inv = coords1.getInverse();
          AffineCoords cs2inv = coords2.getInverse();
  
+         Vec xvec = coords1.transform(Vec(1,0));
+         Vec yvec = coords1.transform(Vec(0,1));
+ 
          // Normalize unit vectors inside coords2 to get border widths
!         float bx = border * 
cs1inv.transform(coords2.transform(cs2inv.transform(xvec).normalize())).length();
!         float by = border * 
cs1inv.transform(coords2.transform(cs2inv.transform(yvec).normalize())).length();
!         Vec xpix = xvec.normalize()*2;
!         Vec ypix = yvec.normalize()*2;
  
          const float x0 = 1;
          const float x1 = 1 - bx;
***************
*** 706,761 ****
                             { Pt(-x2, -y0), Pt(-x0, -y2), Pt(-x1, -y2), 
Pt(-x2, -y1) }
                             };
  
          /* 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 (unsigned i = 0; i < sizeof(sides)/sizeof(sides[0]); i++) {
              ZPt tex0 = cs2inv.transform(coords1.transform(lerp(texf, 
sides[i][3], sides[i][0])));
              ZPt tex1 = cs2inv.transform(coords1.transform(lerp(texf, 
sides[i][2], sides[i][1])));
  
!             glSecondaryColor3fEXT(0, 0, 0);
! 
!             glTexCoord2f(tex0.x, tex0.y);
!             coords1.vertex(sides[i][0]);
! 
!             glTexCoord2f(tex1.x, tex1.y);
!             coords1.vertex(sides[i][1]);
! 
!             glSecondaryColor3fEXT(1, 1, 1);
! 
!             float w = wtbl[i];
! 
!             glTexCoord4f(tex1.x * w, tex1.y * w, 0, w);
!             coords1.vertex(sides[i][2]);
! 
!             glTexCoord4f(tex0.x * w, tex0.y * w, 0, w);
!             coords1.vertex(sides[i][3]);
  
          }
!         glEnd();
! 
          glDisable(GL_REGISTER_COMBINERS_NV);
          glDisable(GL_TEXTURE_2D);
!         glBegin(GL_QUADS);
!         coords1.vertex(Pt(-x2,-y1));
!         coords1.vertex(Pt(+x2,-y1));
!         coords1.vertex(Pt(+x2,+y1));
!         coords1.vertex(Pt(-x2,+y1));
! 
!         coords1.vertex(Pt(-x1,-y2));
!         coords1.vertex(Pt(-x1,+y2));
!         coords1.vertex(Pt(-x2,+y1));
!         coords1.vertex(Pt(-x2,-y1));
! 
!         coords1.vertex(Pt(+x1,-y2));
!         coords1.vertex(Pt(+x1,+y2));
!         coords1.vertex(Pt(+x2,+y1));
!         coords1.vertex(Pt(+x2,-y1));
!         glEnd();
!         GLERR;
  
          glPopAttrib();
      """,
--- 712,806 ----
                             { Pt(-x2, -y0), Pt(-x0, -y2), Pt(-x1, -y2), 
Pt(-x2, -y1) }
                             };
  
+         float m = 1 / sqrt(2);
+         Vec trans[][3] = { { -xpix, -ypix,  ypix },
+                            {  xpix, -ypix,  ypix },
+                            { -ypix, -xpix,  xpix },
+                            {  ypix, -xpix,  xpix },
+                            { m * ( xpix + ypix), m * ( xpix - ypix), m * 
(-xpix + ypix) },
+                            { m * ( xpix - ypix), m * ( xpix + ypix), m * 
(-xpix - ypix) },
+                            { m * (-xpix + ypix), m * (-xpix - ypix), m * ( 
xpix + ypix) },
+                            { m * (-xpix - ypix), m * (-xpix + ypix), m * ( 
xpix - ypix) } };
+         
+ 
          /* 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;
  
!         glActiveTexture(GL_TEXTURE1);
!         float svec[4] = { cs2inv.x.x*.25, cs2inv.y.x*.25, 0, 
cs2inv.center.x*.25+.5 };
!         float tvec[4] = { cs2inv.x.y*.25, cs2inv.y.y*.25, 0, 
cs2inv.center.y*.25+.5 };
!         glTexGenfv(GL_S, GL_OBJECT_PLANE, svec);
!         glTexGenfv(GL_T, GL_OBJECT_PLANE, tvec);
!         glActiveTexture(GL_TEXTURE0);
! 
          for (unsigned i = 0; i < sizeof(sides)/sizeof(sides[0]); i++) {
              ZPt tex0 = cs2inv.transform(coords1.transform(lerp(texf, 
sides[i][3], sides[i][0])));
              ZPt tex1 = cs2inv.transform(coords1.transform(lerp(texf, 
sides[i][2], sides[i][1])));
  
!             for (int t = 0; t < (mode ? 3 : 1); t++) {
!                 if (mode) {
!                     glPushMatrix();
!                     glTranslatef(trans[i][t].x, trans[i][t].y, 0);
!                 }
!             
!                 glBegin(GL_QUADS);
!                 glSecondaryColor3fEXT(0, 0, 0);
! 
!                 glTexCoord2f(tex0.x, tex0.y);
!                 coords1.vertex(sides[i][0]);
! 
!                 glTexCoord2f(tex1.x, tex1.y);
!                 coords1.vertex(sides[i][1]);
! 
!                 glSecondaryColor3fEXT(1, 1, 1);
! 
!                 float w = wtbl[i];
! 
!                 glTexCoord4f(tex1.x * w, tex1.y * w, 0, w);
!                 coords1.vertex(sides[i][2]);
!                 
!                 glTexCoord4f(tex0.x * w, tex0.y * w, 0, w);
!                 coords1.vertex(sides[i][3]);
!                 
!                 glEnd();
!                 GLERR;
  
+                 if (mode) glPopMatrix();
+             }
          }
!         
          glDisable(GL_REGISTER_COMBINERS_NV);
          glDisable(GL_TEXTURE_2D);
! 
!         for (int t = 0; t < (mode ? 4 : 1); t++) {
!             if (mode) {
!                 glPushMatrix();
!                 Vec trans = ((t & 1) ? xpix : -xpix) + ((t & 2) ? ypix : 
-ypix);
!                 glTranslatef(trans.x, trans.y, 0);
!             }
!             
!             glBegin(GL_QUADS);
!             coords1.vertex(Pt(-x2,-y1));
!             coords1.vertex(Pt(+x2,-y1));
!             coords1.vertex(Pt(+x2,+y1));
!             coords1.vertex(Pt(-x2,+y1));
!             
!             coords1.vertex(Pt(-x1,-y2));
!             coords1.vertex(Pt(-x1,+y2));
!             coords1.vertex(Pt(-x2,+y1));
!             coords1.vertex(Pt(-x2,-y1));
!             
!             coords1.vertex(Pt(+x1,-y2));
!             coords1.vertex(Pt(+x1,+y2));
!             coords1.vertex(Pt(+x2,+y1));
!             coords1.vertex(Pt(+x2,-y1));
!             glEnd();
!             GLERR;
! 
!             if (mode) glPopMatrix();
!         }
  
          glPopAttrib();
      """,




reply via email to

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