Author Topic: Using ITexture Effect  (Read 4186 times)

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Using ITexture Effect
« 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?
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Re: Using ITexture Effect
« Reply #1 on: June 11, 2007, 04:59:44 pm »
An accompanying shot:

« Last Edit: June 27, 2007, 02:57:29 pm by hytparadisee »
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Using ITexture Effect
« Reply #2 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.

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Re: Using ITexture Effect
« Reply #3 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)
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Re: Using ITexture Effect
« Reply #4 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.
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution