Problem with creating an Image


I try to create an Image out of a ByteBuffer. I can't use the TextureManager direct because the Texture Format is ".ACE" (Microsoft Train Simulator Texture).

I managed to read out the Infos in a ByteBuffer and I tested it directly in OpenGL. It works there so i assume that the ByteBuffer is set up correctly.

But now I like to do the same thing in JME. The first attempt ended in a white Texture and the following to. So I decided to try with a very simple ByteBuffer. Here is the code:

ACETexture ace = new ACETexture();
            ACELoader.loadACE(ace, file);
            ByteBuffer buf = BufferUtils.createByteBuffer(ace.width*ace.height*3);

            for(int j=0; j<ace.width*ace.height; j++)
               buf.put((byte) 255);
               buf.put((byte) 0);
               buf.put((byte) 0);
            Image img;
            img = new Image(Format.RGB16, ace.width, ace.height, buf);
            Texture tex = new Texture2D();

But when I do it like this, the result is a white plane to. Can anyone tell me, what I'm doing wrong?


I realised that I have to Rewing the buffer.

But when I do this, nothing changes. The Texture is simply white.

I found out that the Problem isn't the reading of the Texture:

The Problem is that I want to put the Texture in a Vector (java.util) and then use it later. But this doesn't work. If I load the Texture and assign it directly to a plane everything works fine.

But i have to load at minimum 5 Textures and then assign them to a lot of Objects so that I can't reload the Texture everytime I use it.

Does anyone have a hint for me?



Try cloning the texture you store in the Vector using Texture.createSimpleClone().

Also this is probably a mistake in your code:

new Image(Format.RGB16, ace.width, ace.height, buf);

You shouldn't use Format.RGB16 in most cases- that is an HDR format. Change RGB16 to RGB8.


well I tried that now. The code now looks like:

TSTexture t = textures.elementAt(i);
            String file = path.substring(0, path.lastIndexOf("/")+1)+t.image;
            ACETexture ace = new ACETexture();
            ACELoader.loadACE(ace, file);
            Image img = new Image();
              ByteBuffer buf = BufferUtils.createByteBuffer(ace.imageSize);
            Texture tex = new Texture2D();

textures_jme is a Vector<Texture>

this is the part to read.

then a little bit later I create the subobjects:

           int id=prim_state.textures.firstElement();
           Texture tex = shape.getJmeTexture(id).createSimpleClone(shape.getJmeTexture(id));


If I apply the Texture directly in the Second part of the Code (the Object-Loading), then everything looks but (but needs to much memory). But if I do it like this, the Texture isn't applied to the model. :?

PS: I tried also with just tex.createSimpleClone (the shorter Variant) but the result wasn't better.