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?