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:de.ikosa.mars.viewer.glviewer.engine.GLTextureBuilder.java

License:Open Source License

public static GLTexture createEmptyTexture(String name, int width, int height, byte r, byte g, byte b, byte a) {
    try {/*from   w  w  w  .  j  a  va 2 s .c o  m*/
        int textureId = GL11.glGenTextures();

        ByteBuffer buffer = ByteBuffer.allocateDirect(width * height * 4);

        for (int i = 0; i < width * height; i++) {
            buffer.put(r);
            buffer.put(g);
            buffer.put(b);
            buffer.put(a);
        }
        buffer.flip();

        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
        GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
                GL11.GL_UNSIGNED_BYTE, buffer);
        GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

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

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

License:Open Source License

public static GLTexture createEmptyTexture(String name, int width, int height, float initial) {
    try {/* ww w.  j  a  va  2s .  c o m*/
        int textureId = GL11.glGenTextures();

        ByteBuffer buffer = ByteBuffer.allocateDirect(width * height * 4);

        for (int i = 0; i < width * height * 4; i++) {
            buffer.put((byte) 0);
        }
        buffer.flip();

        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
        GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_DEPTH_COMPONENT, width, height, 0,
                GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, buffer);
        GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

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

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

License:Open Source License

private int createRGBTexture(BufferedImage image, byte[] x) {
    ByteBuffer buffer;//from   w w  w. j a v  a 2 s  .  c  o  m

    buffer = ByteBuffer.allocateDirect(x.length);
    for (int i = 0; i < x.length; i++) {
        buffer.put(x[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(GL11.GL_TEXTURE_2D, textureId);
    GLRenderer2Stage.errorCheck("binding 2d texture");

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

    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, buffer);
    GLRenderer2Stage.errorCheck("storing 2d texture data");

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

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    GLRenderer2Stage.errorCheck("unbinding 2d texture array");
    return textureId;
}

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

License:Open Source License

private int createGrayscaleTexture(BufferedImage image, byte[] x) {
    ShortBuffer buffer;//from  ww w  . ja va  2s .c o m

    buffer = BufferUtils.createShortBuffer(image.getHeight() * image.getWidth());
    for (int i = 0; i < x.length; i += 2) {
        short val = (short) (fromByte(x[i]) + (fromByte(x[i + 1]) << 8));
        buffer.put(val);
    }

    buffer.flip();

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

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

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
    GLRenderer2Stage.errorCheck("binding 2d texture");

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

    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL30.GL_R16, image.getWidth(), image.getHeight(), 0, GL11.GL_RED,
            GL11.GL_UNSIGNED_SHORT, buffer);
    GLRenderer2Stage.errorCheck("storing 2d texture data");

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

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    GLRenderer2Stage.errorCheck("unbinding 2d texture array");
    return textureId;
}

From source file:eu.over9000.veya.util.TextureLoader.java

License:Open Source License

public static int loadBlockTexture(final int textureUnit) {

    final InputStream in = TextureLoader.class.getResourceAsStream("/textures/blocks.png");
    ByteBuffer convertedBuffer = null;
    int sourceTexWidth = 0;
    int sourceTexHeight = 0;
    int texCount = 0;

    try {//  w  w  w.  ja  va2s.co m
        // Link the PNG decoder to this stream
        final PNGDecoder decoder = new PNGDecoder(in);

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

        texCount = sourceTexWidth / TextureLoader.TEXTURE_WIDTH
                * (sourceTexHeight / TextureLoader.TEXTURE_WIDTH);

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

        convertedBuffer = TextureLoader.convertBuffer(buf, sourceTexWidth, sourceTexHeight);

        in.close();

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

    // Create a new texture object in memory and bind it
    final int texId = GL11.glGenTextures();
    GL13.glActiveTexture(textureUnit);
    GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 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 model 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);
    GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL11.GL_RGBA, TextureLoader.TEXTURE_WIDTH,
            TextureLoader.TEXTURE_HEIGHT, texCount, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, convertedBuffer);
    GL30.glGenerateMipmap(GL30.GL_TEXTURE_2D_ARRAY);

    // Setup the ST coordinate system
    GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

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

    org.lwjgl.opengl.Util.checkGLError();

    System.out
            .println("loading block texture, id=" + texId + ", w=" + sourceTexWidth + ", h=" + sourceTexHeight);

    GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0);

    return texId;
}

From source file:fr.guillaume.prive.viper.core.model.texture.PNGTextureLoader.java

public static int loadTexture(String filename, int textureUnit) {
    ByteBuffer buf = null;/*from  ww  w  . jav a  2 s .  c  om*/
    int tWidth = 0;
    int tHeight = 0;

    try (InputStream in = new FileInputStream(filename)) {
        PNGDecoder decoder = new PNGDecoder(in);

        tWidth = decoder.getWidth();
        tHeight = decoder.getHeight();

        buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
        decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
        buf.flip();
        in.close();
    } catch (IOException e) {
        throw new IllegalStateException("PNG file i/o error", e);
    }

    // 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_RGBA16, 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_LINEAR_MIPMAP_LINEAR);

    GraphicMotor.exitOnGLError("loadPNGTexture");

    return texId;
}

From source file:go.graphics.swing.opengl.LWJGLDrawContext.java

License:Open Source License

@Override
public TextureHandle generateTexture(int width, int height, ShortBuffer data) {
    // 1 byte aligned.
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

    int texture = GL11.glGenTextures();
    if (texture == 0) {
        return null;
    }/*from ww  w  .  j a v a  2  s. co m*/

    //fix strange alpha test problem (minimap and landscape are unaffected)
    ShortBuffer bfr = BufferUtils.createShortBuffer(data.capacity());
    int cap = data.capacity();
    for (int i = 0; i != cap; i++)
        bfr.put(i, data.get(i));

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
            GL12.GL_UNSIGNED_SHORT_4_4_4_4, bfr);
    setTextureParameters();

    return new LWJGLTextureHandle(this, texture);
}

