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:org.oscim.gdx.LwjglGL20.java

License:Apache License

public void genTextures(int n, IntBuffer textures) {
    GL11.glGenTextures(textures);
}

From source file:org.spoutcraft.client.gui.MCRenderDelegate.java

License:Open Source License

public void render(GenericBitmap bitmap) {
    int textureId;
    if (bitmapId.containsKey(bitmap)) {
        textureId = bitmapId.get(bitmap);
    } else {/*from w w  w.ja va  2 s.  c om*/
        IntBuffer tmp = IntBuffer.allocate(1);
        GL11.glGenTextures(tmp);
        textureId = tmp.get(0);
        bitmapId.put(bitmap, textureId);
    }
    int width = (int) bitmap.getActualWidth();
    int height = (int) bitmap.getActualHeight();
    int left = bitmap.getLeft();
    int top = bitmap.getTop();
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, bitmap.getRawWidth(), bitmap.getRawHeight(), 0,
            GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, bitmap.getBuffer());
    GL11.glTranslatef((float) bitmap.getScreenX(), (float) bitmap.getScreenY(), 0); // moves texture into place
    GL11.glPushMatrix();
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(770, 771);
    GL11.glDepthMask(false);
    bindColor(new Color(1.0F, 1.0F, 1.0F));
    SpoutClient.getHandle().renderEngine.bindTexture(textureId);
    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);
    double tLeft = 0, tTop = 0, rWidth = bitmap.getWidth(), rHeight = bitmap.getHeight(), tWidth = rWidth,
            tHeight = rHeight;
    if (top >= 0 && left >= 0) {
        tWidth = Math.min(tWidth, width);
        tHeight = Math.min(tHeight, height);
        tLeft = Math.min(Math.max(0, left), rWidth);
        tTop = Math.min(Math.max(0, top), rHeight);
    }
    Tessellator tessellator = Tessellator.instance;
    tessellator.startDrawingQuads();
    tessellator.addVertexWithUV(0.0D, height, -90, tLeft, tTop); // draw corners
    tessellator.addVertexWithUV(width, height, -90, tWidth, tTop);
    tessellator.addVertexWithUV(width, 0.0D, -90, tWidth, tHeight);
    tessellator.addVertexWithUV(0.0D, 0.0D, -90, tLeft, tHeight);
    tessellator.draw();
    GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    GL11.glPopMatrix();
    GL11.glDisable(GL11.GL_BLEND);
}

From source file:org.xmlvm.iphone.gl.GL.java

License:Open Source License

public static void glGenTextures(int count, IntBuffer buffer) {
    buffer.flip();
    GL11.glGenTextures(buffer);
}

From source file:playn.java.JavaGL20.java

License:Apache License

@Override
public void glGenTextures(int n, IntBuffer textures) {
    GL11.glGenTextures(textures);
}

From source file:processing.lwjgl.PGL.java

License:Open Source License

public void genTextures(int n, IntBuffer ids) {
    GL11.glGenTextures(ids);
}

From source file:processing.opengl.PLWJGL.java

License:Open Source License

@Override
public void genTextures(int n, IntBuffer textures) {
    GL11.glGenTextures(textures);
}

From source file:rainwarrior.mt100.client.PstFont.java

License:Open Source License

public PstFont() {
    charsize = 1;/*from  w  w  w .j  av  a2s . c o m*/
    width = 1;
    height = 1;
    length = 1;
    lShift = 0;
    textureWidth = 1;
    textureHeight = 1;
    ByteBuffer textureBuffer = BufferUtils.createByteBuffer(1);
    texture = BufferUtils.createIntBuffer(1);
    GL11.glGenTextures(texture);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.get(0));
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0x0, GL11.GL_ALPHA, textureWidth, textureHeight, 0x0, GL11.GL_ALPHA,
            GL11.GL_UNSIGNED_BYTE, textureBuffer);
}

From source file:rainwarrior.mt100.client.PstFont.java

License:Open Source License

