Example usage for org.lwjgl.opengl GL12 GL_BGR

List of usage examples for org.lwjgl.opengl GL12 GL_BGR

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL12 GL_BGR.

Prototype

int GL_BGR

To view the source code for org.lwjgl.opengl GL12 GL_BGR.

Click Source Link

Document

Accepted by the format parameter of DrawPixels, GetTexImage, ReadPixels, TexImage1D, and TexImage2D.

Usage

From source file:com.ardor3d.scene.state.lwjgl.util.LwjglTextureUtil.java

License:Open Source License

public static int getGLPixelFormat(final ImageDataFormat format) {
    switch (format) {
    case RGBA://w  ww. j  av  a  2s .  c om
        return GL11.GL_RGBA;
    case RGB:
        return GL11.GL_RGB;
    case RG:
        return ARBTextureRg.GL_RG;
    case Alpha:
        return GL11.GL_ALPHA;
    case Luminance:
        return GL11.GL_LUMINANCE;
    case Intensity:
        return GL11.GL_INTENSITY;
    case LuminanceAlpha:
        return GL11.GL_LUMINANCE_ALPHA;
    case Depth:
        return GL11.GL_DEPTH_COMPONENT;
    case BGR:
        return GL12.GL_BGR;
    case BGRA:
        return GL12.GL_BGRA;
    case Red:
        return GL11.GL_RED;
    case Blue:
        return GL11.GL_BLUE;
    case Green:
        return GL11.GL_GREEN;
    case ColorIndex:
        return GL11.GL_COLOR_INDEX;
    case StencilIndex:
        return GL11.GL_STENCIL_INDEX;
    default:
        break;
    }
    throw new IllegalArgumentException("Incorrect format set: " + format);
}

From source file:kuake2.render.lwjgl.Misc.java

License:Open Source License

void GL_ScreenShot_f() {
    StringBuffer sb = new StringBuffer(FS.Gamedir() + "/scrshot/jake00.tga");
    FS.CreatePath(sb.toString());// w  w w .  ja  va  2  s  .com
    File file = new File(sb.toString());
    // find a valid file name
    int i = 0;
    int offset = sb.length() - 6;
    while (file.exists() && i++ < 100) {
        sb.setCharAt(offset, (char) ((i / 10) + '0'));
        sb.setCharAt(offset + 1, (char) ((i % 10) + '0'));
        file = new File(sb.toString());
    }
    if (i == 100) {
        VID.Printf(Defines.PRINT_ALL, "Clean up your screenshots\n");
        return;
    }

    try {
        RandomAccessFile out = new RandomAccessFile(file, "rw");
        FileChannel ch = out.getChannel();
        int fileLength = TGA_HEADER_SIZE + vid.width * vid.height * 3;
        out.setLength(fileLength);
        MappedByteBuffer image = ch.map(FileChannel.MapMode.READ_WRITE, 0, fileLength);

        // write the TGA header
        image.put(0, (byte) 0).put(1, (byte) 0);
        image.put(2, (byte) 2); // uncompressed type
        image.put(12, (byte) (vid.width & 0xFF)); // vid.width
        image.put(13, (byte) (vid.width >> 8)); // vid.width
        image.put(14, (byte) (vid.height & 0xFF)); // vid.height
        image.put(15, (byte) (vid.height >> 8)); // vid.height
        image.put(16, (byte) 24); // pixel size

        // go to image data position
        image.position(TGA_HEADER_SIZE);

        // change pixel alignment for reading
        if (vid.width % 4 != 0) {
            GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
        }

        // OpenGL 1.2+ supports the GL_BGR color format
        // check the GL_VERSION to use the TARGA BGR order if possible
        // e.g.: 1.5.2 NVIDIA 66.29
        if (gl_config.getOpenGLVersion() >= 1.2f) {
            // read the BGR values into the image buffer
            GL11.glReadPixels(0, 0, vid.width, vid.height, GL12.GL_BGR, GL11.GL_UNSIGNED_BYTE, image);
        } else {
            // read the RGB values into the image buffer
            GL11.glReadPixels(0, 0, vid.width, vid.height, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, image);
            // flip RGB to BGR
            byte tmp;
            for (i = TGA_HEADER_SIZE; i < fileLength; i += 3) {
                tmp = image.get(i);
                image.put(i, image.get(i + 2));
                image.put(i + 2, tmp);
            }
        }
        // reset to default alignment
        GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 4);
        // close the file channel
        ch.close();
    } catch (IOException e) {
        VID.Printf(Defines.PRINT_ALL, e.getMessage() + '\n');
    }

    VID.Printf(Defines.PRINT_ALL, "Wrote " + file + '\n');
}

