}  if (texture == null) { GL11.glDisable(GL11.GL_TEXTURE_2D); continue; } else GL11.glEnable(GL11.GL_TEXTURE_2D);  GL11.glMatrixMode(GL11.GL_TEXTURE); GL11.glLoadIdentity(); if (texture.getTranslation()!=null) { GL11.glTranslatef(texture.getTranslation().x,texture.getTranslation().y,texture.getTranslation().z); } if (texture.getRotation()!=null) GL11.glMultMatrix(texture.getRotation().toRotationMatrix().toFloatBuffer()); if (texture.getScale()!=null) GL11.glScalef(texture.getScale().x,texture.getScale().y,texture.getScale().z); GL11.glMatrixMode(GL11.GL_MODELVIEW);    if (texture.getTextureId() == 0) {    id.clear(); GL11.glGenTextures(id);  GL11.glBindTexture(GL11.GL_TEXTURE_2D, id.get(0));  texture.setTextureId(id.get(0));   Image image = texture.getImage(); if (image == null) { LoggingSystem.getLogger().log(Level.WARNING, "Image data for texture is null."); }   if (GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) GL11 .glTexParameterf( GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, texture.getAnisoLevel());      if (image != null) {
}  if (texture == null) { GL11.glDisable(GL11.GL_TEXTURE_2D); continue; } else GL11.glEnable(GL11.GL_TEXTURE_2D);  GL11.glMatrixMode(GL11.GL_TEXTURE); GL11.glLoadIdentity(); if (texture.getTranslation()!=null) { GL11.glTranslatef(texture.getTranslation().x,texture.getTranslation().y,texture.getTranslation().z); } if (texture.getRotation()!=null) { Vector3f vRot = tmp_rotation1; float rot = texture.getRotation().toAngleAxis( vRot ); GL11.glRotatef( rot, vRot.x, vRot.y, vRot.z ); } if (texture.getScale()!=null) GL11.glScalef(texture.getScale().x,texture.getScale().y,texture.getScale().z); GL11.glMatrixMode(GL11.GL_MODELVIEW);    if (texture.getTextureId() == 0) {    id.clear(); GL11.glGenTextures(id);  GL11.glBindTexture(GL11.GL_TEXTURE_2D, id.get(0));  texture.setTextureId(id.get(0));   Image image = texture.getImage(); if (image == null) { LoggingSystem.getLogger().log(Level.WARNING, "Image data for texture is null."); }   if (GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) GL11 .glTexParameterf( GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, texture.getAnisoLevel());      if (image != null) {
	public void apply() {		if (isEnabled()) {		    int index;			Texture texture;			for (int i = 0; i < numTexUnits; i++) {				texture = getTexture(i);				if (texture == currentTexture[i])					continue;				currentTexture[i] = texture;				index = GL13.GL_TEXTURE0 + i;				if (supportsMultiTexture) {                    GL13.glActiveTexture(index);				}				if (texture == null) {					GL11.glDisable(GL11.GL_TEXTURE_2D);					continue;				} else					GL11.glEnable(GL11.GL_TEXTURE_2D);				GL11.glMatrixMode(GL11.GL_TEXTURE);				GL11.glLoadIdentity();				if (texture.getTranslation()!=null) {				  GL11.glTranslatef(texture.getTranslation().x,texture.getTranslation().y,texture.getTranslation().z);				}				if (texture.getRotation()!=null)				  GL11.glMultMatrix(texture.getRotation().toRotationMatrix().toFloatBuffer());				if (texture.getScale()!=null)				  GL11.glScalef(texture.getScale().x,texture.getScale().y,texture.getScale().z);				GL11.glMatrixMode(GL11.GL_MODELVIEW);				//texture not yet loaded.				if (texture.getTextureId() == 0) {					// Create A IntBuffer For Image Address In Memory					//Create the texture					id.clear();					GL11.glGenTextures(id);					GL11.glBindTexture(GL11.GL_TEXTURE_2D, id.get(0));					texture.setTextureId(id.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.");					}					// Set up the anisotropic filter.					if (GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic)						GL11								.glTexParameterf(										GL11.GL_TEXTURE_2D,										EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT,										texture.getAnisoLevel());					// Get texture image data. Not all textures have image data.					// For example, AM_COMBINE modes can use primary colors,					// texture output, and constants to modify fragments via the					// texture units.					if (image != null) {                        // For textures which need mipmaps auto-generating and which                        // aren't using compressed images, generate the mipmaps.                        // A new mipmap builder may be needed to build mipmaps for                        // compressed textures.                        if (texture.getMipmap() != Texture.MM_NONE &&                            !image.hasMipmaps() && !image.isCompressedType()) {                            GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D,                                    imageComponents[image.getType()], image                                            .getWidth(), image.getHeight(),                                    imageFormats[image.getType()],                                    GL11.GL_UNSIGNED_BYTE, image.getData());                        } else {                            // Get mipmap data sizes and amount of mipmaps to send to                            // opengl. Then loop through all mipmaps and send them.                            int[] mipSizes = image.getMipMapSizes();                            ByteBuffer data = image.getData();                            int max = 1;                            int pos = 0;                            if (mipSizes == null) {                                mipSizes = new int[] { data.capacity() };                            } else if (texture.getMipmap() != Texture.MM_NONE ) {                                max = mipSizes.length;                            }                            for ( int m = 0; m < max; m++ )                            {                                int width = Math.max( 1, image.getWidth() >> m );                                int height = Math.max( 1, image.getHeight() >> m );                                data.position( pos );                                if ( image.isCompressedType() )                                {                                    ARBTextureCompression.glCompressedTexImage2DARB(                                            GL11.GL_TEXTURE_2D, m,                                            imageComponents[image.getType()], width, height,                                            0, mipSizes[m], data );                                }                                else                                {                                    data.limit( data.position() + mipSizes[m] );                                    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, m,                                            imageComponents[image.getType()], width,                                            height, 0, imageFormats[image.getType()],                                            GL11.GL_UNSIGNED_BYTE, data);                                }                                pos += mipSizes[ m ];                            }                        }					}					switch (texture.getWrap()) {					case Texture.WM_ECLAMP_S_ECLAMP_T:						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);						break;					case Texture.WM_BCLAMP_S_BCLAMP_T:						GL11								.glTexParameteri(GL11.GL_TEXTURE_2D,										GL11.GL_TEXTURE_WRAP_S,										GL13.GL_CLAMP_TO_BORDER);						GL11								.glTexParameteri(GL11.GL_TEXTURE_2D,										GL11.GL_TEXTURE_WRAP_T,										GL13.GL_CLAMP_TO_BORDER);						break;					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;					}				} else {					// texture already exists in OpenGL, just bind it					GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture							.getTextureId());				}				// If wrap mode was changed or this texture is new...				if (texture.needsWrapRefresh()) {					texture.setNeedsWrapRefresh(false);					// set up wrap mode					switch (texture.getWrap()) {					case Texture.WM_ECLAMP_S_ECLAMP_T:						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);						break;					case Texture.WM_BCLAMP_S_BCLAMP_T:						GL11								.glTexParameteri(GL11.GL_TEXTURE_2D,										GL11.GL_TEXTURE_WRAP_S,										GL13.GL_CLAMP_TO_BORDER);						GL11								.glTexParameteri(GL11.GL_TEXTURE_2D,										GL11.GL_TEXTURE_WRAP_T,										GL13.GL_CLAMP_TO_BORDER);						break;					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;					}				}				// If texture data was changed, (eg. render to texture) the				// filtering needs to be redone.				if (texture.needsFilterRefresh()) {					texture.setNeedsFilterRefresh(false);					// 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()]);				}				// set up correction mode				GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT,						textureCorrection[texture.getCorrection()]);				// set Texture apply mode.				GL11.glTexEnvi(GL11.GL_TEXTURE_ENV,						GL11.GL_TEXTURE_ENV_MODE, textureApply[texture								.getApply()]);				if (texture.getApply() == Texture.AM_COMBINE						&& supportsMultiTexture) {					if (texture.getCombineFuncAlpha() == Texture.ACF_DOT3_RGB							|| texture.getCombineFuncAlpha() == Texture.ACF_DOT3_RGBA) {						GL11.glDisable(GL11.GL_TEXTURE_2D);						break;					}					if (texture.getCombineFuncRGB() == Texture.ACF_DOT3_RGB							|| texture.getCombineFuncRGB() == Texture.ACF_DOT3_RGBA) {						// check if supported before proceeding						if (!GLContext.getCapabilities().GL_ARB_texture_env_dot3) {							GL11.glDisable(GL11.GL_TEXTURE_2D);							break;						}					}					int cf = texture.getCombineFuncRGB();					GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_COMBINE_RGB,							textureCombineFunc[cf]);					GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_SOURCE0_RGB,							textureCombineSrc[texture.getCombineSrc0RGB()]);					GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_OPERAND0_RGB,							textureCombineOpRgb[texture.getCombineOp0RGB()]);					if (cf != Texture.ACF_REPLACE) {						GL11.glTexEnvi(GL11.GL_TEXTURE_ENV,								GL13.GL_SOURCE1_RGB, textureCombineSrc[texture										.getCombineSrc1RGB()]);						GL11								.glTexEnvi(GL11.GL_TEXTURE_ENV,										GL13.GL_OPERAND1_RGB,										textureCombineOpRgb[texture												.getCombineOp1RGB()]);						if (cf == Texture.ACF_INTERPOLATE) {							GL11.glTexEnvi(GL11.GL_TEXTURE_ENV,									GL13.GL_OPERAND2_RGB,									textureCombineOpRgb[texture											.getCombineOp2RGB()]);							GL11.glTexEnvi(GL11.GL_TEXTURE_ENV,									GL13.GL_SOURCE2_RGB,									textureCombineSrc[texture											.getCombineSrc2RGB()]);						}					}					cf = texture.getCombineFuncAlpha();					GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_COMBINE_ALPHA,							textureCombineFunc[cf]);					GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_SOURCE0_ALPHA,							textureCombineSrc[texture.getCombineSrc0Alpha()]);					GL11							.glTexEnvi(GL11.GL_TEXTURE_ENV,									GL13.GL_OPERAND0_ALPHA,									textureCombineOpAlpha[texture											.getCombineOp0Alpha()]);					if (cf != Texture.ACF_REPLACE) {						GL11								.glTexEnvi(GL11.GL_TEXTURE_ENV,										GL13.GL_SOURCE1_ALPHA,										textureCombineSrc[texture												.getCombineSrc1Alpha()]);						GL11.glTexEnvi(GL11.GL_TEXTURE_ENV,								GL13.GL_OPERAND1_ALPHA,								textureCombineOpAlpha[texture										.getCombineOp1Alpha()]);						if (cf == Texture.ACF_INTERPOLATE) {							GL11.glTexEnvi(GL11.GL_TEXTURE_ENV,									GL13.GL_SOURCE2_ALPHA,									textureCombineSrc[texture											.getCombineSrc2Alpha()]);							GL11.glTexEnvi(GL11.GL_TEXTURE_ENV,									GL13.GL_OPERAND2_ALPHA,									textureCombineOpAlpha[texture											.getCombineOp2Alpha()]);						}					}					GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL13.GL_RGB_SCALE,							texture.getCombineScaleRGB());					GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_ALPHA_SCALE,							texture.getCombineScaleAlpha());				}				if (texture.getEnvironmentalMapMode() == Texture.EM_IGNORE) {					// Do not alter the texure generation status. This allows					// complex texturing outside of texture state to exist					// peacefully.				} else if (texture.getEnvironmentalMapMode() == Texture.EM_NONE) {					// turn off anything that other maps might have turned on					GL11.glDisable(GL11.GL_TEXTURE_GEN_Q);					GL11.glDisable(GL11.GL_TEXTURE_GEN_R);					GL11.glDisable(GL11.GL_TEXTURE_GEN_S);					GL11.glDisable(GL11.GL_TEXTURE_GEN_T);				} else if (texture.getEnvironmentalMapMode() == Texture.EM_SPHERE) {					// generate texture coordinates					GL11.glTexGeni(GL11.GL_S, GL11.GL_TEXTURE_GEN_MODE,							GL11.GL_SPHERE_MAP);					GL11.glTexGeni(GL11.GL_T, GL11.GL_TEXTURE_GEN_MODE,							GL11.GL_SPHERE_MAP);					GL11.glEnable(GL11.GL_TEXTURE_GEN_S);					GL11.glEnable(GL11.GL_TEXTURE_GEN_T);				}				GL11.glTexEnv(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_COLOR,						texture.getBlendColor());			}			if (supportsMultiTexture) {                GL13.glActiveTexture(GL13.GL_TEXTURE0);			}		} else {			if (supportsMultiTexture) {				for (int i = 0; i < numTexUnits; i++) {                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + i);					GL11.glDisable(GL11.GL_TEXTURE_2D);					currentTexture[i] = null;				}			} else {				GL11.glDisable(GL11.GL_TEXTURE_2D);				currentTexture[0] = null;			}		}	}