/[gzz]/gzz/gzz/vob/vobs/OvalBgVob.java
ViewVC logotype

Diff of /gzz/gzz/vob/vobs/OvalBgVob.java

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

revision 1.9 by tjl, Fri Feb 21 20:02:48 2003 UTC revision 1.10 by humppake, Wed Mar 5 14:34:23 2003 UTC
# Line 1  Line 1 
1  /*  /*
2  OvalBgVob.java  OvalBgVob.java
3   *       *    
4   *    Copyright (c) 1999-2002, Ted Nelson and Tuomas Lukka   *    Copyright (c) 2003, Asko Soukka
5   *   *
6   *    This file is part of Gzz.   *    This file is part of Gzz.
7   *       *    
# Line 23  OvalBgVob.java Line 23  OvalBgVob.java
23   *   *
24   */   */
25  /*  /*
26   * Written by Tuomas Lukka, Tero Mäyränen and Asko Soukka   * Written by Asko Soukka
27   */   */
28    
29  package gzz.vob.vobs;  package gzz.vob.vobs;
# Line 45  import gzz.client.GraphicsAPI; Line 45  import gzz.client.GraphicsAPI;
45   * surrounded by a circle of the current foreground color.   * surrounded by a circle of the current foreground color.
46   */   */
47    
48  public class OvalBgVob extends Vob {  public class OvalBgVob extends ColoredSectorVob {
49  public static final String rcsid = "$Id$";  public static final String rcsid = "$Id$";
     public static boolean dbg = false;  
     static final void p(String s) { if(dbg) System.out.println(s); }  
     static final void pa(String s) { System.out.println(s); }  
   
     static Rectangle rect = new Rectangle();  
   
     static protected GL.Texture tex;  
     static protected boolean texLoaded = false;  
     static protected void loadTex() {  
         if (!texLoaded) {  
             String[] texparam = {"line_width", "1"};  
             tex = GL.createTexture();  
             tex.shade_all_levels(512, 512, 0, 4, "RGBA", "RGBA", "circle", texparam);  
             texLoaded = true;  
         }  
     }  
   
     int nsolids = 0;  
     Color[] solids;  
     protected Color bg = Color.white;  
   
     public void setBg(Color c){ if( c != null ) bg = c; }  
     public Color getBg() { return bg; }  
50    
51      boolean drawBorder = true;      public OvalBgVob() {
52            super(90, 360, 10);
53            start = 90;
54            sector = 360;
55            step = 10;
56        }
57    
58      public void render(Graphics g,      public void render(Graphics g,
59                                  boolean fast,                         boolean fast,
60                                  Vob.RenderInfo info1,                         Vob.RenderInfo info1,
61                                  Vob.RenderInfo info2) {                         Vob.RenderInfo info2) {
62          info1.getExtRect(rect);          info1.getExtRect(rect);
63          int mx = rect.x, my=rect.y,          int mx = rect.x, my=rect.y,
64              mw = rect.width, mh = rect.height;              mw = rect.width, mh = rect.height;
# Line 139  public static final String rcsid = "$Id$ Line 121  public static final String rcsid = "$Id$
121              g.drawOval(mx, my, mw, mh);              g.drawOval(mx, my, mw, mh);
122          }          }
123    
   
124          g.setColor(oldfg);          g.setColor(oldfg);
125      }      }
126    
127      Vob glList;      Vob glStencil, glBorder;
128    
129        public int putGL(final VobScene vs, final int coordsys1) {
130            if(dbg) pa("Addtolistgl ovalbg "+coordsys1);
131    
     public int putGL(VobScene vs, int coordsys1) {  
         if(dbg) pa("Addtolistgl rectbg "+coordsys1);  
132          if(glList == null) {          if(glList == null) {
133              /** In OpenGL the oval shape is done by drawing              if (!circleGLReady) prepareCircleGL(0.5f);
              * a quad stript with an oval texture inside it.  
              */  
             if (!texLoaded) loadTex();  
134              String bgcall = "";              String bgcall = "";
135              if(nsolids > 0) {              if(nsolids > 0) {
136                  double w = 1.0 / nsolids;                  bgcall += glSolidsString();
137                  for(int i=0; i<nsolids; i++) {              } else bgcall += glBgString();
138                      double x1 = i*w;              
                     double x2 = x1 + w;  
                     Color c = solids[i];  
                     bgcall += (  
                         "Color "+ColorUtil.colorGLString(solids[i])+" 1\n"+  
                         "Begin QUAD_STRIP\n"+  
                         "TexCoord "+x1+" 1\n"+  
                         "Vertex "+x1+" 1\n"+  
                         "TexCoord "+x1+" 0\n"+  
                         "Vertex "+x1+" 0\n"+  
                         "TexCoord "+x2+" 1\n"+  
                         "Vertex "+x2+" 1\n"+  
                         "TexCoord "+x2+" 0\n"+  
                         "Vertex "+x2+" 0\n"+  
                         "End\n");  
                 }  
             } else {  
                 bgcall = (  
                     "Color "+ColorUtil.colorGLString(bg)+" 1\n" +  
                     "Begin QUAD_STRIP\n"+  
                     "TexCoord 1 1\nVertex 1 1\n"+  
                     "TexCoord 1 0\nVertex 1 0\n"+  
                     "TexCoord 0 1\nVertex 0 1\n"+  
                     "TexCoord 0 0\nVertex 0 0\n"+  
                     "End\n");  
             }  
                       
139              glList = GLRen.createCallListBoxCoorded(              glList = GLRen.createCallListBoxCoorded(
140                  "PushAttrib CURRENT_BIT ENABLE_BIT\n"+                  "PushAttrib CURRENT_BIT ENABLE_BIT\n"+
141                  "BindTexture TEXTURE_2D "+tex.getTexId()+"\n"+                  "Disable TEXTURE_2D\n"+
                 "TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR\n"+  
                 "TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR\n"+  
                 "TexParameter TEXTURE_2D TEXTURE_MAX_ANISOTROPY_EXT 1\n"+  
                 "Enable BLEND\n"+  
                 "BlendFunc SRC_ALPHA ONE_MINUS_SRC_ALPHA\n"+  
                 "Enable TEXTURE_2D\n"+  
142                  bgcall +                  bgcall +
143                  "PopAttrib\n"                  "PopAttrib\n"
144                  );                  );
145          }          }
         vs.map.put(glList, coordsys1);  
         return 0;  
     }  
146    
147      /** Adds one more solid color to be drawn inside          if(glStencil == null) {
148       * the cell.              glStencil = GLRen.createCallListBoxCoorded(
149       */                  "PushAttrib CURRENT_BIT ENABLE_BIT\n"+
150      public boolean addColor(Color c) {                  "Disable TEXTURE_2D\n"+
151          if(solids == null || nsolids >= solids.length) {                  super.glBgString() +
152              Color[] n= new Color[nsolids + 10];                  "PopAttrib\n"
153              if(solids != null) System.arraycopy(solids, 0, n, 0, nsolids);                  );
             solids = n;  
154          }          }
         solids[nsolids++] = c;  
         return false;  
     }  
     /** The currently put solid colors.  
      * null = none. There may be null references near the end  
      * of the array. Mostly useful for checking for nullness.  
      */  
     public Color[] getSolidColors() { return solids; }  
 }  
   
   
   
   
   
