Example usage for com.badlogic.gdx.graphics Texture draw

List of usage examples for com.badlogic.gdx.graphics Texture draw

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics Texture draw.

Prototype

public void draw(Pixmap pixmap, int x, int y) 

Source Link

Document

Draws the given Pixmap to the texture at position x, y.

Usage

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  w w w.j  a v a 2  s . c  o  m*/
    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.");
    }// www  .j  a v  a2s .  c om

    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:de.myreality.acid.gdx.GdxCellRenderer.java

License:Open Source License

@Override
public void drawCell(float x, float y, float width, float height, float r, float g, float b, float a) {
    Texture buffer = renderer.getBuffer();
    if (buffer != null) {

        Pixmap map = new Pixmap((int) width, (int) height, Format.RGBA8888);
        map.setColor(r, g, b, a);/*  w  w w . j a va  2s.c  o  m*/

        if (image != null) {
            Sprite sprite = new Sprite(image);
            sprite.setColor(r, g, b, a);
            image = sprite.getTexture();
            TextureData data = image.getTextureData();
            data.prepare();
            Pixmap tmp = data.consumePixmap();
            map.drawPixmap(tmp, 0, 0, tmp.getWidth(), tmp.getHeight(), 0, 0, (int) width, (int) height);
            image.getTextureData().disposePixmap();
        } else {
            map.fillRectangle(0, 0, (int) width, (int) height);
        }

        buffer.draw(map, (int) x, (int) y);
        map.dispose();
    }
}

From source file:graphics.common.ImageAsset.java

License:Open Source License

/**  Utility method for creating static constants-
  *//*w  w w.  java2 s.  co m*/
public static ImageAsset withColor(final int size, Colour c, Class source) {
    final Color gdxColor = new Color(c.r, c.g, c.b, c.a);
    final ImageAsset asset = new ImageAsset(source, c + "_img", "IMAGE_ASSET_") {
        protected State loadAsset() {
            final Texture tex = new Texture(size, size, Pixmap.Format.RGBA8888);
            final Pixmap draw = new Pixmap(size, size, Pixmap.Format.RGBA8888);
            draw.setColor(gdxColor);
            draw.fillRectangle(0, 0, size, size);
            tex.draw(draw, 0, 0);
            return loadAsset(tex, draw, null);
        }
    };
    return asset;
}

From source file:mobi.shad.s3lib.main.S3File.java

License:Apache License

/**
 * @param name//from   www  .java 2s.c o m
 * @param TextureSize
 * @param scaleMode   0 - FullScreen
 * @return
 */
public static Texture getFileTexture(String name, int TextureSize, int scaleMode) {
    Texture texture = new Texture(TextureSize, TextureSize, Pixmap.Format.RGBA8888);
    Pixmap px = new Pixmap(TextureSize, TextureSize, Pixmap.Format.RGBA8888);
    px.setColor(Color.RED);
    px.fill();
    try {
        px = new Pixmap(S3File.getFileHandle(name));
    } catch (Exception ex) {
        S3Log.error("S3File::getFileTexture", "Error open file texture: " + name, ex);
    }
    Pixmap px2 = new Pixmap(TextureSize, TextureSize, Pixmap.Format.RGBA8888);
    px2.drawPixmap(px, 0, 0, px.getWidth(), px.getHeight(), 0, 0, TextureSize, TextureSize);
    texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Linear);
    texture.draw(px2, 0, 0);
    return texture;
}

From source file:mobi.shad.s3lib.main.S3File.java

License:Apache License

/**
 * @param name//from   w  ww.  j  a  v  a  2  s  . co  m
 * @param TextureSize
 * @return
 */
public static Texture getFileTextureCenter(String name, int TextureSize) {
    Texture texture = new Texture(TextureSize, TextureSize, Pixmap.Format.RGBA8888);
    Pixmap px = new Pixmap(S3File.getFileHandle(name));
    texture.draw(px, (TextureSize / 2) - (px.getWidth() / 2), (TextureSize / 2) - (px.getHeight() / 2));
    return texture;
}

From source file:mobi.shad.s3lib.main.S3ResourceManager.java

License:Apache License

/**
 * Zwraca tekstur zaadowan z dysku/*from w  ww  .  j a va  2  s.  c o  m*/
 *
 * @param fileName
 * @return
 */
