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


Image img = new Image();

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

byte b = ‘c’;

Byte miByte = new Byte(b);

bfData.put(0, miByte);


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



and when i use it


mat_stl.setTexture(“m_ColorMap”, proceduralTexture);


and the exception is

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


at com.jme3.renderer.lwjgl.TextureUtil.uploadTexture(

at com.jme3.renderer.lwjgl.LwjglRenderer.updateTextureData(

at com.jme3.renderer.lwjgl.LwjglRenderer.setTexture(

at com.jme3.material.Material.render(

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

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

1 Like