com.jme3.texture.Image Java Examples

The following examples show how to use com.jme3.texture.Image. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HDRLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object load(AssetInfo info) throws IOException {
    if (!(info.getKey() instanceof TextureKey))
        throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");

    boolean flip = ((TextureKey) info.getKey()).isFlipY();
    InputStream in = null;
    try {
        in = info.openStream();
        Image img = load(in, flip);
        return img;
    } finally {
        if (in != null){
            in.close();
        }
    }
}
 
Example #2
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void deleteImage(Image image) {
    int texId = image.getId();
    if (texId != -1) {
        intBuf1.put(0, texId);
        intBuf1.position(0).limit(1);

        if (verboseLogging) {
            logger.info("GLES20.glDeleteTexture(1, buffer)");
        }

        GLES20.glDeleteTextures(1, intBuf1);
        image.resetObject();

        statistics.onDeleteTexture();
    }
}
 
Example #3
Source File: HDRLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Object load(AssetInfo info) throws IOException {
    if (!(info.getKey() instanceof TextureKey))
        throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");

    boolean flip = ((TextureKey) info.getKey()).isFlipY();
    InputStream in = null;
    try {
        in = info.openStream();
        Image img = load(in, flip);
        return img;
    } finally {
        if (in != null){
            in.close();
        }
    }
}
 
Example #4
Source File: PaintTerrainToolControl.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Start making changes.
 */
@JmeThread
private void startChange() {

    final Array<ColorPoint> colorPoints = getColorPoints();
    colorPoints.clear();

    final Texture alphaTexture = notNull(getAlphaTexture());
    final Image image = alphaTexture.getImage();
    final ByteBuffer data = image.getData(0);

    if (prevBuffer == null) {
        prevBuffer = BufferUtils.createByteBuffer(data.capacity());
    } else if (prevBuffer.capacity() < data.capacity()) {
        BufferUtils.destroyDirectBuffer(prevBuffer);
        prevBuffer = BufferUtils.createByteBuffer(data.capacity());
    }

    final int position = data.position();
    data.position(0);
    prevBuffer.clear();
    prevBuffer.put(data);
    prevBuffer.flip();
    data.position(position);
}
 
Example #5
Source File: ImageToAwt.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void createData(Image image, boolean mipmaps){
    int bpp = image.getFormat().getBitsPerPixel();
    int w = image.getWidth();
    int h = image.getHeight();
    if (!mipmaps){
        image.setData(BufferUtils.createByteBuffer(w*h*bpp/8));
        return;
    }
    int expectedMipmaps = 1 + (int) Math.ceil(Math.log(Math.max(h, w)) / LOG2);
    int[] mipMapSizes = new int[expectedMipmaps];
    int total = 0;
    for (int i = 0; i < mipMapSizes.length; i++){
        int size = (w * h * bpp) / 8;
        total += size;
        mipMapSizes[i] = size;
        w /= 2;
        h /= 2;
    }
    image.setMipMapSizes(mipMapSizes);
    image.setData(BufferUtils.createByteBuffer(total));
}
 
Example #6
Source File: KTXLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Object load(AssetInfo info) throws IOException {
    if (!(info.getKey() instanceof TextureKey)) {
        throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
    }

    InputStream in = null;
    try {
        in = info.openStream();
        Image img = load(in);
        return img;
    } finally {
        if (in != null) {
            in.close();
        }
    }
}
 
Example #7
Source File: TestAnisotropicFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static Texture2D createCheckerBoardTexture() {
    Image image = new Image(Format.RGBA8, 1024, 1024, BufferUtils.createByteBuffer(1024 * 1024 * 4), ColorSpace.sRGB);
    
    ImageRaster raster = ImageRaster.create(image);
    for (int y = 0; y < 1024; y++) {
        for (int x = 0; x < 1024; x++) {
            if (y < 512) {
                if (x < 512) {
                    raster.setPixel(x, y, ColorRGBA.Black);
                } else {
                    raster.setPixel(x, y, ColorRGBA.White);
                }
            } else {
                if (x < 512) {
                    raster.setPixel(x, y, ColorRGBA.White);
                } else {
                    raster.setPixel(x, y, ColorRGBA.Black);
                }
            }
        }
    }

    return new Texture2D(image);
}
 