From source file:org.fenggui.binding.render.lwjgl.LWJGLOpenGL.java

License:Open Source License

public void readPixels(int x, int y, int width, int height, ByteBuffer bgr) {
    GL11.glReadPixels(x, y, width, height, GL12.GL_BGR, GL11.GL_UNSIGNED_BYTE, bgr);
}

From source file:org.free.jake2.render.lwjgl.Misc.java

License:Open Source License

void GL_ScreenShot_f() {
    StringBuilder sb = new StringBuilder(FileSystem.Gamedir() + "/scrshot/jake00.tga");
    FileSystem.CreatePath(sb.toString());
    File file = new File(sb.toString());
    // find a valid file name
    int i = 0;// ww w. j  a va2 s .c  om
    int offset = sb.length() - 6;
    while (file.exists() && i++ < 100) {
        sb.setCharAt(offset, (char) ((i / 10) + '0'));
        sb.setCharAt(offset + 1, (char) ((i % 10) + '0'));
        file = new File(sb.toString());
    }
    if (i == 100) {
        VID.Printf(Defines.PRINT_ALL, "Clean up your screenshots\n");
        return;
    }

    try {
        RandomAccessFile out = new RandomAccessFile(file, "rw");
        FileChannel ch = out.getChannel();
        int fileLength = TGA_HEADER_SIZE + vid.width * vid.height * 3;
        out.setLength(fileLength);
        MappedByteBuffer image = ch.map(FileChannel.MapMode.READ_WRITE, 0, fileLength);

        // write the TGA header
        image.put(0, (byte) 0).put(1, (byte) 0);
        image.put(2, (byte) 2); // uncompressed type
        image.put(12, (byte) (vid.width & 0xFF)); // vid.width
        image.put(13, (byte) (vid.width >> 8)); // vid.width
        image.put(14, (byte) (vid.height & 0xFF)); // vid.height
        image.put(15, (byte) (vid.height >> 8)); // vid.height
        image.put(16, (byte) 24); // pixel size

        // go to image data position
        image.position(TGA_HEADER_SIZE);

        // change pixel alignment for reading
        if (vid.width % 4 != 0) {
            GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
        }

        // OpenGL 1.2+ supports the GL_BGR color format
        // check the GL_VERSION to use the TARGA BGR order if possible
        // e.g.: 1.5.2 NVIDIA 66.29
        if (gl_config.getOpenGLVersion() >= 1.2f) {
            // read the BGR values into the image buffer
            GL11.glReadPixels(0, 0, vid.width, vid.height, GL12.GL_BGR, GL11.GL_UNSIGNED_BYTE, image);
        } else {
            // read the RGB values into the image buffer
            GL11.glReadPixels(0, 0, vid.width, vid.height, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, image);
            // flip RGB to BGR
            byte tmp;
            for (i = TGA_HEADER_SIZE; i < fileLength; i += 3) {
                tmp = image.get(i);
                image.put(i, image.get(i + 2));
                image.put(i + 2, tmp);
            }
        }
        // reset to default alignment
        GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 4);
        // close the file channel
        ch.close();
    } catch (IOException e) {
        VID.Printf(Defines.PRINT_ALL, e.getMessage() + '\n');
    }

    VID.Printf(Defines.PRINT_ALL, "Wrote " + file + '\n');
}

From source file:org.interreg.docexplore.reader.gfx.Texture.java

License:Open Source License

