Example usage for org.lwjgl.opengl GL11 glGenTextures

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

Introduction

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

Prototype

public static void glGenTextures(@NativeType("GLuint *") int[] textures) 

Source Link

Document

Array version of: #glGenTextures GenTextures

Usage

From source file:rtype.Prototyp.java

License:Open Source License

private void createOffScreenBuffer() {
    int bytesPerPixel = 3;
    ByteBuffer scratch = ByteBuffer.allocateDirect(1024 * 1024 * bytesPerPixel);
    IntBuffer buf = ByteBuffer.allocateDirect(12).order(ByteOrder.nativeOrder()).asIntBuffer();
    GL11.glGenTextures(buf); // Create Texture In OpenGL
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));
    SCREEN_TEXTURE_ID = buf.get(0);/*  w w  w.j ava  2s .c  o m*/

    int glType = GL11.GL_RGB;
    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);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, glType, 1024, 1024, 0, glType, GL11.GL_UNSIGNED_BYTE, scratch);

}

From source file:rtype.WorkAroundTextureLoader.java

License:Open Source License

private Texture loadTexture(String path, int xOffSet, int yOffSet, int textWidth, int textHeight) {

    BufferedImage buffImage = null;
    try {/*from w  ww.  j  a v a 2s.  c o  m*/
        if (imageCache.get(path) != null)
            buffImage = (BufferedImage) imageCache.get(path);
        else {
            System.out.println("Loading image:" + path);
            buffImage = ImageIO.read(this.getClass().getResource(path));

            //February 2nd, 2011: Fix for JAVA 1.6 thanks to sonicWonder for the fix
            byte[] data = ((DataBufferByte) buffImage.getRaster().getDataBuffer()).getData();
            switch (buffImage.getType()) {
            case BufferedImage.TYPE_4BYTE_ABGR:
                convertFromARGBToBGRA(data);
                break;
            case BufferedImage.TYPE_3BYTE_BGR:
                convertFromBGRToRGB(data);
                break;
            default:
                System.out.println("Unknown type:" + buffImage.getType());
                break;
            }
            //End February 2nd, 2011: Fix for JAVA 1.6 thanks to sonicWonder for the fix
            imageCache.put(path, buffImage);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    int bytesPerPixel = buffImage.getColorModel().getPixelSize() / 8;

    ByteBuffer scratch = ByteBuffer.allocateDirect(textWidth * textHeight * bytesPerPixel)
            .order(ByteOrder.nativeOrder());

    DataBufferByte dataBufferByte = ((DataBufferByte) buffImage.getRaster().getDataBuffer());

    for (int i = 0; i < textHeight; i++)
        scratch.put(dataBufferByte.getData(), (xOffSet + (yOffSet + i) * buffImage.getWidth()) * bytesPerPixel,
                textWidth * bytesPerPixel);

    scratch.rewind();

    // Create A IntBuffer For Image Address In Memory
    IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
    GL11.glGenTextures(buf); // Create Texture In OpenGL

    // Create Nearest Filtered Texture
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));
    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);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, textWidth, textHeight, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, scratch);

    Texture newTexture = new Texture();
    newTexture.textureId = buf.get(0); // Return Image Addresses In Memory
    newTexture.textureHeight = textHeight;
    newTexture.textureWidth = textWidth;

    return newTexture;
}

From source file:shipeditor.Texture.java

License:GNU General Public License

public void load(String location) {
    glBindTexture(GL_TEXTURE_2D, id);//  www . j a v a 2s  . c om
    InputStream in;
    try {
        in = new FileInputStream("files" + System.getProperty("file.separator") + "resources"
                + System.getProperty("file.separator") + location);
        PNGDecoder decoder = new PNGDecoder(in);
        ByteBuffer buf;
        IntBuffer tmp = BufferUtils.createIntBuffer(1);
        GL11.glGenTextures(tmp);
        tmp.rewind();
        buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
        decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
        buf.flip();
        id = tmp.get(0);
        glBindTexture(GL11.GL_TEXTURE_2D, id);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

        glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0,
                GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf);
        in.close();
        System.out.println("Loaded texture: " + location);
    } catch (Exception e) {
        System.out.println("Failed to load: " + location);
        e.printStackTrace();
    }
}

From source file:src.graphics.common.Texture.java

License:Open Source License

private void cacheTex() {
    if (glID == -1) {
        tmpID.rewind();//from  ww  w.  ja v a2s .c o  m
        GL11.glGenTextures(tmpID);
        glID = tmpID.get(0);
    }
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, glID);
    buffer.flip();
    setDefaultTexParams(GL11.GL_TEXTURE_2D);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, trueSize, trueSize, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, buffer);
    cached = true;
}

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

License:Open Source License

