/[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.21 by jvk, Fri Oct 25 10:39:06 2002 UTC revision 1.22 by jvk, Fri Oct 25 12:53:38 2002 UTC
# Line 13  matrices = [ "1 0 0 0  0 1 0 0  0 0 1 0 Line 13  matrices = [ "1 0 0 0  0 1 0 0  0 0 1 0
13    
14  profiles = []  profiles = []
15    
16    
17    if (GL.hasExtension("GL_NV_texture_shader")):
18        #profiles.append("NV_SHAD")
19        pass
20    
21  if (GL.hasExtension("GL_NV_register_combiners") and  if (GL.hasExtension("GL_NV_register_combiners") and
22      GL.hasExtension("GL_EXT_secondary_color")):      GL.hasExtension("GL_EXT_secondary_color")):
23      profiles.append("NV")      profiles.append("NV_COMB")
24    
25  if GL.hasExtension("GL_EXT_texture_env_dot3"):  if GL.hasExtension("GL_EXT_texture_env_dot3"):
26      profiles.append("DOT3")      profiles.append("DOT3")
# Line 26  def init(profile): Line 31  def init(profile):
31      global tex, texinv      global tex, texinv
32      global texenv_inner, texenv_outer, alphalevel, w0, w1      global texenv_inner, texenv_outer, alphalevel, w0, w1
33      global colmap0, colmap1      global colmap0, colmap1
       
     if profile == "NV":  
34    
35        if profile == "NV_SHAD":
36            print "Using 2-vector HILO displacement texture with GL_NV_texture_shader"
37            texenv_inner = """
38            TexEnv TEXTURE_SHADER_NV PREVIOUS_TEXTURE_INPUT_NV TEXTURE0
39            """
40            
41            alphalevel = 1
42            w0,w1 = 1,1
43            def colmap0(dotvec): return (1,1,1)
44            def colmap1(dotvec): return (0,0,0)
45    
46            tex_scale = 1
47            tex_bias = 0
48            tex_format = [ 2, "HILO", "HILO" ]
49            
50    
51        if profile == "NV_COMB":
52          print "Using full displacement resolution textures with GL_NV_register_combiners"          print "Using full displacement resolution textures with GL_NV_register_combiners"
53            
54          from gfx.libutil.nvcode import combinercode          from gfx.libutil.nvcode import combinercode
# Line 71  def init(profile): Line 91  def init(profile):
91                    
92          alphalevel = 1          alphalevel = 1
93          w0,w1 = 1,1          w0,w1 = 1,1
94          def colmap0(dotvec): return "1 1 1"          def colmap0(dotvec): return (1,1,1)
95          def colmap1(dotvec): return "0 0 0"          def colmap1(dotvec): return (0,0,0)
96    
97          tex_scale = 1          tex_scale = 1
98          tex_bias = 0          tex_bias = 0
# Line 95  def init(profile): Line 115  def init(profile):
115    
116          alphalevel = .5          alphalevel = .5
117          w0,w1 = 1,.5                  w0,w1 = 1,.5        
118          def colmap0(dotvec): return js([.5 + .5 * c for c in dotvec])          def colmap0(dotvec): return [.5 + .5 * c for c in dotvec]
119          def colmap1(dotvec): return js([.5 + .25 * c for c in dotvec])          def colmap1(dotvec): return [.5 + .25 * c for c in dotvec]
120    
121          tex_scale = .25          tex_scale = .25
122          tex_bias = .75          tex_bias = .75
# Line 113  def init(profile): Line 133  def init(profile):
133                    
134          alphalevel = 1          alphalevel = 1
135          w0,w1 = 1,1          w0,w1 = 1,1
136          def colmap0(dotvec): return "1 1 1 1"          def colmap0(dotvec): return (1,1,1,1)
137          def colmap1(dotvec): return "0 0 0 0"          def colmap1(dotvec): return (0,0,0,0)
138                    
139          tex_scale = 1          tex_scale = 1
140          tex_bias = 0          tex_bias = 0
# Line 178  def getIrregu(invert, x0, y0, x1, y1, ou Line 198  def getIrregu(invert, x0, y0, x1, y1, ou
198      m = 0.5 * ripple_scale * texscale / len      m = 0.5 * ripple_scale * texscale / len
199      nvec = (m * (y1 - y0), -m * (x1 - x0), 0, 0) # cw90      nvec = (m * (y1 - y0), -m * (x1 - x0), 0, 0) # cw90
200    
201      vert0 = js(vecmul(vecsub((x0,y0,0,1),nvec), w0))      vertices = [
202      vert1 = js(vecmul(vecadd((x0,y0,0,1),nvec), w1))          vecmul(vecsub((x0,y0,0,1),nvec), w0),
203      vert2 = js(vecmul(vecsub((x1,y1,0,1),nvec), w0))          vecmul(vecadd((x0,y0,0,1),nvec), w1),
204      vert3 = js(vecmul(vecadd((x1,y1,0,1),nvec), w1))          vecmul(vecsub((x1,y1,0,1),nvec), w0),
205            vecmul(vecadd((x1,y1,0,1),nvec), w1)
206      tex0 = js(vecmul((x0,y0,0,texscale), w0))          ]
207      tex1 = js(vecmul((x0,y0,0,texscale), w1))  
208      tex2 = js(vecmul((x1,y1,0,texscale), w0))      texcoords = [
209      tex3 = js(vecmul((x1,y1,0,texscale), w1))          vecmul((x0,y0,0,texscale), w0),
210            vecmul((x0,y0,0,texscale), w1),
211            vecmul((x1,y1,0,texscale), w0),
212            vecmul((x1,y1,0,texscale), w1)
213            ]
214    
215      #print "Vertices:"      #print "Vertices:"
216      #print vert0, tex0      #print vert0, tex0
# Line 194  def getIrregu(invert, x0, y0, x1, y1, ou Line 218  def getIrregu(invert, x0, y0, x1, y1, ou
218      #print vert2, tex2      #print vert2, tex2
219      #print vert3, tex3      #print vert3, tex3
220    
221      if outer:      angle = atan2(y1 - y0, x1 - x0) - texangle
222          angle = atan2(y1 - y0, x1 - x0) - texangle  
223        dx = str(cos(angle))
224        dy = str(sin(angle))
225    
226        if outer:
227          a = angle * 6 / (2 * pi)          a = angle * 6 / (2 * pi)
228          while a < 0: a+=3          while a < 0: a+=3
229          i = int(a) % 3          i = int(a) % 3
# Line 207  def getIrregu(invert, x0, y0, x1, y1, ou Line 234  def getIrregu(invert, x0, y0, x1, y1, ou
234      else:      else:
235          vec = (1,0,0)          vec = (1,0,0)
236    
     col0 = colmap0(vec)  
     col1 = colmap1(vec)  
237      dotvec = js(vec)      dotvec = js(vec)
238    
239        cols = [
240            colmap0(vec),
241            colmap1(vec),
242            colmap0(vec),
243            colmap1(vec)
244        ]
245        
246      code = """      code = """
247      PushAttrib ENABLE_BIT TEXTURE_BIT      PushAttrib ENABLE_BIT TEXTURE_BIT
248    
# Line 250  def getIrregu(invert, x0, y0, x1, y1, ou Line 282  def getIrregu(invert, x0, y0, x1, y1, ou
282      StencilOp INCR INCR INCR      StencilOp INCR INCR INCR
283            
284      Begin QUAD_STRIP      Begin QUAD_STRIP
285        """ % locals()
286    
287      Color %(col0)s      for i in range(0,4):
288      TexCoord %(tex0)s          code += """
289      Vertex %(vert0)s          Color %s
290            TexCoord %s
291      Color %(col1)s          Vertex %s
292      TexCoord %(tex1)s          """ % (js(cols[i]), js(texcoords[i]), js(vertices[i]))
     Vertex %(vert1)s  
   
     Color %(col0)s  
     TexCoord %(tex2)s  
     Vertex %(vert2)s  
   
     Color %(col1)s  
     TexCoord %(tex3)s  
     Vertex %(vert3)s  
293    
294        code += """
295      End      End
296    
297      ColorMask 1 1 1 1      ColorMask 1 1 1 1
298      Disable STENCIL_TEST      Disable STENCIL_TEST
299      PopAttrib      PopAttrib
300            """
     """ % locals()  
301    
302      if outer and texenv_inner == texenv_outer:      if outer and texenv_inner == texenv_outer:
303          code += """          code += """

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22

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