Some png image shows different result when loaded by TextureManager / drawed by ImageGraphics.
Left box is loaded by TextureManager (incorrect) and
Right box is drawn by ImageGraphics (correct).
If you closely look at the image, you can see the difference.
The gradation of left box is not the same as original image.
(Left box is somewhat reddish and image pattern is not the same as original image)
I tried changing texture filtering option, but it doesn’t help at all.
Below is the test code and the image
Any help will be appreciated. thanks in advance.
http://cfile9.uf.tistory.com/image/160F482D4AE514D61224EC
import java.awt.Image;
import java.net.URL;
import javax.swing.ImageIcon;
import com.jme.app.SimpleGame;
import com.jme.image.Texture;
import com.jme.image.Texture2D;
import com.jme.image.Texture.MagnificationFilter;
import com.jme.image.Texture.MinificationFilter;
import com.jme.renderer.Renderer;
import com.jme.scene.Spatial.LightCombineMode;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
import com.jmex.awt.swingui.ImageGraphics;
public class TestImage extends SimpleGame {
private static final String IMAGE_PATH = "popup_512x512.png";
@Override
protected void simpleInitGame() {
rootNode.setLightCombineMode(LightCombineMode.Off);
rootNode.setRenderQueueMode(Renderer.QUEUE_ORTHO);
Quad q1 = new Quad("q1", 512, 512);
Quad q2 = new Quad("q2", 512, 512);
q1.setLocalTranslation(256, 256, 0);
q2.setLocalTranslation(512+256, 256, 0);
rootNode.attachChild(q1);
rootNode.attachChild(q2);
// set texture image loaded by TextureManager
setTexture(q1, IMAGE_PATH, MinificationFilter.BilinearNearestMipMap, MagnificationFilter.Bilinear);
// set texture image by drawing AWTImage
URL url = getClass().getResource(IMAGE_PATH);
final ImageIcon icon = new ImageIcon(url);
Image awtImage = icon.getImage();
ImageGraphics g = ImageGraphics.createInstance(512, 512, 0);
Texture tex = new Texture2D();
g.drawImage(awtImage, 0, 0, null);
g.update();
tex.setImage(g.getImage());
TextureState state2 = display.getRenderer().createTextureState();
state2.setTexture(tex);
q2.setRenderState(state2);
}
private void setTexture(Quad q, String path, MinificationFilter min, MagnificationFilter mag) {
TextureState state = display.getRenderer().createTextureState();
Texture tex = TextureManager.loadTexture(path, min, mag, 0, false);
tex.setMinificationFilter(min);
tex.setMagnificationFilter(mag);
state.setTexture(tex);
q.setRenderState(state);
}
public static void main(String[] args) {
TestImage test = new TestImage();
test.start();
}
}