/** * Sets the background image to the given filename, scaled to fit the window. * * @param imageURL The filename for the background image. */ public static void setBackground (String imageURL) { rootGroup.removeChild(bgGroup); bgGroup.removeChild(background); background = createBackground(); BufferedImage bi = null; try { bi = ImageIO.read(new File(imageURL)); } catch (IOException ioe) {ioe.printStackTrace(); } if (bi == null) { try { ImageIO.read(new URL(imageURL)); } catch (Exception e) { e.printStackTrace(); } } ImageComponent2D imageComp = new ImageComponent2D(ImageComponent.FORMAT_RGB, bi); background.setImage(imageComp); background.setImageScaleMode(Background.SCALE_FIT_ALL); bgGroup.addChild(background); rootGroup.addChild(bgGroup); }
/** * Sets the background image to the given filename, scaled to fit the window. * * @param imageURL The filename for the background image. */ public static void setBackground (String imageURL) { rootGroup.removeChild(bgGroup); bgGroup.removeChild(background); background = createBackground(); BufferedImage bi = null; try { bi = ImageIO.read(new File(imageURL)); } catch (IOException ioe) {ioe.printStackTrace(); } if (bi == null) { try { ImageIO.read(new URL(imageURL)); } catch (Exception e) { e.printStackTrace(); } } ImageComponent2D imageComp = new ImageComponent2D(ImageComponent.FORMAT_RGB, bi); background.setImage(imageComp); background.setImageScaleMode(Background.SCALE_FIT_ALL); bgGroup.addChild(background); rootGroup.addChild(bgGroup); }
/** * Sets the background color to the given color. * * @param color The color to set the background as. */ public static void setBackground (Color color) { if (!color.equals(bgColor)) { bgColor = color; rootGroup.removeChild(bgGroup); bgGroup.removeChild(background); background = createBackground(); background.setColor(new Color3f(bgColor)); bgGroup.addChild(background); rootGroup.addChild(bgGroup); } }
/** * Sets the background color to the given color. * * @param color The color to set the background as. */ public static void setBackground (Color color) { if (!color.equals(bgColor)) { bgColor = color; rootGroup.removeChild(bgGroup); bgGroup.removeChild(background); background = createBackground(); background.setColor(new Color3f(bgColor)); bgGroup.addChild(background); rootGroup.addChild(bgGroup); } }
/** * Sets the background to the given image file. The file gets * wrapped around as a spherical skybox. * * @param imageURL The background image to use. */ public static void setBackgroundSphere (String imageURL) { Sphere sphere = new Sphere(1.1f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, numDivisions); Appearance ap = sphere.getAppearance(); Texture texture = createTexture(imageURL); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.REPLACE); ap.setTexture(texture); ap.setTextureAttributes(texAttr); sphere.setAppearance(ap); BranchGroup backGeoBranch = createBranchGroup(); backGeoBranch.addChild(sphere); rootGroup.removeChild(bgGroup); bgGroup.removeChild(background); background = createBackground(); background.setGeometry(backGeoBranch); bgGroup.addChild(background); rootGroup.addChild(bgGroup); }
/** * Sets the background to the given image file. The file gets * wrapped around as a spherical skybox. * * @param imageURL The background image to use. */ public static void setBackgroundSphere (String imageURL) { Sphere sphere = new Sphere(1.1f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, numDivisions); Appearance ap = sphere.getAppearance(); Texture texture = createTexture(imageURL); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.REPLACE); ap.setTexture(texture); ap.setTextureAttributes(texAttr); sphere.setAppearance(ap); BranchGroup backGeoBranch = createBranchGroup(); backGeoBranch.addChild(sphere); rootGroup.removeChild(bgGroup); bgGroup.removeChild(background); background = createBackground(); background.setGeometry(backGeoBranch); bgGroup.addChild(background); rootGroup.addChild(bgGroup); }