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

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

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

revision 1.8 by tjl, Wed Sep 4 18:05:43 2002 UTC revision 1.9 by tjl, Thu Sep 5 09:49:52 2002 UTC
# Line 9  def js(list): Line 9  def js(list):
9      return " ".join([str(el) for el in list])      return " ".join([str(el) for el in list])
10    
11    
12  t = [  t = {
13   ("tf1", [256, 256, 0, 2],   "tfamb": ( 256, 256, 0, 2, "LUMINANCE_ALPHA", "LUMINANCE_ALPHA",
14        "TubeFrame", ["light", "ambient" ]),
15     "tfdiff": ( 256, 256, 0, 2, "LUMINANCE_ALPHA", "LUMINANCE_ALPHA",
16        "TubeFrame", ["light", "diffuse" ]),
17     "tfspec": ( 256, 256, 0, 2, "LUMINANCE_ALPHA", "LUMINANCE_ALPHA",
18        "TubeFrame", ["light", "specular" ]),
19    }
20    
21    curtex = [
22        "tfamb", "tfdiff", "tfspec"
23    ]
24    
25    shaded = { }
26    
27    def shadedquad(color, tex):
28        return getDList("""
29                    Color %(color)s
30                    BindTexture TEXTURE_2D %(tex)s
31                    TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR
32                    Enable TEXTURE_2D
33                    Begin QUAD_STRIP
34                        TexCoord 1.1 1.1 0
35                        Vertex 1 -1 1
36                        TexCoord 1.1 -0.1 0
37                        Vertex 1 1 1
38                        TexCoord -0.1 1.1 5
39                        Vertex -1 -1 1
40                        TexCoord -0.1 -0.1 5
41                        Vertex -1 1 1
42                    End
43                """ % {
44                    "tex" : tex.getTexId(),
45                    "color" : js(color),
46                    })
47    
48  class ShaderScene:  class ShaderScene:
49      def __init__(self):      def __init__(self):
         self.resolution = [256, 256]  
         self.shadername = "filereader"  
         self.shaderparams = {  
             "bulgemagz": 0.5,  
             "bulgemagx": 0,  
             "lfreq": 2,  
             "hfreq": 10,  
             "bias": -.0,  
             "scale": 1,  
             "file": "lava/gfx/c.dat"  
         }  
         self.colors = [ (1, 1, 1), (1, 0, 0), (0, 1, 0), (0, 0, 1)]  
         self.shadercomps = 1  
         self.shaderformat = "LUMINANCE"  
         self.internalformat = "LUMINANCE"  
         self.angle = 0  
         self.sca = 1  
50          self.shade()          self.shade()
51      def key(self, k):      def key(self, k):
         if k == "+": self.sca += 1./16  
         if k == "-": self.sca -= 1./16  
52          if k == "s":          if k == "s":
53              retexture()              retexture()
54              self.shade()              self.shade()
# Line 43  class ShaderScene: Line 56  class ShaderScene:
56          if k == "c":          if k == "c":
57              rotate(self.colors)              rotate(self.colors)
58      def shade(self):      def shade(self):
59          params = []          self.t = []
60          for item in self.shaderparams.items():          for texname in curtex:
61              params.append(item[0])              texture = GZZGL.createTexture()
62              params.append(str(item[1]))              apply(texture.shade, t[texname])
63          self.texture = getTexture( self.resolution[0], self.resolution[0], self.resolution[0],              self.t.append(texture)
64              self.shadercomps, self.shaderformat, self.internalformat,  
             self.shadername,  
             params)  
         print "SHADER: ",self.texture  
65      def scene(self, vs):      def scene(self, vs):
66    
67          putnoc(vs, background((0.5,0.5,0.5)))          putnoc(vs, background((1.0,0.5,0.5)))
68    
69          putnoc(vs, getDList("""          putnoc(vs, getDList("""
70              PushAttrib POLYGON_BIT ENABLE_BIT              PushAttrib POLYGON_BIT ENABLE_BIT
71              Disable ALPHA_TEST              Disable ALPHA_TEST
72              Disable DEPTH_TEST              Disable DEPTH_TEST
73              Disable BLEND              Enable BLEND
74                BlendFunc SRC_ALPHA ONE_MINUS_SRC_ALPHA
75              Disable TEXTURE_3D              Disable TEXTURE_3D
76          """))          """))
77    
78          self.angle += 13          print "T: ",self.t
79            s = shadedquad("1 0 0 1", self.t[0]);
80            print s
81            vs.put(s, "0", 10, 0, 0, 500, 500);
82            vs.put(shadedquad("1 0 0 1", self.t[1]),
83                "1", 10, 0, 500, 500,500);
84            vs.put(shadedquad("1 0 0 1", self.t[2]),
85                "2", 10, 500, 000, 500,500);
86    
87            putnoc(vs, getDList("""
88                PopAttrib
89            """))
90    
91    
         print "Angle: ",self.angle  
         rotate(vs, "rot", 45, 0, 1, 0)  
         #self.sca = 1-self.sca  
92    
93    def d3foo():
94          transaffine(vs, "coor", 100*self.sca, 0, 1, 0, 0, 1)          transaffine(vs, "coor", 100*self.sca, 0, 1, 0, 0, 1)
95          putnoc(vs,          putnoc(vs,
96              getDListNocoords("""              getDListNocoords("""

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