public PstFont(String fontFile) {
    this.fontFile = fontFile;
    boolean hasUni;
    boolean psf1;
    try {/*from  w w w.j  a  va  2 s .  co m*/
        InputStream str = this.getClass().getResourceAsStream(fontFile);
        if (str != null) {
            GZIPInputStream stream = new GZIPInputStream(str);
            DataInputStream file = new DataInputStream(stream);
            byte[] b = new byte[4];
            for (int i = 0; i < 4; i++)
                b[i] = file.readByte();
            int hoffset;
            if (b[0] == (byte) 0x36 && b[1] == (byte) 04) // psf1 magic
            {
                psf1 = true;
                width = 8;
                height = charsize = b[3];
                length = ((b[2] & 0x01) != 0) ? 512 : 256;
                lShift = 4;
                hasUni = ((b[2] & 0x02) != 0);
                hoffset = 0;
            } else if (b[0] == (byte) 0x72 && b[1] == (byte) 0xB5 && b[2] == (byte) 0x4A && b[3] == (byte) 0x86) // psf2 magic
            {
                psf1 = false;
                ByteBuffer header = ByteBuffer.allocate(28);
                file.readFully(header.array(), 0, 28);
                header.order(ByteOrder.LITTLE_ENDIAN);
                int version = header.getInt();
                hoffset = header.getInt() - 32;
                if (debug)
                    MT100.logger.info("hoffset: " + hoffset);
                int flags = header.getInt();
                hasUni = ((flags & 0x01) != 0);
                length = header.getInt();
                if (length != 256 && length != 512) {
                    throw new RuntimeException("PSF2 file of unsupported length:" + length);
                }
                lShift = 4;
                charsize = header.getInt();
                height = header.getInt();
                width = header.getInt();
            } else {
                if (debug)
                    MT100.logger.severe("File " + fontFile + " is not a PSf file: " + b[0] + " " + b[1] + " "
                            + b[2] + " " + b[3]);
                throw new java.io.IOException();
            }
            if (debug)
                MT100.logger.info("width: " + width);
            if (debug)
                MT100.logger.info("height: " + height);
            if (debug)
                MT100.logger.info("charsize: " + charsize);
            if (debug)
                MT100.logger.info("length: " + length);
            ByteBuffer chars = ByteBuffer.allocate(length * charsize);
            chars.order(ByteOrder.LITTLE_ENDIAN);
            file.skipBytes(hoffset);
            file.readFully(chars.array(), 0, length * charsize);

            int roundWidth = charsize / height; // bytes
            textureWidth = 1;
            while (textureWidth < (1 << lShift) * width) {
                textureWidth <<= 1;
            }
            textureHeight = 1;
            while (textureHeight < (length >> lShift) * height) {
                textureHeight <<= 1;
            }

            ByteBuffer textureBuffer = BufferUtils.createByteBuffer(textureWidth * textureHeight);

            byte bt;
            for (int i = 0; i < (1 << lShift); i++) {
                //               if(debug) MT100.logger.info("i: " + i + ", ^i: "+ ((i >> 4) + (i & 0xF) * (length >> 4)));
                for (int j = 0; j < (length >> lShift); j++) {
                    //                  if(debug) MT100.logger.info("j: " + j + " " + (j * roundWidth) + " " + (i * charsize + j * roundWidth) + " " + ((i >> 4) * width + (i & 0xF) * 16 * width * height + j * 16 * width));
                    for (int k = 0; k < height; k++) {
                        //                     if(debug) MT100.logger.info("k: " + k);
                        for (int l = 0; l < width; l++) {
                            bt = (byte) (((chars
                                    .get((i * (length >> lShift) + j) * charsize + k * roundWidth + (l >> 3))
                                    & (1 << (7 - (l & 7)))) != 0) ? 0xFF : 0x00);
                            textureBuffer.put(i * width + (j * height + k) * textureWidth + l, bt);
                        }
                    }
                }
            }

            texture = BufferUtils.createIntBuffer(1);
            GL11.glGenTextures(texture);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.get(0));
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0x0, GL11.GL_ALPHA, textureWidth, textureHeight, 0x0,
                    GL11.GL_ALPHA, GL11.GL_UNSIGNED_BYTE, textureBuffer);

            int ss = (psf1 ? 0xFFFE : 0xFE);
            int term = (psf1 ? 0xFFFF : 0xFF);
            if (hasUni) {
                int c = 0;
                int sep;
                int i = 0;
                boolean leading = true;
                do {
                    c = 0;
                    sep = file.readByte();
                    if (sep < 0)
                        sep += 0x100;
                    if (psf1) {
                        int sep2 = file.readByte();
                        if (sep2 < 0)
                            sep2 += 0x100;
                        sep |= (sep2 << 8);
                    }
                    if (sep < 0)
                        sep += (psf1 ? 0x10000 : 0x100);
                    if (sep == ss) {
                        leading = false;
                    } else if (sep == term) {
                        leading = true;
                        i++;
                        c = 0;
                    } else // real char
                    {
                        if (!psf1) // parse utf8; TODO: maybe more compact?
                        {
                            int shift;
                            if (sep >= 0xFE) {
                                throw new RuntimeException("Illegal UTF8 start byte");
                            }
                            if (sep >= 0xFC) {
                                shift = 5;
                                c |= ((sep & 0x01) << 30);
                            } else if (sep >= 0xF8) {
                                shift = 4;
                                c |= ((sep & 0x03) << 24);
                            } else if (sep >= 0xF0) {
                                shift = 3;
                                c |= ((sep & 0x07) << 18);
                            } else if (sep >= 0xE0) {
                                shift = 2;
                                c |= ((sep & 0x0F) << 12);
                            } else if (sep >= 0xC0) {
                                shift = 1;
                                c |= ((sep & 0x1F) << 6);
                            } else if (sep >= 0x80) {
                                throw new RuntimeException("Illegal UTF8 start byte: " + sep);
                            } else {
                                shift = 0;
                                c = sep;
                            }
                            if (debug)
                                MT100.logger.info("c: " + c + ", sep: " + sep + ", shift: " + shift);
                            while (shift-- > 0) {
                                sep = file.readByte();
                                if (sep < 0)
                                    sep += 0x100;
                                if (sep >= 0xC0 || sep < 0x80) {
                                    throw new RuntimeException("Illegal UTF8 intermediate byte" + sep);
                                }
                                c |= (sep & 0x3F) << (shift * 6);
                            }
                        } else {
                            c = sep;
                        }
                        if (leading) {
                            PstFontRegistry.fontMap.put(c, this);
                            PstFontRegistry.indexMap.put(c, i);
                            if (debug)
                                MT100.logger.info("c: " + c + ", sep: " + sep + ", i: " + i);
                        }
                    }
                } while (i < length);
            } else {
                for (int i = 0; i < length; i++) {
                    PstFontRegistry.fontMap.put(i, this);
                    PstFontRegistry.indexMap.put(i, i);
                }
            }
            //            System.out.println(file);
        } else {
            MT100.logger.warning("No font file!");
        }
    } catch (java.io.IOException e) {
        throw new RuntimeException(e);
    }
    debug = false;
}