final public static void drawPixels(Box2D area, ByteBuffer pixels) {
    if (!cached) {
        final IntBuffer tmpID = BufferUtils.createIntBuffer(1);
        GL11.glGenTextures(tmpID);
        glID = tmpID.get(0);//from w  w  w.  j  av  a  2s. c  om
        cached = true;
    }

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, glID);
    Texture.setDefaultTexParams(GL11.GL_TEXTURE_2D);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, 4, (int) area.xdim(), (int) area.ydim(), 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, pixels);

    GL11.glBegin(GL11.GL_QUADS);
    UINode.drawQuad((int) area.xpos(), (int) area.ypos(), (int) area.xmax(), (int) area.ymax(), 0, 1, 1, 0, 0);
    GL11.glEnd();
}

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

License:BSD License

public static int createTexture(BufferedImage imageData, TextureFilter filterMode) {
    imageData = convertToGlFormat(imageData);

    IntBuffer buff = BufferUtils.createIntBuffer(16);
    buff.limit(1);/*from   w w w.ja v  a 2s . c o m*/
    GL11.glGenTextures(buff);

    int textureId = buff.get();

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
    if (filterMode == TextureFilter.NEAREST) {
        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);
    } else {
        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);
    }

    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

    ByteBuffer scratch = ByteBuffer.allocateDirect(4 * imageData.getWidth() * imageData.getHeight());

    Raster raster = imageData.getRaster();
    byte data[] = (byte[]) raster.getDataElements(0, 0, imageData.getWidth(), imageData.getHeight(), null);
    scratch.clear();
    scratch.put(data);
    scratch.rewind();

    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, // Mip level & Internal format
            imageData.getWidth(), imageData.getHeight(), 0, // width, height, border
            GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, // pixel data format
            scratch); // pixel data

    GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, imageData.getWidth(), imageData.getHeight(), GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, // format, type
            scratch);

    return textureId;
}

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

License:BSD License

public static int createTexture(BufferedImage[] mips, TextureFilter filterMode) {
    IntBuffer buff = BufferUtils.createIntBuffer(16);
    buff.limit(1);/*from   w  w  w .  j a v a 2  s  . c o m*/
    GL11.glGenTextures(buff);

    int textureId = buff.get();

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
    if (filterMode == TextureFilter.NEAREST) {
        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_LINEAR);
    } else {
        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);
    }

    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

    for (int mip = 0; mip < mips.length; mip++) {
        BufferedImage imageData = mips[mip];
        imageData = convertToGlFormat(imageData);

        ByteBuffer scratch = ByteBuffer.allocateDirect(4 * imageData.getWidth() * imageData.getHeight());

        Raster raster = imageData.getRaster();
        byte data[] = (byte[]) raster.getDataElements(0, 0, imageData.getWidth(), imageData.getHeight(), null);
        scratch.clear();
        scratch.put(data);
        scratch.rewind();

        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, mip, GL11.GL_RGBA, // Mip level & Internal format
                imageData.getWidth(), imageData.getHeight(), 0, // width, height, border
                GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, // pixel data format
                scratch); // pixel data

        //   GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0,
        //         0, 0,
        //         imageData.getWidth(), imageData.getHeight(),
        //         GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,         // format, type
        //         scratch);
    }

    return textureId;
}

From source file:terminal.gld.TrueTypeFont.java

License:Open Source License

public static int loadImage(BufferedImage bufferedImage) {
    try {/*  www . jav a  2  s . c  om*/
        short width = (short) bufferedImage.getWidth();
        short height = (short) bufferedImage.getHeight();
        // textureLoader.bpp =
        // bufferedImage.getColorModel().hasAlpha() ? (byte)32 :
        // (byte)24;
        int bpp = (byte) bufferedImage.getColorModel().getPixelSize();
        ByteBuffer byteBuffer;
        DataBuffer db = bufferedImage.getData().getDataBuffer();
        if (db instanceof DataBufferInt) {
            int intI[] = ((DataBufferInt) (bufferedImage.getData().getDataBuffer())).getData();
            byte newI[] = new byte[intI.length * 4];
            for (int i = 0; i < intI.length; i++) {
                byte b[] = intToByteArray(intI[i]);
                int newIndex = i * 4;

                newI[newIndex] = b[1];
                newI[newIndex + 1] = b[2];
                newI[newIndex + 2] = b[3];
                newI[newIndex + 3] = b[0];
            }

            byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder())
                    .put(newI);
        } else {
            byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder())
                    .put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData());
        }
        byteBuffer.flip();

        int internalFormat = GL11.GL_RGBA8, format = GL11.GL_RGBA;
        IntBuffer textureId = BufferUtils.createIntBuffer(1);
        ;
        GL11.glGenTextures(textureId);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId.get(0));

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

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

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

        GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, internalFormat, width, height, format, GL11.GL_UNSIGNED_BYTE,
                byteBuffer);
        return textureId.get(0);

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

    return -1;
}

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

License:Open Source License

public static void glGenTextures(IntBuffer a) {
    GL11.glGenTextures(a);
}

From source file:util.GLUtils.java

License:Open Source License

public static int glGenTexture() {
    intBuffer.clear();
    GL11.glGenTextures(intBuffer);
    intBuffer.rewind();
    return intBuffer.get();
}