GL11.glTexEnv( GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_COLOR, texture.getBlendColor());
} else {  GL11.glTexEnvi( GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, textureApply[texture.getApply()]); }
    public void apply() {        if (isEnabled()) {            for (int i = 0; i < getNumberOfUnits(); i++) {                if (getTexture(i) == null) {                    continue;                }                GL13.glActiveTexture(GL13.GL_TEXTURE0 + i);                GL11.glEnable(GL11.GL_TEXTURE_2D);                Texture texture = getTexture(i);                if (texture == null) {                    GL11.glDisable(GL11.GL_TEXTURE_2D);                    return;                }                //texture not yet loaded.                if (texture.getTextureId() == 0) {                    // Create A IntBuffer For Image Address In Memory                    IntBuffer buf =                        ByteBuffer                            .allocateDirect(4)                            .order(ByteOrder.nativeOrder())                            .asIntBuffer();                    //Create the texture                    GL11.glGenTextures(buf);                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));                    texture.setTextureId(buf.get(0));                    // pass image data to OpenGL                    Image image = texture.getImage();                    if (image == null) {                        LoggingSystem.getLogger().log(                            Level.WARNING,                            "Image data for texture is null.");                        texture.setTextureId(-1);                        return;                    }                    if (texture.getMipmap() == Texture.MM_NONE) {                        GL11.glTexImage2D(                            GL11.GL_TEXTURE_2D,                            0,                            imageComponents[image.getType()],                            image.getWidth(),                            image.getHeight(),                            0,                            imageFormats[image.getType()],                            GL11.GL_UNSIGNED_BYTE,                            image.getData());                    } else {                        GLU.gluBuild2DMipmaps(                            GL11.GL_TEXTURE_2D,                            imageComponents[image.getType()],                            image.getWidth(),                            image.getHeight(),                            imageFormats[image.getType()],                            GL11.GL_UNSIGNED_BYTE,                            image.getData());                    }                } else {                    // texture already exists in OpenGL, just bind it                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureId());                }                // set up correction mode                GL11.glHint(                    GL11.GL_PERSPECTIVE_CORRECTION_HINT,                    textureCorrection[texture.getCorrection()]);                if(texture.getApply() == Texture.AM_COMBINE) {                    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV,                            GL11.GL_TEXTURE_ENV_MODE,                            textureApply[texture.getApply()]);                    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_COMBINE_RGB,                            textureCombineFunc[texture.getCombineFuncRGB()]);                    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_COMBINE_ALPHA,                            textureCombineFunc[texture.getCombineFuncAlpha()]);                    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_SOURCE0_RGB,                            textureCombineSrc[texture.getCombineSrc0RGB()]);                    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_SOURCE1_RGB,                            textureCombineSrc[texture.getCombineSrc1RGB()]);                    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_SOURCE2_RGB,                            textureCombineSrc[texture.getCombineSrc2RGB()]);                    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_SOURCE0_ALPHA,                            textureCombineSrc[texture.getCombineSrc0Alpha()]);                    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_SOURCE1_ALPHA,                            textureCombineSrc[texture.getCombineSrc1Alpha()]);                    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_SOURCE2_ALPHA,                            textureCombineSrc[texture.getCombineSrc2Alpha()]);                    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_OPERAND0_RGB,                            textureCombineOpRgb[texture.getCombineOp0RGB()]);                    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_OPERAND1_RGB,                            textureCombineOpRgb[texture.getCombineOp1RGB()]);                    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_OPERAND2_RGB,                            textureCombineOpRgb[texture.getCombineOp2RGB()]);                    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_OPERAND0_ALPHA,                            textureCombineOpAlpha[texture.getCombineOp0Alpha()]);                    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_OPERAND1_ALPHA,                            textureCombineOpAlpha[texture.getCombineOp1Alpha()]);                    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_OPERAND2_ALPHA,                            textureCombineOpAlpha[texture.getCombineOp2Alpha()]);                    GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL13.GL_RGB_SCALE,                            textureCombineScale[texture.getCombineScaleRGB()]);                    GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_ALPHA_SCALE,                            textureCombineScale[texture.getCombineScaleRGB()]);                } else {                    // set up apply mode                    GL11.glTexEnvi(                        GL11.GL_TEXTURE_ENV,                        GL11.GL_TEXTURE_ENV_MODE,                        textureApply[texture.getApply()]);                }                GL11.glTexEnv(                    GL11.GL_TEXTURE_ENV,                    GL11.GL_TEXTURE_ENV_COLOR,                    texture.getBlendColor());                // set up wrap mode                switch (texture.getWrap()) {                    case Texture.WM_CLAMP_S_CLAMP_T :                        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);                        break;                    case Texture.WM_CLAMP_S_WRAP_T :                        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_REPEAT);                        break;                    case Texture.WM_WRAP_S_CLAMP_T :                        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_CLAMP);                        break;                    case Texture.WM_WRAP_S_WRAP_T :                        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);                        break;                }                // set up filter mode                GL11.glTexParameteri(                    GL11.GL_TEXTURE_2D,                    GL11.GL_TEXTURE_MAG_FILTER,                    textureFilter[texture.getFilter()]);                // set up mipmap mode                GL11.glTexParameteri(                    GL11.GL_TEXTURE_2D,                    GL11.GL_TEXTURE_MIN_FILTER,                    textureMipmap[texture.getMipmap()]);            }        } else {          for (int i = 0; i < getNumberOfUnits(); i++) {              GL13.glActiveTexture(GL13.GL_TEXTURE0 + i);              GL11.glDisable(GL11.GL_TEXTURE_2D);          }        }    }