From source file:resource.ResourceManager.java

License:Open Source License

public void bindTexture(Texture tex) {

    // Put Image In Memory
    ByteBuffer scratch = ByteBuffer.allocateDirect(4 * tex.getSize() * tex.getSize());

    byte data[] = (byte[]) tex.getImage().getRaster().getDataElements(0, 0, tex.getSize(), tex.getSize(), null);
    scratch.clear();//from www.j a  v a2 s.  c  om
    scratch.put(data);
    scratch.rewind();

    IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
    GL11.glGenTextures(buf); // Create a texure ID
    tex.setID(buf.get(0));

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getID());

    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_MAG_FILTER, GL11.GL_LINEAR);
    // Generate The Texture
    GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, GL11.GL_RGBA, tex.getSize(), tex.getSize(), GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, scratch);
}

From source file:rtype.JNLPTextureLoader.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 2 s  .  co  m*/
        if (imageCache.get(path) != null)
            buffImage = (BufferedImage) imageCache.get(path);
        else {
            System.out.println("Loading image:" + path);
            buffImage = ImageIO.read(new FileImageInputStream(new File(path)));
            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 data = ((DataBufferByte) buffImage.getRaster().getDataBuffer());

    for (int i = 0; i < textHeight; i++)
        scratch.put(data.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;
}