www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: hytparadisee on June 11, 2007, 04:54:08 pm

Title: Using ITexture Effect
Post by: hytparadisee on June 11, 2007, 04:54:08 pm
I am trying to get started with implementing the ITextureEffect interface. I did the following.

Code: [Select]
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?
Title: Re: Using ITexture Effect
Post by: hytparadisee on June 11, 2007, 04:59:44 pm
An accompanying shot:

(http://peterhi.com/resources/images/20070611/ITextureEffect1.JPG)
Title: Re: Using ITexture Effect
Post by: EgonOlsen on June 11, 2007, 05:30:02 pm
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.
Title: Re: Using ITexture Effect
Post by: hytparadisee on June 11, 2007, 05:48:32 pm
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.

Quote
jPCT 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

Code: [Select]
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
Code: [Select]
new Color(255, 0, 0) now has to be
Code: [Select]
new Color(0, 0, 255)
Title: Re: Using ITexture Effect
Post by: hytparadisee on June 11, 2007, 05:58:27 pm
Sorry my bad ;D, "BufferedImage.TYPE_INT_RGB" also works. And i don't have to reorder the channels.