155    
156            if(glBorder == null) {
157                glBorder = GLRen.createCallListBoxCoorded(
158                    "PushAttrib CURRENT_BIT ENABLE_BIT\n"+
159                    "Disable TEXTURE_2D\n"+
160                    glBorderString() +
161                    "PopAttrib\n"
162                    );
163            }
164    
165            gzz.gfx.gl.Stencil.drawStenciled(
166               vs,
167               new Runnable() { public void run() {
168                   vs.map.put(glStencil, coordsys1);
169               }},
170               null,
171               null,
172               new Runnable() { public void run() {
173                   vs.map.put(glList, coordsys1);
174               }},
175               false
176            );
177    
178            if(drawBorder) vs.map.put(glBorder, coordsys1);
179            return 0;
180        }
181    
182        protected String glBgString() {
183            String glString = "";
184            glString += (
185                         "Color "+ColorUtil.colorGLString(bg)+" 1\n" +
186                         "Begin QUAD_STRIP\n"+
187                         "Vertex 1 1\nVertex 1 0\n"+
188                         "Vertex 0 1\nVertex 0 0\n"+
189                         "End\n");
190            return glString;
191        }
192    
193        protected String glSolidsString() {
194            double w = 1.0 / nsolids;
195            String glString = "";
196            for(int i=0; i<nsolids; i++) {
197                double x1 = i*w;
198                double x2 = x1 + w;
199                Color c = solids[i];
200                glString += (
201                  "Color "+ColorUtil.colorGLString(solids[i])+" 1\n"+
202                  "Begin QUAD_STRIP\n"+
203                  "TexCoord "+x1+" 1\n"+
204                  "Vertex "+x1+" 1\n"+
205                  "TexCoord "+x1+" 0\n"+
206                  "Vertex "+x1+" 0\n"+
207                  "TexCoord "+x2+" 1\n"+
208                  "Vertex "+x2+" 1\n"+
209                  "TexCoord "+x2+" 0\n"+
210                  "Vertex "+x2+" 0\n"+
211                  "End\n");
212            }
213            return glString;
214        }
215    }

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

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