Here is a bug with jme when trying to use an empty texture:
[java]
geometry.getMaterial().setTexture(“Texture”, new Texture2D());
[/java]
java.lang.NullPointerException
at com.jme3.renderer.lwjgl.LwjglRenderer.setTexture(LwjglRenderer.java:1886)
at com.jme3.material.MatParamTexture.apply(MatParamTexture.java:46)
at com.jme3.material.Material.render(Material.java:1009)
at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:649)
I think it sucks that jme doesn’t have a default null texture.
Here is the fix :
[java]
private static final Texture2D EMPTY_TEXTURE ;
static
{
BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g2d = image.createGraphics();
g2d.dispose();
AWTLoader loader = new AWTLoader();
EMPTY_TEXTURE = new Texture2D(loader.load(image, true));
EMPTY_TEXTURE.setMagFilter(Texture.MagFilter.Nearest);
EMPTY_TEXTURE.setMinFilter(MinFilter.NearestNoMipMaps);
}
[/java]
Why would you want to render a empty texture ? just wondering?
this bug came when i was testing a scene with 0 sprites = no texture.
So i had to set it to something, anything, the data may not be available beforehand e.g sprites created in simpleUpdate() instead of simpleInit().
maybe its part of my programming, i could always choose to attach the sprite mesh later instead at init().
Or you could wait to give it a texture until it actually has one. Seems like a waste to allocate memory, create an empty image, send it to the GPU, etc. to then not render anything.
you have a point, i will change my code to wait then.
There’s no such thing as a “null texture”. You can get a placeholder image using PlaceholderAssets.getPlaceholderImage()