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:com.github.kajdreef.mazerunnermvn.Object.GameObject.java

protected void setTextureUnit(Texture texture, int textureUnit) {
    // Create a new texture object in memory and bind it
    texId = GL11.glGenTextures();/*  w w w  .j av  a 2  s  .  c  o m*/
    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, texture.getWidth(), texture.getHeight(), 0,
            GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, texture.getTexBuffer());
    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_LINEAR_MIPMAP_LINEAR);
}

From source file:com.google.gapid.glviewer.gl.Texture.java

License:Apache License

public Texture loadData(int width, int height, int internalFormat, int format, int type, ByteBuffer data) {
    bind();//from   w w w  . jav a 2  s . c o  m
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    GL11.glTexImage2D(target, 0, internalFormat, width, height, 0, format, type, data);
    return this;
}

From source file:com.kauridev.lunarfever.graphics.TextureLoader.java

License:Open Source License

public static Texture loadTexture(String file) {
    Texture texture = cache.get(file);/*w  w  w  .ja  v  a2 s .com*/

    if (texture != null && texture.getTexture().valid()) {
        return texture;
    }

    BufferedImage image = loadImage(file);

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    int id = GL11.glGenTextures();

    // bind
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);

    // set filter
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

    // set wrap
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);

    // set unpack alignment
    GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

    // send data to gpu
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, loadBuffer(image));

    // Create texture
    texture = new Texture(id, image.getWidth(), image.getHeight());

    cache.put(file, texture);
    return texture;
}

From source file:com.telinc1.rpjg.texture.Texture.java

License:Apache License

protected void setUnpackAlignment() {
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
}

From source file:com.voxelplugineering.voxelsniper.util.TextureUtilities.java

License:Open Source License

public static int loadPNGTexture(File file, int textureUnit) {
    ByteBuffer buf = null;/*w w w  .  ja v  a  2 s  . com*/
    int tWidth = 0;
    int tHeight = 0;

    try {
        BufferedImage image = ImageIO.read(file);
        tWidth = image.getWidth();
        tHeight = image.getHeight();
        buf = imageToRGBABuffer(image);
    } catch (IOException e) {
        e.printStackTrace();
        if (file.getName().endsWith("debug.png")) {
            System.exit(-1);
        } else {
            return debugTexture;
        }
    }

    // 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_MIPMAP_NEAREST);

    OpenGLUtilities.checkGLError("loadPNGTexture");
    if (file.getName().endsWith("debug.png")) {
        debugTexture = texId;
    }
    return texId;
}

From source file:com.xrbpowered.gl.examples.GLLife.java

License:Open Source License

private void resetBuffers(boolean fill) {
    if (buffers[0] != null)
        buffers[0].destroy();/*www. j av  a2  s .co m*/
    if (buffers[1] != null)
        buffers[1].destroy();

    int width = getTargetWidth();
    int height = getTargetHeight();
    buffers[0] = new OffscreenBuffers(width, height, false);
    buffers[1] = new OffscreenBuffers(width, height, false);
    targetBuffer = 1;
    turn = 0;

    IntBuffer intBuffer = ByteBuffer.allocateDirect(4 * width * height).order(ByteOrder.nativeOrder())
            .asIntBuffer();
    int[] pixels = new int[width * height];
    for (int x = 1; x < width; x++)
        for (int y = 1; y < height; y++) {
            int v = fill && random.nextInt(27) == 0 ? 0xffffffff : 0xff000000;
            pixels[y * width + x] = v;
        }
    intBuffer.put(pixels);
    intBuffer.flip();

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, buffers[0].getColorTexId());
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL12.GL_BGRA,
            GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuffer);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, buffers[1].getColorTexId());
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL12.GL_BGRA,
            GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuffer);
}

From source file:com.xrbpowered.gl.examples.GLLife.java

License:Open Source License

private void addGlider(int x, int y, int width, int height, int[] pixels) {
    IntBuffer intBuffer = ByteBuffer.allocateDirect(4 * width * height).order(ByteOrder.nativeOrder())
            .asIntBuffer();//  w ww  . j  av a2 s. co  m
    intBuffer.put(pixels);
    intBuffer.flip();

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, buffers[1 - targetBuffer].getColorTexId());
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, x, y, width, height, GL12.GL_BGRA,
            GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuffer);
}

From source file:com.xrbpowered.gl.res.textures.BufferTexture.java

License:Open Source License

public void update() {
    if (this.imgBuffer == null)
        createBuffers();/*from w  ww  . j  av  a  2s  .  c  o m*/

    if (updateBuffer((Graphics2D) imgBuffer.getGraphics(), width, height)) {
        pixels = imgBuffer.getRGB(0, 0, width, height, pixels, 0, width);
        intBuffer.put(pixels);
        intBuffer.flip();

        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, getId());

        GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL12.GL_BGRA,
                GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuffer);
        //         GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); // TODO needless mipmaps?
    }

    if (!staticBuffers)
        destroyBuffers();
}

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public void pixelStorei(int pname, int param) {
    GL11.glPixelStorei(translatePixelStoreName(pname), param);
}

From source file:de.ikosa.mars.viewer.glviewer.engine.GLTextureArrayBuilder.java

License:Open Source License

@Override
public GLTextureArray createTexture() {
    try {//from   w w  w. ja  va 2 s  .  co m
        int files = filePaths.length;
        byte[][] imageData = new byte[files][];
        int totalSize = 0;
        int imageWidth = 0;
        int imageHeight = 0;
        // read in files
        for (int file = 0; file < files; file++) {
            InputStream inputStream = new FileInputStream(filePaths[file]);
            BufferedImage image = ImageIO.read(inputStream);

            if (file > 0)
                if (imageWidth != image.getWidth() | imageHeight != image.getHeight())
                    ML.f("Incompatible images in 3D texture...");

            imageWidth = image.getWidth();
            imageHeight = image.getHeight();

            imageData[file] = GLPNGLoader.loadPNG(image);
            totalSize += imageData[file].length;
        }

        // store in consecutive buffer
        ByteBuffer buffer = ByteBuffer.allocateDirect(totalSize);
        for (int file = 0; file < files; file++) {
            byte[] singleImageData = imageData[file];
            for (int i = 0; i < singleImageData.length; i++)
                buffer.put(singleImageData[i]);
        }

        buffer.flip();

        int textureId = GL11.glGenTextures();
        GLRenderer2Stage.errorCheck("generating texture id");

        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GLRenderer2Stage.errorCheck("activating texture image unit");

        GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, textureId);
        GLRenderer2Stage.errorCheck("binding 2d texture array");

        GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
        GLRenderer2Stage.errorCheck("setting unpack aligment");

        GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL11.GL_RGBA, imageWidth, imageHeight, files, 0,
                GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
        GLRenderer2Stage.errorCheck("storing 2d texture array data");

        GL30.glGenerateMipmap(GL30.GL_TEXTURE_2D_ARRAY);
        GLRenderer2Stage.errorCheck("generating 2d texture array mipmaps");

        GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0);
        GLRenderer2Stage.errorCheck("unbinding 2d texture array");

        return new GLTextureArray(name, textureId);
    } catch (Exception e) {
        ML.f(e);
    }
    return null;
}