Example usage for org.lwjgl.opengl GL11 glPixelStorei

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

Introduction

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

Prototype

public static void glPixelStorei(@NativeType("GLenum") int pname, @NativeType("GLint") int param) 

Source Link

Document

Sets the integer value of a pixel store parameter.

Usage

From source file:ion2d.INTexture2D.java

License:Open Source License

/**
 * Creates the actual OpenGL texture to memory
 *//*  w  w w .j  ava 2 s.  c o m*/
protected void createTexture() {
    this.convertToPowerOfTwo();

    if (this.texture != null) {
        IntBuffer tmp = BufferUtils.createIntBuffer(1);
        GL11.glGenTextures(tmp);
        this.id = tmp.get(0);
        this.bind();

        int src = GL11.GL_RGBA;

        if (!this.image.getBufferedImage().getColorModel().hasAlpha()) {
            src = GL11.GL_RGB;
        }

        GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

        this.setAntiAlias();
        GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);

        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, src, this.width, this.height, 0, src, GL11.GL_UNSIGNED_BYTE,
                this.texture);
    }
}

From source file:itdelatrisu.opsu.Utils.java

License:Open Source License

/**
 * Takes a screenshot./*from   w  w w . j av  a 2s  . c om*/
 * @author http://wiki.lwjgl.org/index.php?title=Taking_Screen_Shots
 */
public static void takeScreenShot() {
    // create the screenshot directory
    File dir = Options.getScreenshotDir();
    if (!dir.isDirectory()) {
        if (!dir.mkdir()) {
            ErrorHandler.error("Failed to create screenshot directory.", null, false);
            return;
        }
    }

    // create file name
    SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd_HHmmss");
    final File file = new File(dir,
            String.format("screenshot_%s.%s", date.format(new Date()), Options.getScreenshotFormat()));

    SoundController.playSound(SoundEffect.SHUTTER);

    // copy the screen to file
    final int width = Display.getWidth();
    final int height = Display.getHeight();
    final int bpp = 3; // assuming a 32-bit display with a byte each for red, green, blue, and alpha
    final ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp);
    GL11.glReadBuffer(GL11.GL_FRONT);
    GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
    GL11.glReadPixels(0, 0, width, height, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, buffer);
    new Thread() {
        @Override
        public void run() {
            try {
                BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
                for (int x = 0; x < width; x++) {
                    for (int y = 0; y < height; y++) {
                        int i = (x + (width * y)) * bpp;
                        int r = buffer.get(i) & 0xFF;
                        int g = buffer.get(i + 1) & 0xFF;
                        int b = buffer.get(i + 2) & 0xFF;
                        image.setRGB(x, height - (y + 1), (0xFF << 24) | (r << 16) | (g << 8) | b);
                    }
                }
                ImageIO.write(image, Options.getScreenshotFormat(), file);
            } catch (Exception e) {
                ErrorHandler.error("Failed to take a screenshot.", e, true);
            }
        }
    }.start();
}

From source file:itemrender.client.rendering.FBOHelper.java

License:MIT License

public void saveToFile(File file) {
    // Bind framebuffer texture
    GlStateManager.bindTexture(textureID);

    GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

    int width = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH);
    int height = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_HEIGHT);

    IntBuffer texture = BufferUtils.createIntBuffer(width * height);
    GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, texture);

    int[] texture_array = new int[width * height];
    texture.get(texture_array);/*w w  w. java2  s . com*/

    BufferedImage image = new BufferedImage(renderTextureSize, renderTextureSize, BufferedImage.TYPE_INT_ARGB);
    image.setRGB(0, 0, renderTextureSize, renderTextureSize, texture_array, 0, width);

    file.mkdirs();
    try {
        ImageIO.write(image, "png", file);
    } catch (Exception e) {
        // Do nothing
    }
}

From source file:itemrender.client.rendering.FBOHelper.java

License:MIT License

public String getBase64() {
    // Bind framebuffer texture
    GlStateManager.bindTexture(textureID);

    GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

    int width = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH);
    int height = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_HEIGHT);

    IntBuffer texture = BufferUtils.createIntBuffer(width * height);
    GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, texture);

    int[] texture_array = new int[width * height];
    texture.get(texture_array);//from   ww w .  j a v  a  2 s.  co m

    BufferedImage image = new BufferedImage(renderTextureSize, renderTextureSize, BufferedImage.TYPE_INT_ARGB);
    image.setRGB(0, 0, renderTextureSize, renderTextureSize, texture_array, 0, width);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        ImageIO.write(image, "PNG", out);
    } catch (IOException e) {
        // Do nothing
    }

    return Base64.encodeBase64String(out.toByteArray());
}

