Generate gray scale image

Hi all i want to generate a b&w image for 3d terrain but i want to do that dinamicaly (in run time) but can’t figure out how to write into 2d texture to generate a random b&w image any clue or example??

thanks in advance

here is the code that i use to generate the texture but throw me an exception



[java]

Image img = new Image();





ByteBuffer bfData = ByteBuffer.allocate(512 * 512);

byte b = ‘c’;

Byte miByte = new Byte(b);



bfData.put(0, miByte);



img.setData(bfData);

Texture proceduralTexture = new Texture2D(512, 512, Image.Format.RGB16F);

proceduralTexture.setImage(img);



[/java]

and when i use it



[java]

mat_stl.setTexture(“m_ColorMap”, proceduralTexture);

[/java]







and the exception is



Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at com.jme3.renderer.lwjgl.TextureUtil.uploadTexture(TextureUtil.java:117)

at com.jme3.renderer.lwjgl.LwjglRenderer.updateTextureData(LwjglRenderer.java:1397)

at com.jme3.renderer.lwjgl.LwjglRenderer.setTexture(LwjglRenderer.java:1406)

at com.jme3.material.Material.render(Material.java:512)

hello, check out this post of mine



It has all the code you need

from generating greyscale images, to terrain noise functions, to putting them into the terrain engine



http://hub.jmonkeyengine.org/groups/user-code-projects/forum/topic/java-noise-jnoise/#post-107448



(DISCLAIMER: In-game utilization is built for JME2, but image generation is still the same for jme2/3)

1 Like