BufferedImage img = getImage(scales);
float w = img.getWidth();
float h = img.getHeight();
float factor = height / h;
Quad ret;
if (imgWidth==w && imgHeight==h && imgFactor==factor) {
// Reuse quad and texture
ret = quad;
TextureState texState = (TextureState) quad.getRenderState(StateType.Texture);
Texture oldtex = texState.getTexture();
// Not sure why this does not work, instead release the current texture and create a new one.
// oldtex.setImage(TextureManager.loadImage(img, true));
// texState.setTexture(oldtex);
TextureManager.releaseTexture(oldtex);
Texture tex = TextureManager.loadTexture(img, MinificationFilter.BilinearNoMipMaps, MagnificationFilter.Bilinear, true);
texState.setTexture(tex);
//end workaround
} else {
ret = new Quad("textLabel2d", w * factor, h * factor);
TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
Texture tex = TextureManager.loadTexture(img, MinificationFilter.BilinearNoMipMaps, MagnificationFilter.Bilinear, true);
ts.setTexture(tex);
ts.setEnabled(true);
ret.setRenderState(ts);
BlendState as = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
as.setBlendEnabled(false);
as.setReference(0.5f);
as.setTestFunction(BlendState.TestFunction.GreaterThan);
as.setTestEnabled(true);
ret.setRenderState(as);
ret.setLightCombineMode(LightCombineMode.Off);
ret.updateRenderState();
this.quad = ret;
imgWidth = w;
imgHeight = h;
imgFactor = factor;
}