Example usage for com.badlogic.gdx.graphics.g2d TextureRegion setTexture

List of usage examples for com.badlogic.gdx.graphics.g2d TextureRegion setTexture

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d TextureRegion setTexture.

Prototype

public void setTexture(Texture texture) 

Source Link

Usage

From source file:com.badlogic.gdx.tests.g3d.shadows.system.BaseShadowSystem.java

License:Apache License

/** Set viewport according to allocator.
 * @param lp LightProperties to process.
 * @param cameraViewport Set camera viewport if true. */
protected void processViewport(LightProperties lp, boolean cameraViewport) {
    Camera camera = lp.camera;//from w w  w . ja  v a2 s  .  c om
    ShadowMapRegion r = allocator.nextResult(currentLight);

    if (r == null)
        return;

    TextureRegion region = lp.region;
    region.setTexture(frameBuffers[currentPass].getColorBufferTexture());

    // We don't use HdpiUtils
    // gl commands related to shadow map size and not to screen size
    Gdx.gl.glViewport(r.x, r.y, r.width, r.height);
    Gdx.gl.glScissor(r.x + 1, r.y + 1, r.width - 2, r.height - 2);
    region.setRegion(r.x, r.y, r.width, r.height);

    if (cameraViewport) {
        camera.viewportHeight = r.height;
        camera.viewportWidth = r.width;
        camera.update();
    }
}

From source file:com.mygdx.java.utils.ImageUtils.java

License:Apache License

public static void setScreenTextureRegion(TextureRegion textureRegion, byte[] bytes) {

    if (textureRegion == null) {
        throw new IllegalArgumentException("Input the TextureRegion is null.");
    }//from   www. j a  va  2 s  .c om
    Texture tempTexture = textureRegion.getTexture();
    if (tempTexture != null) {
        tempTexture.dispose();
        tempTexture = null;
    }

    Pixmap pixmap = new Pixmap(bytes, 0, bytes.length);
    int width = pixmap.getWidth();
    int height = pixmap.getHeight();

    Texture texture = new Texture(width, height, pixmap.getFormat());
    texture.draw(pixmap, 0, 0);
    textureRegion.setTexture(texture);
    textureRegion.setRegion(0, 0, width, height);
    pixmap.dispose();

}

From source file:com.mygdx.java.utils.ImageUtils.java

License:Apache License

public static void setScreenTextureRegionInThread(final TextureRegion textureRegion, final byte[] bytes) {

    if (textureRegion == null) {
        throw new IllegalArgumentException("Input the TextureRegion is null.");
    }/*ww w . j a v  a2 s  . c o  m*/

    Gdx.app.postRunnable(new Runnable() {

        @Override
        public void run() {

            Texture tempTexture = textureRegion.getTexture();
            if (tempTexture != null) {
                tempTexture.dispose();
                textureRegion.setTexture(null);
            }

            Pixmap pixmap = new Pixmap(bytes, 0, bytes.length);
            int width = pixmap.getWidth();
            int height = pixmap.getHeight();
            // pixmap.setBlending(Blending.None);
            // Texture texture = new Texture(width, height,
            // pixmap.getFormat());
            Texture texture = new Texture(pixmap, true);
            texture.draw(pixmap, 0, 0);
            textureRegion.setTexture(texture);
            textureRegion.setRegion(0, 0, width, height);
            pixmap.dispose();

        }
    });

}

From source file:test.ImageUtils.java

License:Apache License

public static void setScreenTextureRegion(final TextureRegion textureRegion) {

    if (textureRegion == null) {
        throw new IllegalArgumentException("Input the TextureRegion is null.");
    }//from  w  ww. ja  v  a 2s  .co  m
    Texture tempTexture = textureRegion.getTexture();
    if (tempTexture != null) {
        tempTexture.dispose();
    }
    BufferedImage bufferedImage = ImageUtils.getScreenBufferedImage();
    byte[] bytes = ImageUtils.getBufferedImageBytes(bufferedImage);
    Pixmap pixmap = new Pixmap(bytes, 0, bytes.length);
    int width = pixmap.getWidth();
    int height = pixmap.getHeight();

    Texture texture = new Texture(width, height, pixmap.getFormat());
    texture.draw(pixmap, 0, 0);
    textureRegion.setTexture(texture);
    textureRegion.setRegion(0, 0, width, height);
    pixmap.dispose();

}

From source file:test.ImageUtils.java

License:Apache License

public static void setScreenTextureRegionInThread(final TextureRegion textureRegion) {

    if (textureRegion == null) {
        throw new IllegalArgumentException("Input the TextureRegion is null.");
    }/*from   w w  w  . jav a  2s . c  o m*/

    Gdx.app.postRunnable(new Runnable() {

        @Override
        public void run() {

            Texture tempTexture = textureRegion.getTexture();
            if (tempTexture != null) {
                tempTexture.dispose();
            }
            BufferedImage bufferedImage = ImageUtils.getScreenBufferedImage();
            byte[] bytes = ImageUtils.getBufferedImageBytes(bufferedImage);
            Pixmap pixmap = new Pixmap(bytes, 0, bytes.length);
            int width = pixmap.getWidth();
            int height = pixmap.getHeight();

            Texture texture = new Texture(width, height, pixmap.getFormat());
            texture.draw(pixmap, 0, 0);
            textureRegion.setTexture(texture);
            textureRegion.setRegion(0, 0, width, height);
            pixmap.dispose();

        }
    });

}