Package javax.media.j3d

Examples of javax.media.j3d.Texture2D


        return getModel(tileManager.getArtilleryTarget(type), .5f, false);
    }
   
    public Texture2D getTexture(String filename) {
        TextureLoader tl = new TextureLoader(filename, TextureLoader.GENERATE_MIPMAP, null);
        Texture2D tex = (Texture2D)tl.getTexture();
        tex.setMagFilter(Texture.NICEST);
        tex.setMinFilter(Texture.NICEST);
        return tex;
    }
View Full Code Here


    }

    private final Texture2D getTexture(Image base, boolean border, Color col, float alpha, boolean tile) {
        if (base == null) return null;

        Texture2D tex = textureCache.get(new ImageAlpha(base, alpha));
        if (tex == null) {
            MediaTracker tracker = new MediaTracker(comp);

            // Fully load image before continuing
            tracker.addImage(base, 0);
            do {
                try { tracker.waitForID(0); } catch (InterruptedException e) { continue; }
            } while (false);
            tracker.removeImage(base);

            final int w = base.getWidth(null), h = base.getHeight(null);
            BufferedImage tmp = new BufferedImage(w*2, h*2, BufferedImage.TYPE_INT_ARGB);
            Graphics2D tgr = tmp.createGraphics();
            if (col != null) {
                tgr.setColor(col);
                tgr.fillRect(0, 0, w*2, h*2);
            }
            tgr.translate(w/2, h/2);
            tgr.drawImage(base, null, null);
            if (tile) {
                // create an image of a hex with all 6 surrounding hexes to get
                // better interpolation at the borders
                tgr.translate(0, -h);
                tgr.drawImage(base, null, null);
                tgr.translate(0, 2*h);
                tgr.drawImage(base, null, null);
                tgr.translate(-3*w/4, -h/2);
                tgr.drawImage(base, null, null);
                tgr.translate(0, -h);
                tgr.drawImage(base, null, null);
                tgr.translate(3*w/2, 0);
                tgr.drawImage(base, null, null);
                tgr.translate(0, h);
                tgr.drawImage(base, null, null);
            }

            tracker.addImage(tmp, 1);
            do {
                try { tracker.waitForID(1); } catch (InterruptedException e) { continue; }
            } while (false);
            tracker.removeImage(tmp);

            // TODO: Make this configurable.
            // Cut outer pixel border? This removes the distinct tile border present in most tiles.
            int border_cut = 1;
            // Add our own pixel border? Higher quality (resolution) than the image's tile border.
            int border_add = 3;

            if (!border) {
                border_cut = 0;
                border_add = 0;
            }

            // Scale texture image, cutting border if needed
            BufferedImage src = new BufferedImage(TEXSIZE, TEXSIZE, BufferedImage.TYPE_INT_ARGB);
            AffineTransform at = new AffineTransform();
            at.scale(TEXSIZE/(double)(w-border_cut*2), TEXSIZE/(double)(h-border_cut*2));
            at.translate(-w/2-border_cut, -h/2-border_cut);
            AffineTransformOp ato = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
            ato.filter(tmp, src);

            if (border_add > 0) {
                // Add border if needed
                Graphics2D gr = src.createGraphics();
                gr.setColor(Color.DARK_GRAY);
                gr.setStroke(new BasicStroke(border_add));
                gr.addRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
                int[] xvals = { TEXSIZE/4, 3*TEXSIZE/4-1, TEXSIZE-1, 3*TEXSIZE/4-1, TEXSIZE/4, 0, TEXSIZE/4 };
                int[] yvals = { 0, 0, TEXSIZE/2, TEXSIZE-1, TEXSIZE-1, TEXSIZE/2, 0 };
                gr.drawPolygon(xvals, yvals, xvals.length);
            }
           
            if (alpha < 1.0f) {
                WritableRaster wr = src.getAlphaRaster();
                for (int y = 0; y < src.getHeight(); y++) {
                    for (int x = 0; x < src.getWidth(); x++)
                        wr.setSample(x, y, 0, alpha*wr.getSampleFloat(x, y, 0));
                }
            }

            // Finally create actual texture
            TextureLoader tl = new TextureLoader(src, TextureLoader.GENERATE_MIPMAP);
            tex = (Texture2D)tl.getTexture();
            tex.setMagFilter(Texture.NICEST);
            tex.setMinFilter(Texture.NICEST);

            if (tileManager.isLoaded()) textureCache.put(new ImageAlpha(base, alpha), tex);
        }
        return tex;
    }
View Full Code Here

    //Generate a (scaled) image of the texture. Height and width must be
    //powers of 2.
    ImageComponent2D textureIm = textureLoad.getScaledImage(64,128);

    //Generate the texture.
    Texture2D aTexture = new Texture2D(Texture2D.BASE_LEVEL,Texture2D.RGB,
                                            textureIm.getWidth(),
                                            textureIm.getHeight());
    aTexture.setImage(0,textureIm);

    //An Appearance which will use the texture.
    Appearance textureApp = new Appearance();
    textureApp.setTexture(aTexture);
    TextureAttributes textureAttr = new TextureAttributes();