From source file:im.bci.jnuit.lwjgl.assets.AssetsLoader.java

License:Open Source License

private Texture loadPngTexture(String name) throws FileNotFoundException, IOException {
    InputStream is = vfs.open(name);
    try {/*from w  w w  . j  a v  a  2  s . co  m*/
        PNGDecoder decoder = new PNGDecoder(is);
        int bpp;
        PNGDecoder.Format format;
        int pixelFormat;
        int texWidth = decoder.getWidth();
        int texHeight = decoder.getHeight();
        boolean hasAlpha = decoder.hasAlpha();
        if (hasAlpha) {
            bpp = 4;
            format = PNGDecoder.Format.RGBA;
            pixelFormat = GL11.GL_RGBA;
        } else {
            bpp = 3;
            format = PNGDecoder.Format.RGB;
            pixelFormat = GL11.GL_RGB;
        }

        int stride = bpp * texWidth;
        ByteBuffer buffer = ByteBuffer.allocateDirect(stride * texHeight);
        decoder.decode(buffer, stride, format);
        buffer.flip();
        Texture texture = new Texture(texWidth, texHeight, hasAlpha);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getId());
        GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
        LwjglHelper.setupGLTextureParams();
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, pixelFormat, texWidth, texHeight, 0, pixelFormat,
                GL11.GL_UNSIGNED_BYTE, buffer);
        return texture;
    } finally {
        is.close();
    }
}

From source file:im.bci.jnuit.lwjgl.assets.AssetsLoader.java

License:Open Source License

private Texture loadJpegTexture(String name) throws IOException {
    InputStream is = vfs.open(name);
    try {/*w  w w.  j a  va2  s  .  c  o m*/
        JPEGDecoder decoder = new JPEGDecoder(is);
        decoder.startDecode();
        int texWidth = decoder.getImageWidth();
        int texHeight = decoder.getImageHeight();
        int stride = 3 * texWidth;
        ByteBuffer buffer = ByteBuffer.allocateDirect(stride * texHeight);
        decoder.decode(buffer, stride, decoder.getNumMCURows(), YUVtoRGB.instance);
        buffer.flip();
        Texture texture = new Texture(texWidth, texHeight, false);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getId());
        GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
        LwjglHelper.setupGLTextureParams();
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, texWidth, texHeight, 0, GL11.GL_RGB,
                GL11.GL_UNSIGNED_BYTE, buffer);
        return texture;
    } finally {
        is.close();
    }
}

From source file:io.root.gfx.glutils.GL.java

License:Apache License

public static void glPixelStorei(int pname, int param) {
    GL11.glPixelStorei(pname, param);
}