Example usage for com.badlogic.gdx.graphics GL20 GL_UNSIGNED_BYTE

List of usage examples for com.badlogic.gdx.graphics GL20 GL_UNSIGNED_BYTE

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics GL20 GL_UNSIGNED_BYTE.

Prototype

int GL_UNSIGNED_BYTE

To view the source code for com.badlogic.gdx.graphics GL20 GL_UNSIGNED_BYTE.

Click Source Link

Usage

From source file:com.agateau.utils.ScreenshotCreator.java

License:Apache License

private static Pixmap takeScreenshot() {
    int width = Gdx.graphics.getWidth();
    int height = Gdx.graphics.getHeight();
    if (sPixmap == null) {
        init();/*from ww  w . j a v a 2s. c o m*/
    }
    Gdx.gl.glReadPixels(0, 0, width, height, GL20.GL_RGB, GL20.GL_UNSIGNED_BYTE, sPixmap.getPixels());
    return sPixmap;
}

From source file:com.googlecode.gdxquake2.game.render.GlRenderer.java

License:Open Source License

public void uploadImage(Image image) {
    GlState.checkError("before upload image");
    image.has_alpha = true;/* w w w  . j a v a 2 s  .c o  m*/
    image.complete = true;

    Images.GL_Bind(image.texnum);
    if (image.type == com.googlecode.gdxquake2.game.common.QuakeImage.it_pic) {
        GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP_TO_EDGE);
        GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP_TO_EDGE);
        GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
        texImage2D(image.pixmap, GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE);
        image.upload_width = image.width;
        image.upload_height = image.height;
    } else if (image.type == com.googlecode.gdxquake2.game.common.QuakeImage.it_sky) {
        GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP_TO_EDGE);
        GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP_TO_EDGE);
        GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
        if (Images.skyTarget == null)
            Images.skyTarget = image;
        Images.GL_Bind(Images.skyTarget.texnum);
        if (Images.skyTarget.upload_width != 6 * image.width) {
            texImage2D(new Pixmap(6 * image.width, image.height, Pixmap.Format.RGBA8888), GL20.GL_TEXTURE_2D, 0,
                    GL20.GL_RGBA, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE);
            Images.skyTarget.upload_width = 6 * image.width;
        }
        Images.skyTarget.upload_height = image.height;
        texSubImage2D(image.pixmap, GL20.GL_TEXTURE_2D, 0, image.width * image.skyIndex, 0, GL20.GL_RGBA,
                GL20.GL_UNSIGNED_BYTE);
    } else {
        GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
        GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
        GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER,
                GL11.GL_LINEAR_MIPMAP_LINEAR);
        GlState.gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        int p2size = 1 << ((int) Math.ceil(Math.log(Math.max(image.width, image.height)) / Math.log(2)));
        image.upload_width = p2size;
        image.upload_height = p2size;

        int level = 0;
        do {
            Pixmap canvas = getTmpImage(p2size, p2size);
            canvas.setColor(0x88888888);
            canvas.fill();
            try {
                canvas.drawPixmap(image.pixmap, 0, 0, image.pixmap.getWidth(), image.pixmap.getHeight(), 0, 0,
                        p2size, p2size);
            } catch (Exception e) {
                GdxQuake2.tools.log("Error rendering image " + image.name + "; size: " + p2size + " MSG: " + e);
                break;
            }
            texImage2D(canvas, GL20.GL_TEXTURE_2D, level++, GL20.GL_RGBA, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE);
            p2size /= 2;
        } while (p2size > 0);
    }

    GLDebug.checkError(GlState.gl, "uploadImage");
}

From source file:com.heaven7.fantastictank.test.ScreenUtils.java

License:Apache License

public static Pixmap getFrameBufferPixmap(int x, int y, int w, int h) {
    Gdx.gl.glPixelStorei(GL20.GL_PACK_ALIGNMENT, 1);

    final Pixmap pixmap = new Pixmap(w, h, Format.RGBA8888);
    ByteBuffer pixels = pixmap.getPixels();
    Gdx.gl.glReadPixels(x, y, w, h, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels);

    return pixmap;
}

From source file:com.heaven7.fantastictank.test.ScreenUtils.java

License:Apache License

/** Returns a portion of the default framebuffer contents specified by x, y, width and height, as a byte[] array with a length
 * equal to the specified width * height * 4. The byte[] will always contain RGBA8888 data. If the width and height specified
 * are larger than the framebuffer dimensions, the Texture will be padded accordingly. Pixels that fall outside of the current
 * screen will have RGBA values of 0. Because of differences in screen and image origins the framebuffer contents should be
 * flipped along the Y axis if you intend save them to disk as a bitmap. Flipping is not cheap operation, so use this
 * functionality wisely.//from w  w w.j  a  v  a 2 s .c o m
 * 
 * @param flipY whether to flip pixels along Y axis */
public static byte[] getFrameBufferPixels(int x, int y, int w, int h, boolean flipY) {
    Gdx.gl.glPixelStorei(GL20.GL_PACK_ALIGNMENT, 1);
    final ByteBuffer pixels = BufferUtils.newByteBuffer(w * h * 4);
    Gdx.gl.glReadPixels(x, y, w, h, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels);
    final int numBytes = w * h * 4;
    byte[] lines = new byte[numBytes];
    if (flipY) {
        final int numBytesPerLine = w * 4;
        for (int i = 0; i < h; i++) {
            pixels.position((h - i - 1) * numBytesPerLine);
            pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
        }
    } else {
        pixels.clear();
        pixels.get(lines);
    }
    return lines;

}

From source file:com.softwaresemantics.diyglsllwp.ShaderGalleryActivity.java

License:Creative Commons License

/**
 *
 * *//*from  w ww .  j  a v a 2  s  . co m*/
public Pixmap getScreenshot(int x, int y, int w, int h, boolean flipY) {
    Gdx.gl20.glPixelStorei(GL20.GL_PACK_ALIGNMENT, 1);

    final Pixmap pixmap = new Pixmap(w, h, Format.RGBA8888);
    ByteBuffer pixels = pixmap.getPixels();

    Gdx.gl20.glReadPixels(x, y, w, h, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels);

    final int numBytes = w * h * 4;
    byte[] lines = new byte[numBytes];
    if (flipY) {
        final int numBytesPerLine = w * 4;
        for (int i = 0; i < h; i++) {
            pixels.position((h - i - 1) * numBytesPerLine);
            pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
        }
        pixels.clear();
        pixels.put(lines);
    } else {
        pixels.clear();
        pixels.get(lines);
    }

    return pixmap;
}

From source file:com.toet.TinyVoxel.android.AndroidConfig.java

@Override
public void uploadPalette(int width, int height) {
    paletteBuffer.rewind();//  w ww  . j a v  a2  s  .co m
    Gdx.graphics.getGL20().glPixelStorei(GL20.GL_UNPACK_ALIGNMENT, 1);
    Gdx.graphics.getGL20().glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, width, height, 0, GL20.GL_RGBA,
            GL20.GL_UNSIGNED_BYTE, paletteBuffer);
}

From source file:com.toet.TinyVoxel.android.AndroidConfig.java

@Override
public void uploadSinglePalette(int paletteId) {
    tinyPaletteBuffer.rewind();/*  w  ww .  ja v  a2  s  .  com*/
    Gdx.graphics.getGL20().glPixelStorei(GL20.GL_UNPACK_ALIGNMENT, 1);
    Gdx.graphics.getGL20().glTexSubImage2D(GL20.GL_TEXTURE_2D, 0, 0, paletteId, Config.TINY_GRID_TOTAL, 1,
            GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, tinyPaletteBuffer);
}

From source file:com.watabou.glwrap.NoosaTexture.java

License:Open Source License

public void pixels(int w, int h, int[] pixels) {

    // FIXME//from w  ww.  ja  va 2  s.  c om
    bind();

    IntBuffer imageBuffer = ByteBuffer.allocateDirect(w * h * 4).order(ByteOrder.nativeOrder()).asIntBuffer();
    imageBuffer.put(pixels);
    imageBuffer.position(0);

    Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, w, h, 0, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE,
            imageBuffer);
}

From source file:com.watabou.glwrap.NoosaTexture.java

License:Open Source License

public void pixels(int w, int h, byte[] pixels) {

    bind();/*  w  ww . j av a 2 s . c o m*/

    ByteBuffer imageBuffer = ByteBuffer.allocateDirect(w * h).order(ByteOrder.nativeOrder());
    imageBuffer.put(pixels);
    imageBuffer.position(0);

    Gdx.gl.glPixelStorei(GL20.GL_UNPACK_ALIGNMENT, 1);

    Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_ALPHA, w, h, 0, GL20.GL_ALPHA, GL20.GL_UNSIGNED_BYTE,
            imageBuffer);
}

From source file:mobi.shad.s3lib.gfx.util.ScreenShot.java

License:Apache License

/**
 * @param x//  w w  w  . ja  v  a  2  s  . c  o  m
 * @param y
 * @param w
 * @param h
 * @param flipY
 * @return
 */
public static Pixmap getScreenShot(int x, int y, int w, int h, boolean flipY) {
    Gdx.gl.glPixelStorei(GL20.GL_PACK_ALIGNMENT, 1);

    final Pixmap pixmap = new Pixmap(w, h, Format.RGBA8888);
    ByteBuffer pixels = pixmap.getPixels();
    Gdx.gl.glReadPixels(x, y, w, h, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels);

    final int numBytes = w * h * 4;
    byte[] lines = new byte[numBytes];
    if (flipY) {
        final int numBytesPerLine = w * 4;
        for (int i = 0; i < h; i++) {
            pixels.position((h - i - 1) * numBytesPerLine);
            pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
        }
        pixels.clear();
        pixels.put(lines);
    } else {
        pixels.clear();
        pixels.get(lines);
    }

    return pixmap;
}