Example #8
Source File: GdxRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void updateRenderTexture(FrameBuffer fb, RenderBuffer rb) {
        Texture tex = rb.getTexture();
        Image image = tex.getImage();
        if (image.isUpdateNeeded()) {
            updateTexImageData(image, tex.getType(), false);

            // NOTE: For depth textures, sets nearest/no-mips mode
            // Required to fix "framebuffer unsupported"
            // for old NVIDIA drivers!
            setupTextureParams(tex);
        }

        Gdx.gl20.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER,
                convertAttachmentSlot(rb.getSlot()),
                convertTextureType(tex.getType()),
                image.getId(),
                0);

//        RendererUtil.checkGLError();
    }
 
Example #9
Source File: CombinedTexture.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * This method merges two given textures. The result is stored in the
 * 'target' texture.
 * 
 * @param target
 *            the target texture
 * @param source
 *            the source texture
 */
private void merge(Texture2D target, Texture2D source) {
    if (target.getImage().getDepth() != source.getImage().getDepth()) {
        throw new IllegalArgumentException("Cannot merge images with different depths!");
    }
    Image sourceImage = source.getImage();
    Image targetImage = target.getImage();
    PixelInputOutput sourceIO = PixelIOFactory.getPixelIO(sourceImage.getFormat());
    PixelInputOutput targetIO = PixelIOFactory.getPixelIO(targetImage.getFormat());
    TexturePixel sourcePixel = new TexturePixel();
    TexturePixel targetPixel = new TexturePixel();
    int depth = target.getImage().getDepth() == 0 ? 1 : target.getImage().getDepth();

    for (int layerIndex = 0; layerIndex < depth; ++layerIndex) {
        for (int x = 0; x < sourceImage.getWidth(); ++x) {
            for (int y = 0; y < sourceImage.getHeight(); ++y) {
                sourceIO.read(sourceImage, layerIndex, sourcePixel, x, y);
                targetIO.read(targetImage, layerIndex, targetPixel, x, y);
                targetPixel.merge(sourcePixel);
                targetIO.write(targetImage, layerIndex, targetPixel, x, y);
            }
        }
    }
}
 
Example #10
Source File: MipMapGenerator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void resizeToPowerOf2(Image image){
    BufferedImage original = ImageToAwt.convert(image, false, true, 0);
    int potWidth = FastMath.nearestPowerOfTwo(image.getWidth());
    int potHeight = FastMath.nearestPowerOfTwo(image.getHeight());
    int potSize = Math.max(potWidth, potHeight);

    BufferedImage scaled = scaleDown(original, potSize, potSize);

    AWTLoader loader = new AWTLoader();
    Image output = loader.load(scaled, false);

    image.setWidth(potSize);
    image.setHeight(potSize);
    image.setDepth(0);
    image.setData(output.getData(0));
    image.setFormat(output.getFormat());
    image.setMipMapSizes(null);
}
 
Example #11
Source File: GdxRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void deleteImage(Image image) {
    int texId = image.getId();
    if (texId != -1) {
        intBuf1.put(0, texId);
        intBuf1.position(0).limit(1);

        if (verboseLogging) {
            logger.info("GLES20.glDeleteTexture(1, buffer)");
        }

        Gdx.gl20.glDeleteTextures(1, intBuf1);
        image.resetObject();

        statistics.onDeleteTexture();
    }
}
 
Example #12
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void updateRenderTexture(FrameBuffer fb, RenderBuffer rb) {
        Texture tex = rb.getTexture();
        Image image = tex.getImage();
        if (image.isUpdateNeeded()) {
            updateTexImageData(image, tex.getType(), false);

            // NOTE: For depth textures, sets nearest/no-mips mode
            // Required to fix "framebuffer unsupported"
            // for old NVIDIA drivers!
            setupTextureParams(tex);
        }

        GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER,
                convertAttachmentSlot(rb.getSlot()),
                convertTextureType(tex.getType()),
                image.getId(),
                0);