public static Texture getTexture(String fileName, int destAndroidResolution) {

    Texture texture;

    if (textureResuorce == null) {
        textureResuorce = new ArrayMap<String, TextureHandle>(20);
    }

    if (!textureResuorce.containsKey(fileName) || reBindProcess == true) {

        if (LOG) {
            S3Log.trace(TAG, "Load texture (def size: " + destAndroidResolution + ") from file: " + fileName,
                    3);
        }

        try {
            if (destAndroidResolution == 0) {
                FileHandle fileHandle = S3File.getFileHandle(fileName, true, false);
                texture = new Texture(fileHandle);
                texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
            } else {
                Pixmap px = new Pixmap(S3File.getFileHandle(fileName, true, false));
                Pixmap px2 = new Pixmap(destAndroidResolution, destAndroidResolution, Pixmap.Format.RGBA8888);
                px2.drawPixmap(px, 0, 0, px.getWidth(), px.getHeight(), 0, 0, destAndroidResolution,
                        destAndroidResolution);
                texture = new Texture(px2);
                texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
                texture.draw(px2, 0, 0);
            }

            if (USE_CACHE_RESOURCE) {
                if (textureResuorce.containsKey(fileName)) {
                    textureResuorce.removeKey(fileName);
                }
                TextureHandle textureHeandle = new TextureHandle();
                textureHeandle.fileName = fileName;
                textureHeandle.texture = texture;
                textureHeandle.width = texture.getWidth();
                textureHeandle.height = texture.getHeight();
                textureHeandle.defResolution = destAndroidResolution;
                textureResuorce.put(fileName, textureHeandle);
            }

        } catch (Exception e) {
            S3Log.error("S3ResourceManager::getTexture", "Error create texture data ....", e);

            Pixmap pixmap = new Pixmap(S3Constans.proceduralTextureSizeLow, S3Constans.proceduralTextureSizeLow,
                    Pixmap.Format.RGBA4444);
            pixmap.setColor(Color.RED);
            pixmap.fill();
            texture = new Texture(pixmap);
            texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
            texture.draw(pixmap, 0, 0);
        }
    } else {

        if (LOG) {
            S3Log.trace(TAG,
                    "Load texture from cache (def size: " + destAndroidResolution + ") from file: " + fileName,
                    2);
        }
        TextureHandle textureHandle = textureResuorce.get(fileName);
        texture = textureHandle.texture;
    }
    if (LOG) {
        S3Log.trace(TAG, "Texture size width: " + texture.getWidth() + "px height: " + texture.getHeight());
    }
    return texture;
}

From source file:mobi.shad.s3lib.main.S3ResourceManager.java

License:Apache License

/**
 * Zwraca tekstur zaadowan z dysku/*from  ww w  .  jav a 2s  . c  om*/
 *
 * @param fileName
 * @return
 */
public static TextureRegion getTextureRegion(String fileName) {

    TextureRegion textureRegion;

    if (regionResuorce == null) {
        regionResuorce = new ArrayMap<String, TextureRegion>(20);
    }

    if (!regionResuorce.containsKey(fileName) || reBindProcess == true) {

        if (LOG) {
            S3Log.trace(TAG, "Load textureRegion region: " + fileName, 3);
        }

        try {
            FileHandle fileHandle = S3File.getFileHandle(fileName, true, false);
            textureRegion = new TextureRegion(assetManager.get(fileHandle.path(), Texture.class));
            textureRegion.getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);

            if (USE_CACHE_RESOURCE) {
                if (regionResuorce.containsKey(fileName)) {
                    regionResuorce.removeKey(fileName);
                }
                regionResuorce.put(fileName, textureRegion);
            }

        } catch (Exception e) {
            S3Log.error("S3ResourceManager::getTexture", "Error create textureRegion data ....", e);

            try {
                Pixmap pixmap = new Pixmap(S3Constans.proceduralTextureSizeLow,
                        S3Constans.proceduralTextureSizeLow, Pixmap.Format.RGBA4444);
                pixmap.setColor(Color.RED);
                pixmap.fill();
                Texture text2 = new Texture(pixmap);
                text2.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
                text2.draw(pixmap, 0, 0);
                textureRegion = new TextureRegion(text2);
            } catch (Exception ex) {
                textureRegion = regionResuorce.firstValue();
            }
        }
    } else {

        if (LOG) {
            S3Log.trace(TAG, "Load textureRegion region from cache: " + fileName, 2);
        }
        textureRegion = regionResuorce.get(fileName);
    }
    return textureRegion;
}

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.");
    }/* w  w w  . jav a2s.  c om*/
    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 ww  .  j ava2 s .  c  om

    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();

        }
    });

}