Example usage for org.lwjgl.opengl GL11 glBindTexture

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

Introduction

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

Prototype

public static void glBindTexture(@NativeType("GLenum") int target, @NativeType("GLuint") int texture) 

Source Link

Document

Binds the a texture to a texture target.

Usage

From source file:shadowmage.meim.client.texture.TextureManager.java

License:Open Source License

public static void resetBoundTexture() {
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, prevTexNum);
}

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

License:Open Source License

/**  Binds this texture to the current Gl rendering context, caching itself
  *  as neccesary./*from ww  w  .j  av  a 2 s.com*/
  */
public void bindTex() {
    if (!cached)
        cacheTex();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, glID);
}

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

License:Open Source License

private void cacheTex() {
    if (glID == -1) {
        tmpID.rewind();//from  www  .j a v  a  2 s.  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);//from  w w  w  . ja  v  a 2s .c o  m
        glID = tmpID.get(0);
        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.LwjglMesh.java

License:BSD License

@Override
public void bind() {
    if (vertices == null)
        return;/*from   ww  w  . ja v a 2 s.  c om*/

    assert (isFinalised);
    assert (numVertices > 0);

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

    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glVertexPointer(3, 0, vertices);

    GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
    GL11.glColorPointer(4, true, 0, colours);

    GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
    GL11.glTexCoordPointer(2, 0, texCoords);

    if (texture != null) {
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getId());
    } else {
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    }

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

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

License:BSD License

public void bindTexture(Texture texture) {
    LwjglTexture tex = (LwjglTexture) texture;

    if (tex != null) {
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getId());
    } else {//from ww  w.java  2 s .c om
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    }
}

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 ww.j  a  va2  s . c om*/
    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 ava2s.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 void drawString(float x, float y, String whatchars, int startIndex, int endIndex, float scaleX,
        float scaleY, int format, Color[] colarr) {

    IntObject intObject = null;//  www.  jav  a  2 s.c  o m
    int charCurrent;

    int totalwidth = 0;
    int i = startIndex, d, c;
    float startY = 0;

    switch (format) {
    case ALIGN_RIGHT: {
        d = -1;
        c = correctR;

        while (i < endIndex) {
            if (whatchars.charAt(i) == '\n')
                startY -= fontHeight;
            i++;
        }
        break;
    }
    case ALIGN_CENTER: {
        for (int l = startIndex; l <= endIndex; l++) {
            charCurrent = whatchars.charAt(l);
            if (charCurrent == '\n')
                break;
            if (charCurrent < 256) {
                intObject = charArray[charCurrent];
            } else {
                intObject = customChars.get(new Character((char) charCurrent));
            }
            totalwidth += intObject.width - correctL;
        }
        totalwidth /= -2;
    }
    case ALIGN_LEFT:
    default: {
        d = 1;
        c = correctL;
        break;
    }

    }

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, fontTextureID);
    GL11.glBegin(GL11.GL_QUADS);

    boolean usecol = colarr != null && colarr.length == whatchars.length();

    while (i >= startIndex && i <= endIndex) {

        charCurrent = whatchars.charAt(i);
        if (charCurrent < 256) {
            intObject = charArray[charCurrent];
        } else {
            intObject = customChars.get(new Character((char) charCurrent));
        }

        if (intObject != null) {
            if (d < 0)
                totalwidth += (intObject.width - c) * d;
            if (charCurrent == '\n') {
                startY -= fontHeight * d;
                totalwidth = 0;
                if (format == ALIGN_CENTER) {
                    for (int l = i + 1; l <= endIndex; l++) {
                        charCurrent = whatchars.charAt(l);
                        if (charCurrent == '\n')
                            break;
                        if (charCurrent < 256) {
                            intObject = charArray[charCurrent];
                        } else {
                            intObject = customChars.get(new Character((char) charCurrent));
                        }
                        totalwidth += intObject.width - correctL;
                    }
                    totalwidth /= -2;
                }
                // if center get next lines total
                // width/2;
            } else {
                if (usecol) {
                    Color col = colarr[i];
                    GL11.glColor4f(col.getRed() / 255f, col.getGreen() / 255f, col.getBlue() / 255f,
                            col.getAlpha() / 255f);

                }
                drawQuad((totalwidth + intObject.width) * scaleX + x, startY * scaleY + y,
                        totalwidth * scaleX + x, (startY + intObject.height) * scaleY + y,
                        intObject.storedX + intObject.width, intObject.storedY + intObject.height,
                        intObject.storedX, intObject.storedY);
                if (d > 0)
                    totalwidth += (intObject.width - c) * d;
            }
            i += d;

        }
    }
    GL11.glEnd();
}

From source file:terminal.gld.TrueTypeFont.java

License:Open Source License

public static int loadImage(BufferedImage bufferedImage) {
    try {//from   w w w  .  j a v  a 2  s .  c o  m
        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;
}