//        RendererUtil.checkGLError();
    }
 
Example #13
Source File: SkyFactory.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create a cube-mapped sky using six textures.
 *
 * @param assetManager from which to load materials
 * @param west texture for the western face of the cube
 * @param east texture for the eastern face of the cube
 * @param north texture for the northern face of the cube
 * @param south texture for the southern face of the cube
 * @param up texture for the top face of the cube
 * @param down texture for the bottom face of the cube
 * @param normalScale The normal scale is multiplied by the 3D normal to get
 * a texture coordinate. Use Vector3f.UNIT_XYZ to not apply and
 * transformation to the normal.
 * @param sphereRadius the sky sphere's radius: for the sky to be visible,
 * its radius must fall between the near and far planes of the camera's
 * frustum
 * @return a new spatial representing the sky, ready to be attached to the
 * scene graph
 */
public static Spatial createSky(AssetManager assetManager, Texture west,
        Texture east, Texture north, Texture south, Texture up,
        Texture down, Vector3f normalScale, float sphereRadius) {

    Image westImg = west.getImage();
    Image eastImg = east.getImage();
    Image northImg = north.getImage();
    Image southImg = south.getImage();
    Image upImg = up.getImage();
    Image downImg = down.getImage();

    checkImagesForCubeMap(westImg, eastImg, northImg, southImg, upImg, downImg);

    Image cubeImage = new Image(westImg.getFormat(), westImg.getWidth(), westImg.getHeight(), null, westImg.getColorSpace());

    cubeImage.addData(westImg.getData(0));
    cubeImage.addData(eastImg.getData(0));
    cubeImage.addData(downImg.getData(0));
    cubeImage.addData(upImg.getData(0));
    cubeImage.addData(southImg.getData(0));
    cubeImage.addData(northImg.getData(0));
    
    TextureCubeMap cubeMap = new TextureCubeMap(cubeImage);
    return createSky(assetManager, cubeMap, normalScale, EnvMapType.CubeMap, sphereRadius);
}
 
Example #14
Source File: DDSLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object load(AssetInfo info) throws IOException {
    if (!(info.getKey() instanceof TextureKey)) {
        throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
    }

    InputStream stream = null;
    try {
        stream = info.openStream();
        in = new LittleEndien(stream);
        loadHeader();
        if (texture3D) {
            ((TextureKey) info.getKey()).setTextureTypeHint(Type.ThreeDimensional);
        } else if (depth > 1) {
            ((TextureKey) info.getKey()).setTextureTypeHint(Type.CubeMap);
        }
        ArrayList<ByteBuffer> data = readData(((TextureKey) info.getKey()).isFlipY());
        return new Image(pixelFormat, width, height, depth, data, sizes);
    } finally {
        if (stream != null){
            stream.close();
        }
    }
}
 
Example #15
Source File: PaintTerrainToolAction.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void paintTexture(Terrain terrain, Vector3f markerLocation, float toolRadius, float toolWeight, int selectedTextureIndex) {
    if (selectedTextureIndex < 0 || markerLocation == null)
        return;
    
    int alphaIdx = selectedTextureIndex/4; // 4 = rgba = 4 textures
    Texture tex = getAlphaTexture(terrain, alphaIdx);
    Image image = tex.getImage();

    Vector2f UV = getPointPercentagePosition(terrain, markerLocation);

    // get the radius of the brush in pixel-percent
    float brushSize = toolRadius/(terrain.getTerrainSize()*((Node)terrain).getLocalScale().x);
    int texIndex = selectedTextureIndex - ((selectedTextureIndex/4)*4); // selectedTextureIndex/4 is an int floor, do not simplify the equation
    boolean erase = toolWeight<0;
    if (erase)
        toolWeight *= -1;

    doPaintAction(texIndex, image, UV, true, brushSize, erase, toolWeight);

    tex.getImage().setUpdateNeeded();
}
 
