ImageGraphics and Dynamic Texture question

I'm new to jMonkey, so please bear with me. I want to have a HUD with a dynamically generated image (a graph) in it, and can't get it working. This code (below, error checking removed for brevity) is stripped down to simply load an image, but it doesn't work either.



graphNode = new Node("graphNode");
Quad graph = new Quad("graphQuad", graphWidth, graphHeight);
graph.setRenderQueueMode(Renderer.QUEUE_ORTHO);
Vector3f graphVector = new Vector3f(500, 500, 0);
graph.setLocalTranslation(graphVector);
graph.setLightCombineMode(LightState.OFF);

//load image
BufferedImage bufImg = ImageIO.read(new File("/tmp/test.png"));
ImageGraphics graphics = ImageGraphics.createInstance(256, 256, 0);
graphics.drawImage(bufImg, 0, 256, null);

Texture texture = new Texture();
texture.setFilter(Texture.MM_LINEAR);
texture.setImage(graphics.getImage());

//create texture state for graph
graphTextureState = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
graphTextureState.setTexture(texture);
graphTextureState.setEnabled(true);

graph.setRenderState(graphTextureState);
graph.updateRenderState();
graphNode.attachChild(graph);
rootNode.attachChild(graphNode);
rootNode.updateRenderState();



When I run it, there is a 256x256 piece of the scene blocked by the HUD (as it should, in the correct place), but nothing appears except blackness. The animation behind it continues as normal, and appears if it's not behind the HUD.

I've been fighting this for the past two days and am completely out of ideas. Any ideas?

thanks
mike

I don't use ImageGraphics but rather I use java.awt.Image like this:





BufferedImage imageBuffer = ImageIO.read(new File("/tmp/test.png"));
Image image = Toolkit.getDefaultToolkit().createImage( bufferedImage.getSource() );

Texture texture = new Texture();
texture.setImage( TextureManager.loadImage( image, true ) );
texture.setMipmapState( Texture.MM_LINEAR );
texture.setFilter( Texture.FM_NEAREST );


graphics.drawImage(bufImg, 0, 256, null);



The signature for drawImage is:

boolean drawImage(Image img, int x, int y, ImageObserver observer)



The drawing canvas is 256x256, and you're drawing at (0, 256), so it's possible the graph image is clipped off? You probably intended to draw at (0, 0).

Thanks basixs, that was the fix. Now I can run JFreeChart and create a decent graph, and use that for the HUD. Greatly appreciate your help!



mike

no problemo, thanx for the thanx :slight_smile: