Create Thumbnails via TextureRenderer

Hi there.

First of all I beg you to ignore my bad english. I'm not used to write in such great extends. ^^



My problem is following:

At the moment I try to create Thumbnails of 3DModels. This happens while the program runs, because i need it to happen dynamicly.



My code (see below) runs without errors or warnings, but the saved thumbnail is only a black image.

(The Code is splitted into two methods, the names are self-explaining. )





public void createThumbnail() throws Exception {


        if (!(loader.getModel() instanceof Spatial)) {
            throw new Exception("The Spatial was not initialized yet. Can't create Thumbnail!");
        }
        
        
        TextureRenderer tRender=DisplaySystem.getDisplaySystem().createTextureRenderer(100, 100, TextureRenderer.Target.Texture2D);
        Texture2D rTex=new Texture2D();
        
        tRender.getCamera().setLocation(new Vector3f(0,0,5f));
        tRender.setBackgroundColor(ColorRGBA.darkGray);
        tRender.setupTexture(rTex);
        
        tRender.render(loader.getModel(), rTex);
        
        saveThumbnail(rTex);
    }




    public boolean saveThumbnail(Texture2D tex) {
        try {
        FileOutputStream out = new FileOutputStream(ConstantList.thumbnail_dir + Name + ".jpeg");
        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
        BufferedImage image=new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
        image.getGraphics().drawImage(ImageUtils.makeAwtImage(tex.getImage()), 0, 0, new Label()); // The Label works as a dummy-imageobserver

        JPEGEncodeParam param = JPEGCodec.getDefaultJPEGEncodeParam(image);
        encoder.setJPEGEncodeParam(param);
        encoder.encode(image);

        System.out.println("Thumbnail saved succesfull.");

        } catch (Exception e) {
            System.out.println(e.getMessage());
            return false;
        }
        return true;
    }



The model was load succesfull btw. All used methods work fine... i suppose. I think my problem is something with the jme stuff. It's new for me, so it don't know, how to handel it. I'm working at this problem for some days now and my backup of ideas is running dry...

Has anyone of you oldstagers an idea where my problem is? ( And if so, how to fix it? :P )

Greetings, Kuro Sei

Oh well, no reply and no results.

I tested some more. TextureRenderer's isSupported() returns true.



I changed my 'saveThumbnail' method as following:



   public boolean saveThumbnail(Texture2D tex) {
       try {
         FileOutputStream out = new FileOutputStream(ConstantList.thumbnail_dir + Name + ".jpeg");
         JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
         BufferedImage image=new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);

         // Convert Image to BufferedImage
         Graphics2D bufImageGraphics = image.createGraphics();
         bufImageGraphics.setColor(Color.gray);
         bufImageGraphics.fillRect(0, 0, 100, 100);
         bufImageGraphics.drawImage(ImageUtils.makeAwtImage(tex.getImage()), 0, 0, null);
         bufImageGraphics.setColor(Color.white);
         bufImageGraphics.drawString(Name.substring(0, Name.length()-4), 2, 92);

         JPEGEncodeParam param = JPEGCodec.getDefaultJPEGEncodeParam(image);
         encoder.setJPEGEncodeParam(param);
         encoder.encode(image);

         System.out.println("Thumbnail '" + Name + ".jpg' saved succesfull.");
       } catch (Exception e) {
           System.out.println("Exception occured while creating Thumbnail... n" + e.getMessage());
           return false;
       }
       return true;
   }



Now it creates a gray image with the specific text.
I also made some tests wether the Models are loaded succesfull and ye, they are. I render them with my normal renderer, too.

I beg you for help...


Edit:
Ah... I'm a dumb one, am I?


  Reading image data from TextureRenderer

What is the expected output? What do you see instead?
- Textures bound to an FBO or a Pbuffer have their data set-up on the GPU,
therefore the call tex.getImage() returns no data. The TextureRenderer
interface should provide a means for downloading the image data onto the
CPU without the use of user GL calls.


How to solve this problem? oO