public ByteBuffer toRGBABuffer(BufferedImage image, ByteBuffer data) {
    int psize = hasAlpha ? 4 : 3;
    if (data == null)
        data = BufferUtils.newUnsafeByteBuffer(psize * width * height);

    data.position(0);//from w  w  w  .j a  v a 2s .co m
    if (image.getType() == BufferedImage.TYPE_3BYTE_BGR && image.getWidth() == width
            && image.getHeight() == height) {
        dataType = GL12.GL_BGR;
        data.put(((DataBufferByte) image.getData().getDataBuffer()).getData());
    } else if (image.getType() == BufferedImage.TYPE_INT_ARGB && image.getWidth() == width
            && image.getHeight() == height) {
        dataType = GL12.GL_BGRA;
        data.asIntBuffer().put(((DataBufferInt) image.getData().getDataBuffer()).getData());
    } else if (image.getType() == BufferedImage.TYPE_4BYTE_ABGR && image.getWidth() == width
            && image.getHeight() == height) {
        dataType = GL11.GL_RGBA;
        data.put(((DataBufferByte) image.getData().getDataBuffer()).getData());
    } else {
        dataType = hasAlpha ? GL12.GL_BGRA : GL12.GL_BGR;
        int w = Math.min(width, image.getWidth()), h = Math.min(height, image.getHeight());
        for (int i = 0; i < w; i++)
            for (int j = 0; j < h; j++) {
                int col = image.getRGB(i, j);
                data.put(psize * (j * image.getWidth() + i), (byte) ((col >> 0) & 0xff));
                data.put(psize * (j * image.getWidth() + i) + 1, (byte) ((col >> 8) & 0xff));
                data.put(psize * (j * image.getWidth() + i) + 2, (byte) ((col >> 16) & 0xff));
                if (hasAlpha)
                    data.put(psize * (j * image.getWidth() + i) + 3, (byte) ((col >> 24) & 0xff));
            }
    }
    data.position(0);
    return data;
}

From source file:org.llama.jmf.JMFVideoImage.java

License:Open Source License

public void setSize(int videowidth, int videoheight, RGBFormat format) {
    log.info("set Size: " + videowidth + " " + videoheight);
    if (ready) {//from ww  w.  j av a2 s . c  o  m
        return;
    }

    // TODO: support more formats, test on linux/mac (might need ARGB?)

    switch (format.getBitsPerPixel()) {
    case 32:
        pixelformat = GL12.GL_BGRA;
        this.setFormat(Format.RGBA8);
        break;
    case 16:
        pixelformat = GL12.GL_BGRA;
        this.setFormat(Format.RGB5A1);
        break;
    case 24:
    default:
        pixelformat = GL12.GL_BGR;
        this.setFormat(Format.RGB8);
    }

    // TODO: not actually used yet.
    switch (format.getPixelStride()) {
    case 1:
        if (this.getFormat() == Format.RGB5A1) {
            /*
             * setFormat will be a jME method to set the native texture
             * image format. (currently always GL11.GL_UNSIGNED_BYTE)
             * Using formats with the same packing size will speed up
             * texture updates.
             */
            // TODO: this.setFormat(GL12.GL_UNSIGNED_SHORT_1_5_5_5);
            dataformat = GL12.GL_UNSIGNED_SHORT_1_5_5_5_REV;
            log.info("texture format: GL_UNSIGNED_SHORT_1_5_5_5_REV");
        } else {
            // TODO: this.setFormat(GL12.GL_INT_8_8_8_8_REV);
            dataformat = GL12.GL_UNSIGNED_INT_8_8_8_8_REV;
            log.info("texture format: GL_UNSIGNED_INT_8_8_8_8_REV");
        }

        break;
    case 3:
    case 4:
    default:
        dataformat = GL11.GL_UNSIGNED_BYTE;
        log.info("texture format: GL_UNSIGNED_BYTE");
    }

    if (format.getFlipped() == RGBFormat.FALSE) {
        flipped = true;
    }

    this.videowidth = videowidth;
    this.videoheight = videoheight;

    try {
        int size = Math.max(videoheight, videowidth);

        if (!FastMath.isPowerOfTwo(size)) {
            int newsize = 2;
            do {
                newsize <<= 1;
            } while (newsize < size);
            size = newsize;
        }
        this.width = size;
        this.height = size;

        data.clear();
        data.add(ByteBuffer.allocateDirect(size * size * 4).order(ByteOrder.nativeOrder()));

        ready = true;
        inittexture = true;
    } catch (Exception e) {
        e.printStackTrace();
        failed = true;
    }
    synchronized (this) {
        this.notifyAll();
    }

}

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) {/*from w  w  w .  j  a  v  a  2s  .  co m*/
    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;
}