Problem with creating an Image

Hi,



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);
            img.setData(ace.imageData);
            
            Texture tex = new Texture2D();
            tex.setMinificationFilter(Texture.MinificationFilter.BilinearNoMipMaps);
            tex.setMagnificationFilter(Texture.MagnificationFilter.Bilinear);
            tex.setImage(img);
            
            textures_jme.add(tex);



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

Regards
David

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?



Regards

David

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.

hi,



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();
              img.setFormat(ace.type);
              img.setWidth(ace.width);
              img.setHeight(ace.height);
              ByteBuffer buf = BufferUtils.createByteBuffer(ace.imageSize);
              buf.put(ace.imageData);
              buf.rewind();
              img.setData(buf);
             
            Texture tex = new Texture2D();
            tex.setMinificationFilter(Texture.MinificationFilter.BilinearNoMipMaps);
            tex.setMagnificationFilter(Texture.MagnificationFilter.Bilinear);
            tex.setImage(img);
            tex.setImageLocation(file);
                                    
            textures_jme.add(tex.createSimpleClone(tex));


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));

           ts.setTexture(tex);
           ts.setEnabled(true);
           triMesh.setRenderState(ts);
           triMesh.updateRenderState();
           transparent.setRenderState(ts);
           transparent.updateRenderState();



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.