Example usage for org.lwjgl.opengl GL11 GL_MODULATE

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

Introduction

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

Prototype

int GL_MODULATE

To view the source code for org.lwjgl.opengl GL11 GL_MODULATE.

Click Source Link

Document

TextureEnvMode

Usage

From source file:org.spout.engine.resources.ClientTexture.java

License:Open Source License

@Override
public void load() {
    if (textureID != -1) {
        throw new IllegalStateException("Cannot load an already loaded texture!");
    }/*from  w w  w  . j av  a  2 s  .  c  om*/

    GL11.glEnable(GL11.GL_TEXTURE_2D);

    textureID = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

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

    /*if (((Client) Spout.getEngine()).getRenderMode() != RenderMode.GL30) {
            
       //Use Mipmaps
       GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
    }*/

    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_BASE_LEVEL, 0);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, 0);

    //Bilinear Filter the closest mipmap
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);

    //Wrap the texture
    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);

    int width = image.getWidth();
    int height = image.getHeight();

    int[] pixels = new int[width * height];
    image.getRGB(0, 0, width, height, pixels, 0, width);

    ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * 4);
    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            int pixel = pixels[y * width + x];
            buffer.put((byte) ((pixel >> 16) & 0xFF)); // Red component
            buffer.put((byte) ((pixel >> 8) & 0xFF)); // Green component
            buffer.put((byte) (pixel & 0xFF)); // Blue component
            buffer.put((byte) ((pixel >> 24) & 0xFF)); // Alpha component. Only for RGBA
        }
    }

    buffer.flip();
    //if (((Client) Spout.getEngine()).getRenderMode() == RenderMode.GL30) {
    //   GL30.glGenerateMipmap(textureID);
    //}

    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, buffer);

    //EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_2D); //Not sure if this extension is supported on most cards. 
}

From source file:org.voxels.platform.LWJGLOpenGLAdapter.java

License:Open Source License

@Override
public int GL_MODULATE() {
    return GL11.GL_MODULATE;
}

From source file:terminal.gld.TrueTypeFont.java

License:Open Source License

public static int loadImage(BufferedImage bufferedImage) {
    try {//from   w  ww . 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;
}