From source file:ivengine.Util.java

License:Creative Commons License

/**
 * Loads a texture from a URL <filename> into a texture unit <textureUnit>
 *///  w ww .j a va 2s .co  m
public static int loadPNGTexture(URL filename, int textureUnit) {
    ByteBuffer buf = null;
    int tWidth = 0;
    int tHeight = 0;

    try {
        // Open the PNG file as an InputStream
        InputStream in = filename.openStream();
        // Link the PNG decoder to this stream
        PNGDecoder decoder = new PNGDecoder(in);

        // Get the width and height of the texture
        tWidth = decoder.getWidth();
        tHeight = decoder.getHeight();

        // Decode the PNG file in a ByteBuffer
        buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
        decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
        buf.flip();

        in.close();
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(-1);
    }

    // Create a new texture object in memory and bind it
    int texId = GL11.glGenTextures();
    GL13.glActiveTexture(textureUnit);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);

    // All RGB bytes are aligned to each other and each component is 1 byte
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

    // Upload the texture data and generate mip maps (for scaling)
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tWidth, tHeight, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, buf);
    //GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);

    // Setup the ST coordinate system
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);

    // Setup what to do when the texture has to be scaled
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);

    return texId;
}

From source file:jake2.desktop.LWJGLAdapter.java

License:Open Source License

@Override
public void glPixelStorei(int i, int j) {
    GL11.glPixelStorei(i, j);
}

From source file:jpcsp.graphics.RE.RenderingEngineLwjgl.java

License:Open Source License

@Override
public void setPixelStore(int rowLength, int alignment) {
    if (!VideoEngine.getInstance().isUsexBRZFilter()) {
        GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, rowLength);
    }/*ww w  . ja va2s. com*/
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, alignment);
    GL11.glPixelStorei(GL11.GL_PACK_ROW_LENGTH, rowLength);
    GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, alignment);
}

From source file:kihira.tails.client.gui.GuiEditor.java

License:Open Source License

private int getColourAtPoint(int x, int y) {
    int[] pixelData;
    int pixels = 1;

    if (pixelBuffer == null) {
        pixelBuffer = BufferUtils.createIntBuffer(pixels);
    }//  w  w  w  . j a  v a 2 s  . co  m
    pixelData = new int[pixels];

    GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    pixelBuffer.clear();

    GL11.glReadPixels(x, mc.displayHeight - y, 1, 1, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV,
            pixelBuffer);

    pixelBuffer.get(pixelData);
    return pixelData[0];
}

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());//from w  w  w.  java 2 s .c o  m
    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:main.java.com.YeAJG.game.io.FileIOHandler.java

License:Open Source License

public static int loadPNGTexture(String filename, int textureUnit) throws IOException {
    ByteBuffer buf = null;//from  w  ww  .  j  ava 2s . c o m
    int tWidth = 0;
    int tHeight = 0;

    try {
        // Open the PNG file as an InputStream
        InputStream in = new FileInputStream(filename);
        // Link the PNG decoder to this stream
        PNGDecoder decoder = new PNGDecoder(in);

        // Get the width and height of the texture
        tWidth = decoder.getWidth();
        tHeight = decoder.getHeight();

        // Decode the PNG file in a ByteBuffer
        buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
        decoder.decode(buf, decoder.getWidth() * 4, PNGDecoder.RGBA);
        buf.flip();

        in.close();
    } catch (IOException e) {
        throw new IOException(e.getMessage());
    }

    // Create a new texture object in memory and bind it
    int texId = GL11.glGenTextures();
    GL13.glActiveTexture(textureUnit);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);

    // All RGB bytes are aligned to each other and each component is 1 byte
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

    // Upload the texture data and generate mip maps (for scaling)
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, tWidth, tHeight, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, buf);
    GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);

    // Setup the ST coordinate system
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);

    // Setup what to do when the texture has to be scaled
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);

    Game.exitOnGLError("loadPNGTexture");

    return texId;
}