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

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

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

revision 1.29 by jvk, Tue Oct 29 12:32:59 2002 UTC revision 1.30 by jvk, Tue Oct 29 13:24:14 2002 UTC
# Line 22  if (GL.hasExtension("GL_NV_texture_shade Line 22  if (GL.hasExtension("GL_NV_texture_shade
22    
23  if (GL.hasExtension("GL_NV_register_combiners") and  if (GL.hasExtension("GL_NV_register_combiners") and
24      GL.hasExtension("GL_EXT_secondary_color")):      GL.hasExtension("GL_EXT_secondary_color")):
25      profiles.append("NV_COMB")      profiles.append("NV_COMB_DOT3")
26      profiles.append("NV_COMB4")      profiles.append("NV_COMB_DOT4")
27    
28  if GL.hasExtension("GL_EXT_texture_env_dot3"):  if GL.hasExtension("GL_EXT_texture_env_dot3"):
29      profiles.append("DOT3")      profiles.append("DOT3")
30    
31  profiles.append("STD")  profiles.append("STD")
32    profiles.append("STD_4")
33    
34  def getIrreguTex(components, iformat, format, scale = 1, bias = 0, angles = 0, invert = 0):  def getIrreguTex(components, iformat, format, scale = 1, bias = 0, angle = 0, angles = 0, invert = 0):
35    
36      return getCachedTexture([texsize, texsize, 0, components, iformat, format, "irregu",      return getCachedTexture([texsize, texsize, 0, components, iformat, format, "irregu",
37                               ["radius", "2",                               ["radius", "2",
38                                "ripple_scale", str(ripple_scale),                                "ripple_scale", str(ripple_scale),
39                                "scale", str(scale),                                "scale", str(scale),
40                                "bias", str(bias),                                "bias", str(bias),
41                                  "angle", str(angle),
42                                "angles", str(angles),                                "angles", str(angles),
43                                "eps", ".125",                                "eps", ".125",
44                                "invert", str(invert),                                "invert", str(invert),
# Line 44  def getIrreguTex(components, iformat, fo Line 46  def getIrreguTex(components, iformat, fo
46                              shade_all_levels = 1)                              shade_all_levels = 1)
47    
48  def init(profile):  def init(profile):
49      global tex, texinv      global tex
50      global texenv_inner, texenv_outer, alphalevel, w0, w1      global texenv_inner, texenv_outer, alphalevel, w0, w1
51      global colmap0, colmap1, angles      global colmap0, colmap1, angles
52      global using_shader, using_secondary_color      global using_shader, using_secondary_color
# Line 107  def init(profile): Line 109  def init(profile):
109          tex = ( getIrreguTex(2, "HILO_NV", "HILO_NV"),          tex = ( getIrreguTex(2, "HILO_NV", "HILO_NV"),
110                  )                  )
111    
112      elif profile == "NV_COMB" or profile == "NV_COMB4":      elif profile == "NV_COMB_DOT3" or profile == "NV_COMB_DOT4":
113          print "Using full displacement resolution textures with GL_NV_register_combiners"          print "Using full displacement resolution textures with GL_NV_register_combiners"
114    
115          using_secondary_color = 1          using_secondary_color = 1
# Line 147  def init(profile): Line 149  def init(profile):
149          def colmap0(dotvec): return (1,1,1)          def colmap0(dotvec): return (1,1,1)
150          def colmap1(dotvec): return (0,0,0)          def colmap1(dotvec): return (0,0,0)
151    
152          if profile == "NV_COMB":          if profile == "NV_COMB_DOT3":
153              texenv_inner = texenv % "0 0 0 1"              texenv_inner = texenv % "0 0 0 1"
154              texenv_outer = texenv % "%(dotvec)s 0"              texenv_outer = texenv % "%(dotvec)s 0"
155              angles = 3              angles = 3
# Line 190  def init(profile): Line 192  def init(profile):
192                  getIrreguTex(4, "RGBA", "RGBA", scale = .25, bias = .75, angles = 3, invert = 1),                  getIrreguTex(4, "RGBA", "RGBA", scale = .25, bias = .75, angles = 3, invert = 1),
193                  )                  )
194    
195      elif profile == "STD":      elif profile == "STD" or profile == "STD_4":
196          print "Using full displacement resolution texture with standard GL (texture_env_add)"          print "Using full displacement resolution texture with standard GL (texture_env_add)"
197    
198          texenv = """          texenv = """
# Line 203  def init(profile): Line 205  def init(profile):
205          w0,w1 = 1,1          w0,w1 = 1,1
206          def colmap0(dotvec): return (1,1,1,1)          def colmap0(dotvec): return (1,1,1,1)
207          def colmap1(dotvec): return (0,0,0,0)          def colmap1(dotvec): return (0,0,0,0)
208            
209          angles = 0          angles = 0        
210          tex = ( getIrreguTex(1, "INTENSITY", "LUMINANCE"),          tex = ( getIrreguTex(1, "INTENSITY", "LUMINANCE"),
211                  getIrreguTex(1, "INTENSITY", "LUMINANCE", invert = 1),                  getIrreguTex(1, "INTENSITY", "LUMINANCE", invert = 1),
212                  )                  )
213    
214            if profile == "STD_4":
215                texenv_outer = texenv_outer + "\n"
216                angles = 4
217                for i in range(0, angles):
218                    angle = i * 180. / angles
219                    tex += ( getIrreguTex(1, "INTENSITY", "LUMINANCE", angle = angle, angles = 1),
220                             getIrreguTex(1, "INTENSITY", "LUMINANCE", angle = angle, angles = 1, invert = 1) )
221            
222      else:      else:
223          assert(0)          assert(0)
224    
# Line 218  def init(profile): Line 229  def init(profile):
229      reinit = 1      reinit = 1
230    
231    
232    print "Profiles:"
233    for i in range(0, len(profiles)):
234        print ("F%s:" % (i+1)), profiles[i]
235    
236    
237  init(profiles[0])  init(profiles[0])
238    
239  def globalkey(k):  def globalkey(k):
240      global reinit      global reinit
241            
242      if "F1" <= k <= "F4":      if "F1" <= k <= "F8":
243          global profiles          global profiles
244          init(profiles[int(k[1]) - 1])          init(profiles[int(k[1]) - 1])
245      elif k == "m":      elif k == "m":
# Line 257  def vecadd(u, v): return [ u[i] + v[i] f Line 272  def vecadd(u, v): return [ u[i] + v[i] f
272  def vecsub(u, v): return [ u[i] - v[i] for i in range(0, len(u)) ]  def vecsub(u, v): return [ u[i] - v[i] for i in range(0, len(u)) ]
273    
274  def getIrregu(invert, x0, y0, x1, y1, outer = 0, texscale = 1, texangle = 0):  def getIrregu(invert, x0, y0, x1, y1, outer = 0, texscale = 1, texangle = 0):
   
     if len(tex) == 1:  
         texid = tex[0].getTexId()  
     elif len(tex) == 2:  
         texid = tex[invert].getTexId()  
     elif len(tex) == 4:  
         texid = tex[invert + 2 * outer].getTexId()  
     else:  
         assert(0)  
275            
276      striplen = sqrt((x1 - x0)**2 + (y1 - y0)**2)      striplen = sqrt((x1 - x0)**2 + (y1 - y0)**2)
277    
# Line 287  def getIrregu(invert, x0, y0, x1, y1, ou Line 293  def getIrregu(invert, x0, y0, x1, y1, ou
293    
294      angle = atan2(y1 - y0, x1 - x0) - texangle      angle = atan2(y1 - y0, x1 - x0) - texangle
295    
296        if len(tex) == 1:
297            texid = tex[0].getTexId()
298        elif len(tex) == 2:
299            texid = tex[invert].getTexId()
300        elif len(tex) == 4:
301            texid = tex[invert + 2 * outer].getTexId()
302        elif len(tex) == 2 * (1 + angles):
303            a = angle * (angles / pi)
304            while a < 0: a += angles
305            i0 = int(a + .5) % angles
306            texid = tex[ 2 * outer * (i0 + 1) + invert ].getTexId()
307        else:
308            assert(0)
309    
310      if using_shader:      if using_shader:
311          dx = -cos(angle)          dx = -cos(angle)
312          dy = -sin(angle)          dy = -sin(angle)

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.30

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