Using ITexture Effect

Started by hytparadisee, June 11, 2007, 04:54:08 PM

Previous topic - Next topic

hytparadisee

I am trying to get started with implementing the ITextureEffect interface. I did the following.


public void apply(int[] dest, int[] source) {
            Graphics g = image.getGraphics();
            g.setColor(new Color(0, 0, 0));
            g.fillRect(i, i, 100, 100);
            image.flush();
            PixelGrabber grab = new PixelGrabber(image, x, y, w, h, false);
            System.out.println("number: " + i);
            try {
                grab.grabPixels();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            Object o = grab.getPixels();
            int[] array = (int[] )o;
           
            System.arraycopy(array, 0, dest, 0, Math.min(array.length, dest.length));
        }


First of all, it somehow works and it is much better than replacing texture for each frame (actually much much better, at least the memory usage is about the same, unlike the latter which soars up 7MB per second >:() But I m sure i didn't get it right. What I tried to do, clearly is to fill a black rect on the 0,0 of the texture, but when i run the app, it is green instead. I am afraid i copied my int array wrongly?
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

hytparadisee

#1
An accompanying shot:

Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

EgonOlsen

Seems to be a format mismatch between the source and the target image. jPCT uses ARGB32 (without the alpha being used in software mode). So either make sure that your image matches that format or do a conversion on the byte level.

hytparadisee

Thanks Egon. Problem solved... to some extent

I forgot to mention that by image source come from a BufferedImage. Now i can render the image on the fly.

However there happens to be a very wierd thing.

QuotejPCT uses ARGB32 (without the alpha being used in software mode)

Therefore i tried all BufferedImage_TYPE_blahblah and finally found only one that works correctly. Surprisingly the only one worked was

new BufferedImage(256, 256, BufferedImage.TYPE_INT_BGR);

And idea why it is like that? I can do the painting, but all my colors are in the wrong order, in other words
new Color(255, 0, 0) now has to be new Color(0, 0, 255)
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

hytparadisee

Sorry my bad ;D, "BufferedImage.TYPE_INT_RGB" also works. And i don't have to reorder the channels.
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution