/** * Constructs a background image layer with an image source. The image's dimensions must be no greater than 2048 x * 2048. * * @param imageSource the image source * @param imageOptions the image options, or null to use the default options * * @throws IllegalArgumentException If the image source is null */ public BackgroundLayer(ImageSource imageSource, ImageOptions imageOptions) { if (imageSource == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "BackgroundLayer", "constructor", "missingSource")); } this.setDisplayName("Background"); // Disable picking for the layer because it covers the full sphere and will override a terrain pick. this.setPickEnabled(false); // Delegate display to the SurfaceImage shape. SurfaceImage surfaceImage = new SurfaceImage(new Sector().setFullSphere(), imageSource); surfaceImage.setImageOptions(imageOptions); this.addRenderable(surfaceImage); } }
SurfaceImage surfaceImageResource = new SurfaceImage(sector, ImageSource.fromResource(resourceId)); SurfaceImage surfaceImageUrl = new SurfaceImage(sector, ImageSource.fromUrl(urlString));
@Override protected void doRender(RenderContext rc) { if (this.sector.isEmpty()) { return; // nothing to render } if (!rc.terrain.getSector().intersects(this.sector)) { return; // no terrain surface to render on } Texture texture = rc.getTexture(this.imageSource); // try to get the texture from the cache if (texture == null) { texture = rc.retrieveTexture(this.imageSource, this.imageOptions); // puts retrieved textures in the cache } if (texture == null) { return; // no texture to draw } // Enqueue a drawable surface texture for processing on the OpenGL thread. SurfaceTextureProgram program = this.getShaderProgram(rc); Pool<DrawableSurfaceTexture> pool = rc.getDrawablePool(DrawableSurfaceTexture.class); DrawableSurfaceTexture drawable = DrawableSurfaceTexture.obtain(pool).set(program, this.sector, texture, texture.getTexCoordTransform()); rc.offerSurfaceDrawable(drawable, 0 /*z-order*/); // Enqueue a picked object that associates the drawable surface texture with this surface image. if (rc.pickMode) { int pickedObjectId = rc.nextPickedObjectId(); PickedObject.identifierToUniqueColor(pickedObjectId, drawable.color); rc.offerPickedObject(PickedObject.fromRenderable(pickedObjectId, this, rc.currentLayer)); } }
protected boolean addImage() { // Create an image source with a unique factory instance. This pattern is used in order to force WorldWind to // allocate a new OpenGL texture object for each surface image from a single bitmap instance. ImageSource imageSource = ImageSource.fromBitmapFactory(new ImageSource.BitmapFactory() { @Override public Bitmap createBitmap() { return bitmap; } }); // Add the surface image to this test's layer. this.layer.addRenderable(new SurfaceImage(new Sector(this.sector), imageSource)); this.getWorldWindow().requestRedraw(); // Advance to the next surface image's location. if (this.sector.maxLongitude() < this.firstSector.minLongitude() + this.firstSector.deltaLongitude() * 20) { this.sector.set( this.sector.minLatitude(), this.sector.minLongitude() + this.sector.deltaLongitude() + 0.1, this.sector.deltaLatitude(), this.sector.deltaLongitude()); } else { this.sector.set( this.sector.minLatitude() + this.sector.deltaLatitude() + 0.1, this.firstSector.minLongitude(), this.sector.deltaLatitude(), this.sector.deltaLongitude()); } // Add another image after the configured delay. return this.handler.sendEmptyMessageDelayed(ADD_IMAGE, ADD_IMAGE_DELAY); }