Search in sources :

Example 16 with Picture

use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.

the class HDRLoader method load.

public Image load(InputStream in, boolean flipY) throws IOException {
    float gamma = -1f;
    float exposure = -1f;
    float[] colorcorr = new float[] { -1f, -1f, -1f };
    int width = -1, height = -1;
    boolean verifiedFormat = false;
    while (true) {
        String ln = readString(in);
        ln = ln.trim();
        if (ln.startsWith("#") || ln.equals("")) {
            if (ln.equals("#?RADIANCE") || ln.equals("#?RGBE"))
                verifiedFormat = true;
            // comment or empty statement
            continue;
        } else if (ln.startsWith("+") || ln.startsWith("-")) {
            // + or - mark image resolution and start of data
            String[] resData = ln.split("\\s");
            if (resData.length != 4) {
                throw new IOException("Invalid resolution string in HDR file");
            }
            if (!resData[0].equals("-Y") || !resData[2].equals("+X")) {
                logger.warning("Flipping/Rotating attributes ignored!");
            }
            //if (resData[0].endsWith("X")){
            // first width then height
            //    width = Integer.parseInt(resData[1]);
            //    height = Integer.parseInt(resData[3]);
            //}else{
            width = Integer.parseInt(resData[3]);
            height = Integer.parseInt(resData[1]);
            break;
        } else {
            // regular command
            int index = ln.indexOf("=");
            if (index < 1) {
                logger.log(Level.FINE, "Ignored string: {0}", ln);
                continue;
            }
            String var = ln.substring(0, index).trim().toLowerCase();
            String value = ln.substring(index + 1).trim().toLowerCase();
            if (var.equals("format")) {
                if (!value.equals("32-bit_rle_rgbe") && !value.equals("32-bit_rle_xyze")) {
                    throw new IOException("Unsupported format in HDR picture");
                }
            } else if (var.equals("exposure")) {
                exposure = Float.parseFloat(value);
            } else if (var.equals("gamma")) {
                gamma = Float.parseFloat(value);
            } else {
                logger.log(Level.WARNING, "HDR Command ignored: {0}", ln);
            }
        }
    }
    assert width != -1 && height != -1;
    if (!verifiedFormat)
        logger.warning("Unsure if specified image is Radiance HDR");
    // some HDR images can get pretty big
    System.gc();
    // each pixel times size of component times # of components
    Format pixelFormat;
    if (writeRGBE) {
        pixelFormat = Format.RGBA8;
    } else {
        pixelFormat = Format.RGB16F;
    }
    dataStore = BufferUtils.createByteBuffer(width * height * pixelFormat.getBitsPerPixel());
    int bytesPerPixel = pixelFormat.getBitsPerPixel() / 8;
    int scanLineBytes = bytesPerPixel * width;
    for (int y = height - 1; y >= 0; y--) {
        if (flipY)
            dataStore.position(scanLineBytes * y);
        decodeScanline(in, width);
    }
    in.close();
    dataStore.rewind();
    //HDR files color data is actually stored in linear space.
    return new Image(pixelFormat, width, height, dataStore, ColorSpace.Linear);
}
Also used : Format(com.jme3.texture.Image.Format) IOException(java.io.IOException) Image(com.jme3.texture.Image)

Example 17 with Picture

use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.

the class FilterPostProcessor method initialize.

public void initialize(RenderManager rm, ViewPort vp) {
    renderManager = rm;
    renderer = rm.getRenderer();
    viewPort = vp;
    fsQuad = new Picture("filter full screen quad");
    fsQuad.setWidth(1);
    fsQuad.setHeight(1);
    if (fbFormat == Format.RGB111110F && !renderer.getCaps().contains(Caps.PackedFloatTexture)) {
        fbFormat = Format.RGB8;
    }
    Camera cam = vp.getCamera();
    //save view port diensions
    left = cam.getViewPortLeft();
    right = cam.getViewPortRight();
    top = cam.getViewPortTop();
    bottom = cam.getViewPortBottom();
    originalWidth = cam.getWidth();
    originalHeight = cam.getHeight();
    //first call to reshape
    reshape(vp, cam.getWidth(), cam.getHeight());
}
Also used : Picture(com.jme3.ui.Picture)

Example 18 with Picture

use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.

the class Picture method setTexture.

/**
     * Set the texture to put on the picture.
     * 
     * @param assetManager The {@link AssetManager} to use to load the material.
     * @param tex The texture
     * @param useAlpha If true, the picture will appear transparent and allow
     * objects behind it to appear through. If false, the transparent
     * portions will be the image's color at that pixel.
     */
public void setTexture(AssetManager assetManager, Texture2D tex, boolean useAlpha) {
    if (getMaterial() == null) {
        Material mat = new Material(assetManager, "Common/MatDefs/Gui/Gui.j3md");
        mat.setColor("Color", ColorRGBA.White);
        setMaterial(mat);
    }
    material.getAdditionalRenderState().setBlendMode(useAlpha ? BlendMode.Alpha : BlendMode.Off);
    material.setTexture("Texture", tex);
}
Also used : Material(com.jme3.material.Material)

Example 19 with Picture

use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.

the class Picture method setImage.

/**
     * Set the image to put on the picture.
     * 
     * @param assetManager The {@link AssetManager} to use to load the image.
     * @param imgName The image name.
     * @param useAlpha If true, the picture will appear transparent and allow
     * objects behind it to appear through. If false, the transparent
     * portions will be the image's color at that pixel.
     */
public void setImage(AssetManager assetManager, String imgName, boolean useAlpha) {
    TextureKey key = new TextureKey(imgName, true);
    Texture2D tex = (Texture2D) assetManager.loadTexture(key);
    setTexture(assetManager, tex, useAlpha);
}
Also used : TextureKey(com.jme3.asset.TextureKey) Texture2D(com.jme3.texture.Texture2D)

Example 20 with Picture

use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.

the class Picture method setHeight.

/**
     * Set the height in pixels of the picture, if the height
     * does not match the texture's height, then the texture will
     * be scaled to fit the picture.
     * 
     * @param height the height to set.
     */
public void setHeight(float height) {
    this.height = height;
    setLocalScale(new Vector3f(width, height, 1f));
}
Also used : Vector3f(com.jme3.math.Vector3f)

Aggregations

Picture (com.jme3.ui.Picture)22 Texture2D (com.jme3.texture.Texture2D)11 Material (com.jme3.material.Material)9 Geometry (com.jme3.scene.Geometry)5 FrameBuffer (com.jme3.texture.FrameBuffer)5 Quaternion (com.jme3.math.Quaternion)4 Vector3f (com.jme3.math.Vector3f)4 Node (com.jme3.scene.Node)4 Image (com.jme3.texture.Image)4 ViewPort (com.jme3.renderer.ViewPort)3 Quad (com.jme3.scene.shape.Quad)3 ActionListener (com.jme3.input.controls.ActionListener)2 KeyTrigger (com.jme3.input.controls.KeyTrigger)2 Matrix4f (com.jme3.math.Matrix4f)2 Camera (com.jme3.renderer.Camera)2 Sphere (com.jme3.scene.shape.Sphere)2 Format (com.jme3.texture.Image.Format)2 ByteBuffer (java.nio.ByteBuffer)2 TextureKey (com.jme3.asset.TextureKey)1 EnvironmentCamera (com.jme3.environment.EnvironmentCamera)1