View Full Code Here

         
          // screen in die textur umwandeln und anzeigen
          ImageComponent2D texImage = new ImageComponent2D(
                  ImageComponent.FORMAT_RGBA4, screen);

          tex = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, 256, 256);
          tex.setImage(0, texImage);
         
          texAttr = new TextureAttributes();
      texAttr.setTextureMode(TextureAttributes.MODULATE);
      textureUnitState[0] = new TextureUnitState(tex, texAttr, null);
View Full Code Here

/*     */           }
/*     */           else {
/* 309 */             t = new TextureLoader(this.basePath + tFile, "RGB", 1, null);
/*     */           }
/*     */
/* 313 */           Texture2D texture = (Texture2D)t.getTexture();
/* 314 */           if (texture != null) this.cur.t = texture;
/*     */         }
/*     */         catch (FileNotFoundException e)
/*     */         {
/*     */         }
View Full Code Here

/*     */   Texture getTexture()
/*     */   {
/* 132 */     debugOutputLn(1, "getTexture()");
/* 133 */     if (this.theImage == null)
/* 134 */       return null;
/* 135 */     Texture2D t2d = (Texture2D)textureTable.get(this.theImage);
/* 136 */     if (t2d == null) {
/* 137 */       ImageScaler scaler = new ImageScaler((BufferedImage)this.theImage);
/* 138 */       BufferedImage scaledImage = (BufferedImage)scaler.getScaledImage();
/* 139 */       TextureLoader tl = new TextureLoader(scaledImage);
/* 140 */       t2d = (Texture2D)tl.getTexture();
View Full Code Here

/*     */
/* 121 */     if ((imageComponent.getWidth() == width) && (imageComponent.getHeight() == height))
/*     */     {
/* 123 */       tex.setImage(0, imageComponent);
/*     */     } else {
/* 125 */       Texture2D newTex = setupTexture(imageComponent);
/*     */
/* 129 */       newTex.setBoundaryModeS(tex.getBoundaryModeS());
/* 130 */       newTex.setBoundaryModeT(tex.getBoundaryModeT());
/* 131 */       newTex.setMinFilter(tex.getMinFilter());
/* 132 */       newTex.setMagFilter(tex.getMagFilter());
/* 133 */       newTex.setEnable(tex.getEnable());
/* 134 */       newTex.setAnisotropicFilterMode(tex.getAnisotropicFilterMode());
/* 135 */       newTex.setAnisotropicFilterDegree(tex.getAnisotropicFilterDegree());
/* 136 */       int pcount = tex.getFilter4FuncPointsCount();
/* 137 */       if (pcount > 0) {
/* 138 */         float[] weights = new float[pcount];
/* 139 */         tex.getFilter4Func(weights);
/* 140 */         newTex.setFilter4Func(weights);
/*     */       }
/* 142 */       Color4f c = new Color4f();
/* 143 */       tex.getBoundaryColor(c);
/* 144 */       newTex.setBoundaryColor(c);
/* 145 */       newTex.setUserData(tex.getUserData());
/* 146 */       getAppearance().setTexture(newTex);
/*     */     }
/*     */   }
View Full Code Here

/*     */
/*     */   private void updateText2D(String text, Color3f color, String fontName, int fontSize, int fontStyle)
/*     */   {
/* 152 */     ImageComponent imageComponent = setupImage(text, color, fontName, fontSize, fontStyle);
/*     */
/* 155 */     Texture2D t2d = setupTexture(imageComponent);
/*     */
/* 157 */     QuadArray rect = setupGeometry(imageComponent.getWidth(), imageComponent.getHeight());
/*     */
/* 159 */     setGeometry(rect);
/*     */
View Full Code Here

/* 184 */     return this.rectangleScaleFactor;
/*     */   }
/*     */
/*     */   private Texture2D setupTexture(ImageComponent imageComponent)
/*     */   {
/* 191 */     Texture2D t2d = new Texture2D(1, 6, imageComponent.getWidth(), imageComponent.getHeight());
/*     */
/* 195 */     t2d.setMinFilter(3);
/* 196 */     t2d.setMagFilter(3);
/* 197 */     t2d.setImage(0, imageComponent);
/* 198 */     t2d.setEnable(true);
/* 199 */     t2d.setCapability(7);
/* 200 */     t2d.setCapability(8);
/* 201 */     t2d.setCapability(0);
/* 202 */     t2d.setCapability(2);
/* 203 */     t2d.setCapability(3);
/* 204 */     t2d.setCapability(6);
/* 205 */     t2d.setCapability(12);
/* 206 */     t2d.setCapability(14);
/* 207 */     return t2d;
/*     */   }
View Full Code Here

/*     */
/*     */   public Texture2DState(SymbolTableData symbol, Controller control) {
/*  56 */     super(symbol, control);
/*     */
/*  59 */     if (this.node != null) {
/*  60 */       Texture2D t = (Texture2D)this.node;
/*  61 */       this.detailImage = control.getSymbolTable().addReference(t.getDetailImage());
/*     */     }
/*     */   }
View Full Code Here

TOP

Related Classes of javax.media.j3d.Texture2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.