Hi,
I have the following code:
public class TextureCopyTest extends DebugGameState {
private JMEDesktop jmeDesktop;
private Quad testQuad1;
private Quad testQuad2;
public TextureCopyTest() {
super();
initKeyBindings();
// create the test Quads
testQuad1 = new Quad("testQuad1", 10.24f, 20.48f);
testQuad2 = new Quad("testQuad2", 10.24f, 20.48f);
testQuad1.setLocalTranslation(new Vector3f(10.0f, 0.0f, 0.0f));
testQuad2.setLocalTranslation(new Vector3f(20.0f, 0.0f, 0.0f));
testQuad1.setLightCombineMode(LightState.OFF);
testQuad2.setLightCombineMode(LightState.OFF);
// create the desktop Quad
Callable<?> preload = new Callable() {
public Object call() throws Exception {
initJMEDesktop();
jmeDesktop.setLocalScale(0.01f);
jmeDesktop.updateRenderState();
copyTexture();
testQuad1.updateRenderState();
testQuad2.updateRenderState();
return null;
}
};
GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER).enqueue(preload);
rootNode.attachChild(testQuad1);
rootNode.attachChild(testQuad2);
}
private void initKeyBindings() {
KeyBindingManager.getKeyBindingManager().set("copyTexFinal", KeyInput.KEY_X);
}
@Override
public void update(float tpf) {
super.update(tpf);
if (KeyBindingManager.getKeyBindingManager().isValidCommand("copyTexFinal", false)) {
copyTextureFinal(jmeDesktop, testQuad1);
this.getRootNode().updateRenderState();
}
}
private void copyTexture() {
TextureState state = (TextureState) jmeDesktop.getRenderState(RenderState.RS_TEXTURE);
testQuad1.setRenderState(state);
testQuad2.setRenderState(state);
}
private void initJMEDesktop() {
jmeDesktop = new JMEDesktop("test internalFrame");
jmeDesktop.setup(800, 1185, false, input);
jmeDesktop.setLightCombineMode(LightState.OFF);
jmeDesktop.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
rootNode.attachChild(jmeDesktop);
rootNode.setCullMode(SceneElement.CULL_NEVER);
jmeDesktop.getJDesktop().setBackground(new Color(1, 1, 1, 0.2f));
// No Alpha State
AlphaState alpha = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
jmeDesktop.setRenderState(alpha);
createSwingStuff();
}
protected void createSwingStuff() {
final JDesktopPane desktopPane = jmeDesktop.getJDesktop();
desktopPane.removeAll();
createSwingInternalFrame(desktopPane, "My Frame 1", 10, 150);
createSwingInternalFrame(desktopPane, "My Frame 2", 20, 300);
createSwingInternalFrame(desktopPane, null, 400, 350);
final JButton button3 = new JButton("more stuff");
button3.setLocation(300, 100);
button3.setSize(button3.getPreferredSize());
desktopPane.add(button3);
final JButton buttonToggleMouse = new JButton("toggle system/custom cursor");
buttonToggleMouse.setLocation(300, 70);
buttonToggleMouse.setSize(buttonToggleMouse.getPreferredSize());
desktopPane.add(buttonToggleMouse);
buttonToggleMouse.setMnemonic('m');
final JLabel label = new JLabel("click scene to steer view (WASD+Arrows)");
label.setSize(label.getPreferredSize());
desktopPane.add(label);
final JButton themeButton = new JButton("change l&f");
themeButton.setLocation(10, 400);
themeButton.setSize(themeButton.getPreferredSize());
desktopPane.add(themeButton);
JButton fullScreenButton = new JButton("<html><big>toggle fullscreen</big></html>");
fullScreenButton.setSize(fullScreenButton.getPreferredSize());
desktopPane.repaint();
desktopPane.revalidate();
}
private void createSwingInternalFrame(final JDesktopPane desktopPane, final String title, int x, int y) {
final JInternalFrame internalFrame = new JInternalFrame(title);
if (title == null) {
internalFrame.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
}
internalFrame.setLocation(x, y);
internalFrame.setResizable(true);
internalFrame.getContentPane().setLayout(new FlowLayout());
JButton button1 = new JButton("button in " + title);
button1.setMnemonic('u');
internalFrame.getContentPane().add(button1);
internalFrame.getContentPane().add(new JButton("<html><i>test</i> <big>2</big></html>"));
internalFrame.setVisible(true);
internalFrame.pack();
final JTextField textField = new JTextField("type in here");
internalFrame.getContentPane().add(textField);
internalFrame.pack();
desktopPane.add(internalFrame);
}
private void copyTextureFinal(SceneElement source, SceneElement target) {
TextureState ts = (TextureState) source.getRenderState(RenderState.RS_TEXTURE);
Texture t = ts.getTexture().createSimpleClone();
// clone image
CloneImportExport ie = new CloneImportExport();
ie.saveClone(t.getImage());
Image clonedImage = (Image) ie.loadClone();
// clone the buffer? (not needed)
// ByteBuffer bb = BufferUtils.clone(t.getImage().getData());
// clonedImage.setData(bb);
t.setImage(clonedImage);
//TextureState newState = (TextureState) target.getRenderState(RenderState.RS_TEXTURE);
TextureState newState = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
newState.setTexture(t);
target.setRenderState(newState);
target.updateRenderState();
}
public static void main(String args[]) {
StandardGame game = new StandardGame("JMEDesktop Test");
game.start();
GameStateManager.create();
TextureCopyTest state = new TextureCopyTest();
GameStateManager.getInstance().attachChild(state);
state.setActive(true);
state.getRootNode().updateRenderState();
}
}
(mouse - 'm', cloneFinal - 'x')
If you do something on the JMEDesktop, the same happens on the quads. Thats ok.
My goal is, that the texture is copied but changes on the JMEDesktop doenst affect to
the quad. So I wrote the method copyTextureFinal(), where I clone all the Texture/Image
and ByteBuffer data. But it doenst work, the quad and the desktop are still connected.
Any ideas?