/[gzz]/gzz/gfx/demo/paperbasis.py
ViewVC logotype

Diff of /gzz/gfx/demo/paperbasis.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by jvk, Mon Sep 16 09:19:39 2002 UTC revision 1.9 by jvk, Mon Sep 16 10:18:48 2002 UTC
# Line 2  from __future__ import nested_scopes Line 2  from __future__ import nested_scopes
2    
3  from gfx.libutil import nvcode  from gfx.libutil import nvcode
4    
5  execfile("gfx/libpaper/papermill.py")  from gzz.gfx.gl import GZZGL,Paper,PaperMill
6    
7    import java
8    from java.lang import Math
9    
10    execfile("gfx/libcolor/spaces.py")
11    execfile("gfx/libpaper/textures.py")
12    execfile("gfx/libpaper/texcoords.py")
13    execfile("gfx/libpaper/colors.py")
14    
15  passmask = [ 1, 0, 0, 0 ]  passmask = [ 1, 0, 0, 0 ]
16    
# Line 71  tex1codes = { Line 79  tex1codes = {
79      """),      """),
80      }      }
81  isectcodes = {  isectcodes = {
82      "ALL" : "",      "BAND" : nvcode.combinercode("""
83                    # Band-like texture
84                    CombinerParameterNV NUM_GENERAL_COMBINERS_NV 2
85                    
86                    # SPARE0 <- (TEX0 . TEX1)
87                    CI0 RGB A TEXTURE0 EXPAND_NORMAL_NV RGB
88                    CI0 RGB B TEXTURE1 EXPAND_NORMAL_NV RGB
89                    CO0 RGB SPARE0_NV DISCARD_NV DISCARD_NV NONE NONE TRUE FALSE FALSE
90    
91                    # SPARE1 <- SPARE0 * SPARE0 * 2
92                    # SPARE0 <- (TEX0 . CONST0) * 2
93                    CI1 RGB A SPARE0_NV SIGNED_IDENTITY_NV RGB
94                    CI1 RGB B SPARE0_NV SIGNED_IDENTITY_NV RGB
95                    CI1 RGB C TEXTURE0 EXPAND_NORMAL_NV RGB
96                    CI1 RGB D CONSTANT_COLOR0_NV EXPAND_NORMAL_NV RGB
97                    CO1 RGB SPARE1_NV SPARE0_NV DISCARD_NV SCALE_BY_TWO_NV NONE FALSE TRUE FALSE
98    
99                    # EF <- SPARE0 * SPARE1
100                    FCI E SPARE1_NV UNSIGNED_INVERT_NV RGB
101                    FCI F SPARE0_NV UNSIGNED_IDENTITY_NV RGB
102    
103                    # lerp(EF, PRI_COL, SEC_COL)
104                    FCI A E_TIMES_F_NV UNSIGNED_IDENTITY_NV RGB
105                    FCI B PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
106                    FCI C SECONDARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
107                    FCI D ZERO UNSIGNED_IDENTITY_NV RGB
108    
109                    FCI G ZERO UNSIGNED_INVERT_NV BLUE
110        """),
111        "I3COL" : nvcode.combinercode("""
112                    # Interpolate between three colors using two dot products
113                    CombinerParameterNV NUM_GENERAL_COMBINERS_NV 2
114                
115                    # SPARE0 <- (TEX0 . CONST0)
116                    # SPARE1 <- (TEX1 . CONST1)
117                    CI0 RGB A TEXTURE0 EXPAND_NORMAL_NV RGB
118                    CI0 RGB B CONSTANT_COLOR0_NV EXPAND_NORMAL_NV RGB
119                    CI0 RGB C TEXTURE1 EXPAND_NORMAL_NV RGB
120                    CI0 RGB D CONSTANT_COLOR1_NV EXPAND_NORMAL_NV RGB
121                    CO0 RGB SPARE0_NV SPARE1_NV DISCARD_NV NONE NONE TRUE TRUE FALSE
122    
123                    # PRI_COL <- lerp(SPARE0, PRI_COL, SEC_COL)
124                    CI1 RGB A PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
125                    CI1 RGB B SPARE0_NV UNSIGNED_IDENTITY_NV RGB
126                    CI1 RGB C SECONDARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
127                    CI1 RGB D SPARE0_NV UNSIGNED_INVERT_NV RGB
128                    CO1 RGB DISCARD_NV DISCARD_NV PRIMARY_COLOR_NV NONE NONE FALSE FALSE FALSE
129    
130                    # SPARE1.alpha <- SPARE0^2 - SPARE1^2
131                    CI1 ALPHA A SPARE0_NV SIGNED_IDENTITY_NV BLUE
132                    CI1 ALPHA B SPARE0_NV SIGNED_IDENTITY_NV BLUE
133                    CI1 ALPHA C SPARE1_NV SIGNED_NEGATE_NV BLUE
134                    CI1 ALPHA D SPARE1_NV SIGNED_IDENTITY_NV BLUE
135                    CO1 ALPHA DISCARD_NV DISCARD_NV SPARE1_NV NONE NONE FALSE FALSE FALSE
136    
137                    # lerp(SPARE1, PRI_COL, FOG)
138                    FCI A SPARE1_NV UNSIGNED_IDENTITY_NV RGB
139                    FCI B PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
140                    FCI C FOG UNSIGNED_IDENTITY_NV RGB
141                    FCI D ZERO UNSIGNED_IDENTITY_NV RGB
142    
143                    FCI G ZERO UNSIGNED_INVERT_NV ALPHA
144        """),
145      "DOT" : nvcode.combinercode("""      "DOT" : nvcode.combinercode("""
146      CombinerParameterNV NUM_GENERAL_COMBINERS_NV 1      CombinerParameterNV NUM_GENERAL_COMBINERS_NV 1
147            
# Line 90  isectcodes = { Line 160  isectcodes = {
160    
161  tex0comb = "RGB"  tex0comb = "RGB"
162  tex1comb = "RGB"  tex1comb = "RGB"
163  isectcomb = "ALL"  isectcomb = "I3COL"
164    
165  def getpaper(seed, vecseed0 = 0, vecseed1 = 0, colseed = 0):  def getpaper(vecs, cols):
166      pap = ThePaperMill().getPaper(seed, passmask=passmask)      pap = Paper()
167        pap.setNPasses(1)
168        ppass = pap.getPass(0)
169        ppass.setSetupcode("""
170                PushAttrib ENABLE_BIT TEXTURE_BIT DEPTH_BUFFER_BIT
171        """)
172        ppass.setTeardowncode("""
173                PopAttrib
174                ActiveTexture TEXTURE0
175        """)
176    
177      constcode = ""      texid = ptextures["RGB2"][0].getTexId();
178      if colseed:      
179          colors = Colors(colseed)      constcode = """
180          c0,c1,c2,c3 = [ colors.getColorStr(i) for i in range(0,4) ]          ActiveTexture TEXTURE0
181          constcode += """          Enable TEXTURE_2D
182            BindTexture TEXTURE_2D %(texid)s
183            TexParameter TEXTURE_2D TEXTURE_WRAP_S REPEAT
184            TexParameter TEXTURE_2D TEXTURE_WRAP_T REPEAT
185            TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR
186            TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR
187            
188            ActiveTexture TEXTURE1
189            Enable TEXTURE_2D
190            BindTexture TEXTURE_2D %(texid)s
191            TexParameter TEXTURE_2D TEXTURE_WRAP_S REPEAT
192            TexParameter TEXTURE_2D TEXTURE_WRAP_T REPEAT
193            TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR
194            TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR
195            
196            Enable BLEND
197            BlendFunc SRC_ALPHA ONE_MINUS_SRC_ALPHA
198            BlendEquation FUNC_ADD
199            Disable ALPHA_TEST
200    
201            Enable REGISTER_COMBINERS_NV
202        """ % locals()
203    
204        r0,r1 = vecs
205        c0,c1,c2,c3 = cols
206        constcode += """
207          Color %(c0)s          Color %(c0)s
208          SecondaryColorEXT %(c1)s          SecondaryColorEXT %(c1)s
209          Fog FOG_COLOR %(c2)s          Fog FOG_COLOR %(c2)s
210          """ % locals()          CombinerParameterNV CONSTANT_COLOR0_NV %(r0)s
211      if vecseed0:          CombinerParameterNV CONSTANT_COLOR1_NV %(r1)s
212          colors = Colors(vecseed0)      """ % locals()
         constcode += ("CombinerParameterNV CONSTANT_COLOR0_NV %s\n"  
                       % (colors.getNVDP3VecStr(0)))  
     if vecseed1:  
         colors = Colors(vecseed1)  
         constcode += ("CombinerParameterNV CONSTANT_COLOR1_NV %s\n"  
                       % (colors.getNVDP3VecStr(1)))  
     print seed, vecseed0, vecseed1, colseed  
     print constcode  
213    
214      return GZZGL.createBasisPaperQuad(pap, -1, -1, 1, 1,      return GZZGL.createBasisPaperQuad(pap, -1, -1, 1, 1,
215                                        tex0codes[tex0comb] + constcode,                                        constcode + tex0codes[tex0comb],
216                                        tex1codes[tex1comb] + constcode,                                        constcode + tex1codes[tex1comb],
217                                        isectcodes[isectcomb] + constcode)                                        constcode + isectcodes[isectcomb])
218    
219  rng = java.util.Random()  rng = java.util.Random()
220    
# Line 127  class PaperScene: Line 223  class PaperScene:
223      def __init__(self):      def __init__(self):
224          self.bgcolor = (0.7, 0.8, 0.6)          self.bgcolor = (0.7, 0.8, 0.6)
225    
         self.seed = 0  
226          self.vecseed0 = 0          self.vecseed0 = 0
227          self.vecseed1 = 0          self.vecseed1 = 0
228          self.colseed = 0          self.colseed = 0
229    
230            self.initvecs()
231            self.initcols()
232          self.initpaper()          self.initpaper()
233    
234          self.x0, self.y0 = 600, 300          self.x0, self.y0 = 600, 450
235          self.x1, self.y1 = 600, 450          self.x1, self.y1 = 600, 600
236          self.texgen0 = TexGenXYRepeatUnit(vecs = [[.5,0], [0,.5]])          self.texgen0 = TexGenXYRepeatUnit(vecs = [[.5,0], [0,.5]])
237          self.texgen1 = TexGenXYRepeatUnit(vecs = [[.25,.25], [.25,-.25]])          self.texgen1 = TexGenXYRepeatUnit(vecs = [[.25,.25], [.25,-.25]])
238    
# Line 150  class PaperScene: Line 248  class PaperScene:
248          End          End
249          """)          """)
250    
251      def initpaper(self):      def initvecs(self):
252          self.pq = getpaper(self.seed, self.vecseed0, self.vecseed1, self.colseed)          colors = Colors(self.vecseed0)
253            r0 = colors.getNVDP3VecStr(0)
254            colors = Colors(self.vecseed1)
255            r1 = colors.getNVDP3VecStr(1)
256            self.vecs = [ r0, r1 ]
257    
258        def initcols(self):
259            rnd = java.util.Random(self.colseed)
260            colors = Colors(rnd.nextInt())
261            colorbase = rnd.nextInt()
262            self.cols = [ colors.getColorStr(colorbase+i)
263                          for i in range(0,4) ]
264    
265        def initpaper(self):        
266            self.pq = getpaper(self.vecs, self.cols)
267          AbstractUpdateManager.setNoAnimation()          AbstractUpdateManager.setNoAnimation()
268    
269      def key(self, k):      def key(self, k):
270          global tex0comb,tex1comb,isectcomb          global tex0comb,tex1comb,isectcomb
         oldseed = self.seed  
271          if k == "v":          if k == "v":
272              self.seed = rng.nextInt(2000000000)              self.vecseed0 = rng.nextInt(2000000000)
273              self.vecseed0 = 0              self.vecseed1 = rng.nextInt(2000000000)
274              self.vecseed1 = 0              self.colseed = rng.nextInt(2000000000)
275              self.colseed = 0              self.initvecs()
276                self.initcols()
277              self.initpaper()              self.initpaper()
278          elif k == "1":          elif k == "1":
279              self.vecseed0 = rng.nextInt(2000000000)              self.vecseed0 = rng.nextInt(2000000000)
280                self.initvecs()
281              self.initpaper()              self.initpaper()
282          elif k == "3":          elif k == "3":
283              self.vecseed1 = rng.nextInt(2000000000)              self.vecseed1 = rng.nextInt(2000000000)
284                self.initvecs()
285              self.initpaper()              self.initpaper()
286          elif k == "2":          elif k == "2":
287              self.colseed = rng.nextInt(2000000000)              self.colseed = rng.nextInt(2000000000)
288                self.initcols()
289              self.initpaper()              self.initpaper()
290          elif k == "F4":          elif k == "F4":
291              self.texgen0 = TexGenXYRepeatUnit(rnd=rng)              self.texgen0 = TexGenXYRepeatUnit(rnd=rng)
# Line 183  class PaperScene: Line 298  class PaperScene:
298          elif k == "F1":          elif k == "F1":
299              list = tex0codes.keys()              list = tex0codes.keys()
300              tex0comb = list[(list.index(tex0comb) + 1) % len(list)]              tex0comb = list[(list.index(tex0comb) + 1) % len(list)]
301              print "Using", tex0comb, tex1comb, isectcomb, "combiners"              print "Using", tex0comb, isectcomb, tex1comb, "combiners"
302              self.initpaper()              self.initpaper()
303          elif k == "F3":          elif k == "F3":
304              list = tex1codes.keys()              list = tex1codes.keys()
305              tex1comb = list[(list.index(tex1comb) + 1) % len(list)]              tex1comb = list[(list.index(tex1comb) + 1) % len(list)]
306              print "Using", tex0comb, tex1comb, isectcomb, "combiners"              print "Using", tex0comb, isectcomb, tex1comb, "combiners"
307              self.initpaper()              self.initpaper()
308          elif k == "F2":          elif k == "F2":
309              list = isectcodes.keys()              list = isectcodes.keys()
310              isectcomb = list[(list.index(isectcomb) + 1) % len(list)]              isectcomb = list[(list.index(isectcomb) + 1) % len(list)]
311              print "Using", tex0comb, tex1comb, isectcomb, "combiners"              print "Using", tex0comb, isectcomb, tex1comb, "combiners"
312              self.initpaper()              self.initpaper()
313                            
314      def scene(self, vs):      def scene(self, vs):
# Line 220  class PaperScene: Line 335  class PaperScene:
335          vs.map.put(self.frame, cs1)          vs.map.put(self.frame, cs1)
336          vs.map.put(self.frame, cs2)          vs.map.put(self.frame, cs2)
337    
338            for i in range(0,3):
339                cs = vs.coords.affineCoordsys(0, "col" + str(i), 10, 600 + (i-1)*150, 80, 50, 0, 0, 50)
340                col = self.cols[i].split()
341                cq = coloredQuad((col[0], col[1], col[2]))
342                vs.map.put(cq, cs)
343                vs.map.put(self.frame, cs)
344    
345  currentScene = PaperScene()          currentScene = PaperScene()        

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26