Example #16
Source File: ImageToAwt.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void createData(Image image, boolean mipmaps){
    int bpp = image.getFormat().getBitsPerPixel();
    int w = image.getWidth();
    int h = image.getHeight();
    if (!mipmaps){
        image.setData(BufferUtils.createByteBuffer(w*h*bpp/8));
        return;
    }
    int expectedMipmaps = 1 + (int) Math.ceil(Math.log(Math.max(h, w)) / LOG2);
    int[] mipMapSizes = new int[expectedMipmaps];
    int total = 0;
    for (int i = 0; i < mipMapSizes.length; i++){
        int size = (w * h * bpp) / 8;
        total += size;
        mipMapSizes[i] = size;
        w /= 2;
        h /= 2;
    }
    image.setMipMapSizes(mipMapSizes);
    image.setData(BufferUtils.createByteBuffer(total));
}
 
Example #17
Source File: AWTLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object load(AssetInfo info) throws IOException {
    if (ImageIO.getImageWritersBySuffix(info.getKey().getExtension()) != null){
        
        boolean flip = ((TextureKey) info.getKey()).isFlipY();
        InputStream in = null;
        try {
            in = info.openStream();
            Image img = load(in, flip);
            return img;
        } finally {
            if (in != null){
                in.close();
            }
        }
    }
    return null;
}
 
Example #18
Source File: DefaultImageRaster.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public DefaultImageRaster(Image image, int slice, int mipMapLevel, boolean convertToLinear) {
    int[] mipMapSizes = image.getMipMapSizes();
    int availableMips = mipMapSizes != null ? mipMapSizes.length : 1;
    
    if (mipMapLevel >= availableMips) {
        throw new IllegalStateException("Cannot create image raster for mipmap level #" + mipMapLevel + ". "
                                      + "Image only has " + availableMips + " mipmap levels.");
    }
    
    if (image.hasMipmaps()) {
        this.width  = Math.max(1, image.getWidth()  >> mipMapLevel);
        this.height = Math.max(1, image.getHeight() >> mipMapLevel);
        
        int mipOffset = 0;
        for (int i = 0; i < mipMapLevel; i++) {
            mipOffset += mipMapSizes[i];
        }
        
        this.offset = mipOffset;
    } else {
        this.width = image.getWidth();
        this.height = image.getHeight();
        this.offset = 0;
    }
    
    this.image = image;
    this.slice = slice;
    
    // Conversion to linear only needed if image's color space is sRGB.
    this.convertToLinear = convertToLinear && image.getColorSpace() == ColorSpace.sRGB;
    
    this.buffer = image.getData(slice);
    this.codec = ImageCodec.lookup(image.getFormat());
    
    if (codec instanceof ByteAlignedImageCodec || codec instanceof ByteOffsetImageCodec) {
        this.temp = new byte[codec.bpp];
    } else {
        this.temp = null;
    }
}
 
Example #19
Source File: Statistics.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
     * Called by the Renderer when a texture has been set.
     * 
     * @param image The image that was set
     * @param wasSwitched If true, the texture has required a state switch
     */
    public void onTextureUse(Image image, boolean wasSwitched){
        assert image.getId() >= 1;

//        if (!texturesUsed.contains(image.id))
//            texturesUsed.add(image.id);

        if (wasSwitched)
            numTextureBinds ++;
    }
 
Example #20
Source File: TextureAtlas.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Node insert(Image image) {
    if (!isLeaf()) {
        Node newNode = child[0].insert(image);

        if (newNode != null) {
            return newNode;
        }

        return child[1].insert(image);
    } else {
        if (occupied) {
            return null; // occupied
        }

        if (image.getWidth() > location.getWidth() || image.getHeight() > location.getHeight()) {
            return null; // does not fit
        }

        if (image.getWidth() == location.getWidth() && image.getHeight() == location.getHeight()) {
            occupied = true; // perfect fit
            return this;
        }

        int dw = location.getWidth() - image.getWidth();
        int dh = location.getHeight() - image.getHeight();

        if (dw > dh) {
            child[0] = new Node(location.getX(), location.getY(), image.getWidth(), location.getHeight());
            child[1] = new Node(location.getX() + image.getWidth(), location.getY(), location.getWidth() - image.getWidth(), location.getHeight());
        } else {
            child[0] = new Node(location.getX(), location.getY(), location.getWidth(), image.getHeight());
            child[1] = new Node(location.getX(), location.getY() + image.getHeight(), location.getWidth(), location.getHeight() - image.getHeight());
        }

        return child[0].insert(image);
    }
}
 
