Hi,
right now I’m fighting with nifty gui. I need to create something like gamma curve modifier. The math behind is done. The problem is how to create a paint into image loaded by nifty gui. All I found is how to load image from disk but not how to create the image in code and display it.
So:
How to paint into ?
Nifty lets you change the image in the ImageRenderer object you can get from an element. See the nifty bible.
The contribution I posted http://hub.jmonkeyengine.org/groups/user-code-projects/forum/topic/image-getpixelsetpixel-imagepainter-editing-jme3-images/ might help.
Although you would need to investigate how to wrap the jme image into a nifty one - that’s not something I’ve tried so I’m not sure how easy it would be.
Solved, thanks for the tips.
Here’s the code:
[java]import java.nio.ByteBuffer;
import com.jme3.niftygui.RenderImageJme;
import com.jme3.texture.Image;
import com.jme3.texture.Image.Format;
import com.jme3.texture.Texture2D;
import de.lessvoid.nifty.render.NiftyImage;
import de.lessvoid.nifty.render.NiftyRenderEngine;
public class PaintableNiftyImage extends NiftyImage {
protected Texture2D texture;
public PaintableNiftyImage(NiftyRenderEngine renderingEngine, int width, int height) {
this(renderingEngine,getEmptyTexture(width, height));
}
public PaintableNiftyImage(NiftyRenderEngine renderingEngine, Texture2D texture) {
super(renderingEngine, new RenderImageJme(texture));
this.texture = texture;
}
public Texture2D getTexture() {
return texture;
}
public Image getImage(){
return getTexture().getImage();
}
public static Texture2D getEmptyTexture(int width, int height){
ByteBuffer buffer = ByteBuffer.allocateDirect((widthheight4));
while (buffer.hasRemaining())
buffer.put((byte)(255));
Image image = new Image(Format.ABGR8, width, height,buffer);
return new Texture2D(image);
}
}[/java]