Example usage for org.lwjgl.opengl GL11 glReadPixels

List of usage examples for org.lwjgl.opengl GL11 glReadPixels

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 glReadPixels.

Prototype

public static void glReadPixels(@NativeType("GLint") int x, @NativeType("GLint") int y,
        @NativeType("GLsizei") int width, @NativeType("GLsizei") int height, @NativeType("GLenum") int format,
        @NativeType("GLenum") int type, @NativeType("void *") float[] pixels) 

Source Link

Document

Array version of: #glReadPixels ReadPixels

Usage

From source file:playn.java.JavaGL20.java

License:Apache License

@Override
public void glReadPixels(int x, int y, int width, int height, int format, int type, Buffer pixels) {
    if (pixels instanceof ByteBuffer)
        GL11.glReadPixels(x, y, width, height, format, type, (ByteBuffer) pixels);
    else if (pixels instanceof ShortBuffer)
        GL11.glReadPixels(x, y, width, height, format, type, (ShortBuffer) pixels);
    else if (pixels instanceof IntBuffer)
        GL11.glReadPixels(x, y, width, height, format, type, (IntBuffer) pixels);
    else if (pixels instanceof FloatBuffer)
        GL11.glReadPixels(x, y, width, height, format, type, (FloatBuffer) pixels);
    else/*from   ww  w  .j av a2  s .c o m*/
        throw new RuntimeException(
                "Can't use " + pixels.getClass().getName() + " with this method. Use ByteBuffer, "
                        + "ShortBuffer, IntBuffer or FloatBuffer instead. Blame LWJGL");
}

From source file:playn.java.JavaGL20.java

License:Apache License

@Override
public void glReadPixels(int x, int y, int width, int height, int format, int type, int pixelsBufferOffset) {
    GL11.glReadPixels(x, y, width, height, format, type, pixelsBufferOffset);
}

From source file:processing.lwjgl.PGL.java

License:Open Source License

public void readPixels(int x, int y, int width, int height, int format, int type, Buffer buffer) {

    GL11.glReadPixels(x, y, width, height, format, type, (IntBuffer) buffer);
}

From source file:processing.lwjgl.PLWJGL.java

License:Open Source License

protected void readPixelsImpl(int x, int y, int width, int height, int format, int type, Buffer buffer) {
    GL11.glReadPixels(x, y, width, height, format, type, (IntBuffer) buffer);
}

From source file:processing.opengl.PLWJGL.java

License:Open Source License

@Override
protected void readPixelsImpl(int x, int y, int width, int height, int format, int type, Buffer buffer) {
    GL11.glReadPixels(x, y, width, height, format, type, (IntBuffer) buffer);
}

From source file:shadowmage.meim.client.gui.GuiModelEditor.java

License:Open Source License

protected void doSelection() {
    int posX = Mouse.getX();
    int posY = Mouse.getY();

    GL11.glDisable(GL11.GL_TEXTURE_2D);//from w  w  w  . jav  a2  s .  co  m
    GL11.glClearColor(1.f, 1.f, 1.f, 1.f);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GuiModelEditor.model.renderForSelection();

    byte[] pixelColorsb = new byte[3];
    ByteBuffer pixelColors = ByteBuffer.allocateDirect(3);
    GL11.glReadPixels(posX, posY, 1, 1, GL11.GL_RGB, GL11.GL_BYTE, pixelColors);

    for (int i = 0; i < 3; i++) {
        pixelColorsb[i] = pixelColors.get(i);
    }

    int r = pixelColorsb[0];
    int g = pixelColorsb[1];
    int b = pixelColorsb[2];

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    AWLog.logDebug("colors clicked on: " + r + "," + g + "," + b);
    int color = (r << 16) | (g << 8) | b;
    AWLog.logDebug("color out: " + color);

    GL11.glClearColor(.2f, .2f, .2f, 1.f);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    Primitive p = model.getPrimitive(color);
    if (p == null) {
        this.setSelectedPiece(null);
        this.setSelectedPrimitive(null);
    } else {
        this.setSelectedPrimitive(p);
    }
}

From source file:src.graphics.widgets.UINode.java

License:Open Source License

final public static ByteBuffer copyPixels(Box2D area, ByteBuffer pixels) {
    final int size = ((int) area.xdim()) * ((int) area.ydim()) * 4;
    if (pixels == null || pixels.capacity() != size) {
        pixels = BufferUtils.createByteBuffer(size);
    } else/* ww w.  j  a  v a  2  s . c  om*/
        pixels.rewind();
    GL11.glReadPixels((int) area.xpos(), (int) area.ypos(), (int) area.xdim(), (int) area.ydim(), GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, pixels);
    return pixels;
}

From source file:tectonicus.rasteriser.lwjgl.LwjglRasteriser.java

License:BSD License

public BufferedImage takeScreenshot2(final int startX, final int startY, final int width, final int height,
        ImageFormat imageFormat) {/*from   ww  w. j a  v  a 2  s  .  co  m*/
    ByteBuffer screenContentsBytes = ByteBuffer.allocateDirect(width * height * 4)
            .order(ByteOrder.LITTLE_ENDIAN);
    IntBuffer screenContents = screenContentsBytes.asIntBuffer();

    GL11.glReadPixels(startX, startY, width, height, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, screenContents);

    int[] pixels = new int[width * height];
    screenContents.get(pixels);

    final int pixelFormat = imageFormat.hasAlpha() ? BufferedImage.TYPE_4BYTE_ABGR
            : BufferedImage.TYPE_3BYTE_BGR;
    BufferedImage img = new BufferedImage(width, height, pixelFormat);
    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            final int rgba = pixels[x + y * width];

            img.setRGB(x, height - 1 - y, rgba);
        }
    }

    return img;
}

From source file:tectonicus.rasteriser.lwjgl.LwjglRasteriser.java

License:BSD License

public BufferedImage takeScreenshot(final int startX, final int startY, final int width, final int height,
        ImageFormat imageFormat) {// ww w . j  a  va2s  . c om
    BufferedImage img = null;

    ByteBuffer screenContentsBytes = ByteBuffer.allocateDirect(width * height * 4)
            .order(ByteOrder.LITTLE_ENDIAN);
    IntBuffer screenContents = screenContentsBytes.asIntBuffer();

    if (imageFormat.hasAlpha()) {
        img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        int[] pixels = ((DataBufferInt) (img.getRaster().getDataBuffer())).getData();

        GL11.glReadPixels(startX, startY, width, height, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, screenContents);

        for (int y = startY; y < startY + height; y++) {
            screenContents.position(y * width);
            screenContents.get(pixels, (height - y - 1) * width, width);
        }
    } else {
        img = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
        byte[] pixels = ((DataBufferByte) (img.getRaster().getDataBuffer())).getData();

        GL11.glReadPixels(startX, startY, width, height, GL12.GL_BGR, GL11.GL_UNSIGNED_BYTE, screenContents);

        for (int y = startY; y < startY + height; y++) {
            screenContentsBytes.position(y * width * 3);
            screenContentsBytes.get(pixels, (height - y - 1) * width * 3, width * 3);
        }
    }

    return img;
}

From source file:tk.ivybits.engine.gl.GL.java

License:Open Source License

public static void glReadPixels(int a, int b, int c, int d, int e, int f, DoubleBuffer g) {
    GL11.glReadPixels(a, b, c, d, e, f, g);
}