Example #21
Source File: LwjglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void deleteImage(Image image) {
    int texId = image.getId();
    if (texId != -1) {
        intBuf1.put(0, texId);
        intBuf1.position(0).limit(1);
        glDeleteTextures(intBuf1);
        image.resetObject();

        statistics.onDeleteTexture();
    }
}
 
Example #22
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void updateRenderTexture(FrameBuffer fb, RenderBuffer rb) {
    Texture tex = rb.getTexture();
    Image image = tex.getImage();
    if (image.isUpdateNeeded()) {
        // Check NPOT requirements
        checkNonPowerOfTwo(tex);

        updateTexImageData(image, tex.getType(), 0, false);

        // NOTE: For depth textures, sets nearest/no-mips mode
        // Required to fix "framebuffer unsupported"
        // for old NVIDIA drivers!
        setupTextureParams(0, tex);
    }

    if (rb.getLayer() < 0){
        glfbo.glFramebufferTexture2DEXT(GLFbo.GL_FRAMEBUFFER_EXT,
                convertAttachmentSlot(rb.getSlot()),
                convertTextureType(tex.getType(), image.getMultiSamples(), rb.getFace()),
                image.getId(),
                0);
    } else {
        glfbo.glFramebufferTextureLayerEXT(GLFbo.GL_FRAMEBUFFER_EXT, 
                convertAttachmentSlot(rb.getSlot()), 
                image.getId(), 
                0,
                rb.getLayer());
    }
}
 
Example #23
Source File: TriangulatedTexture.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * This method alters the images to fit them into UV coordinates of the
 * given target texture.
 * 
 * @param targetTexture
 *            the texture to whose UV coordinates we fit current images
 * @param blenderContext
 *            the blender context
 */
public void castToUVS(TriangulatedTexture targetTexture, BlenderContext blenderContext) {
    int[] sourceSize = new int[2], targetSize = new int[2];
    ImageLoader imageLoader = new ImageLoader();
    TextureHelper textureHelper = blenderContext.getHelper(TextureHelper.class);
    for (TriangleTextureElement entry : faceTextures) {
        TriangleTextureElement targetFaceTextureElement = targetTexture.getFaceTextureElement(entry.faceIndex);
        Vector2f[] dest = targetFaceTextureElement.uv;

        // get the sizes of the source and target images
        sourceSize[0] = entry.image.getWidth();
        sourceSize[1] = entry.image.getHeight();
        targetSize[0] = targetFaceTextureElement.image.getWidth();
        targetSize[1] = targetFaceTextureElement.image.getHeight();

        // create triangle transformation
        AffineTransform affineTransform = textureHelper.createAffineTransform(entry.uv, dest, sourceSize, targetSize);

        // compute the result texture
        BufferedImage sourceImage = ImageToAwt.convert(entry.image, false, true, 0);

        BufferedImage targetImage = new BufferedImage(targetSize[0], targetSize[1], sourceImage.getType());
        Graphics2D g = targetImage.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g.drawImage(sourceImage, affineTransform, null);
        g.dispose();

        Image output = imageLoader.load(targetImage, false);
        entry.image = output;
        entry.uv[0].set(dest[0]);
        entry.uv[1].set(dest[1]);
        entry.uv[2].set(dest[2]);
    }
}
 
Example #24
Source File: TestVideoPlayer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void drawFrame(VFrame frame){
    Image image = frame.getImage();
    frame.setImage(image);
    picture.setTexture(assetManager, frame, false);

    // note: this forces renderer to upload frame immediately,
    // since it is going to be returned to the video queue pool
    // it could be used again.
    renderer.setTexture(0, frame);
    videoQueue.returnFrame(frame);
    lastFrameTime = frame.getTime();
}
 
Example #25
Source File: GLImageFormats.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void formatCompSrgb(GLImageFormat[][] formatToGL, Image.Format format, 
                                   int glCompressedFormat,
                                   int glFormat, 
                                   int glDataType)
{
    formatToGL[1][format.ordinal()] = new GLImageFormat(glCompressedFormat, glFormat, glDataType, true);
}
 
Example #26
Source File: GLImageFormats.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void formatSrgb(GLImageFormat[][] formatToGL, Image.Format format, 
                               int glInternalFormat, 
                               int glFormat, 
                               int glDataType)
{
    formatToGL[1][format.ordinal()] = new GLImageFormat(glInternalFormat, glFormat, glDataType);
}
 
Example #27
Source File: SkyFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static void checkImage(Image image) {
//        if (image.getDepth() != 1)
//            throw new IllegalArgumentException("3D/Array images not allowed");

        if (image.getWidth() != image.getHeight()) {
            throw new IllegalArgumentException("Image width and height must be the same");
        }

        if (image.getMultiSamples() != 1) {
            throw new IllegalArgumentException("Multisample textures not allowed");
        }
    }
 
Example #28
Source File: OpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ViewPort setupViewBuffers(Camera cam, String viewName){
	
	if (environment != null){
		if (environment.getApplication() != null){
			// create offscreen framebuffer
	        FrameBuffer offBufferLeft = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
	        //offBufferLeft.setSrgb(true);
	        
	        //setup framebuffer's texture
	        Texture2D offTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
	        offTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
	        offTex.setMagFilter(Texture.MagFilter.Bilinear);

	        //setup framebuffer to use texture
	        offBufferLeft.setDepthBuffer(Image.Format.Depth);
	        offBufferLeft.setColorTexture(offTex);        
	        
	        ViewPort viewPort = environment.getApplication().getRenderManager().createPreView(viewName, cam);
	        viewPort.setClearFlags(true, true, true);
	        viewPort.setBackgroundColor(ColorRGBA.Black);
	        
	        Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
	        while(spatialIter.hasNext()){
	        	viewPort.attachScene(spatialIter.next());
	        }

	        //set viewport to render to offscreen framebuffer
	        viewPort.setOutputFrameBuffer(offBufferLeft);
	        return viewPort;
		} else {
			throw new IllegalStateException("This VR environment is not attached to any application.");
		}
	} else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
  	}  
}
 
Example #29
Source File: OpaqueComparatorTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Texture createTexture(String name) {
    ByteBuffer bb = BufferUtils.createByteBuffer(3);
    Image image = new Image(Format.RGB8, 1, 1, bb, ColorSpace.sRGB);
    Texture2D texture = new Texture2D(image);
    texture.setName(name);
    return texture;
}
 
Example #30
Source File: LuminancePixelInputOutput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void read(Image image, int layer, TexturePixel pixel, int index) {
    ByteBuffer data = image.getData(layer);
    switch (image.getFormat()) {
        case Luminance8:
            pixel.fromIntensity(data.get(index));
            break;
        case Luminance8Alpha8:
            pixel.fromIntensity(data.get(index));
            pixel.setAlpha(data.get(index + 1));
            break;
        case Luminance16:
            pixel.fromIntensity(data.getShort(index));
            break;
        case Luminance16Alpha16:
            pixel.fromIntensity(data.getShort(index));
            pixel.setAlpha(data.getShort(index + 2));
            break;
        case Luminance16F:
            pixel.intensity = FastMath.convertHalfToFloat(data.getShort(index));
            break;
        case Luminance16FAlpha16F:
            pixel.intensity = FastMath.convertHalfToFloat(data.getShort(index));
            pixel.alpha = FastMath.convertHalfToFloat(data.getShort(index + 2));
            break;
        case Luminance32F:
            pixel.intensity = Float.intBitsToFloat(data.getInt(index));
            break;
        default:
            throw new IllegalStateException("Unknown luminance format type.");
    }
}