1
Bugs / FrameBuffer.blit() - int[] version
« on: October 16, 2007, 04:20:47 am »
I highly doubt that the FrameBuffer.blit() - int[] contains bug. For the Texture version is ok, but if i use the int[] version, no matter how I do it, I always get java.lang.ArrayIndexOutOfBoundsException: 9 saying that no such item at index 9. But obviously I'm passing an image with a length of 307200. If you can help, the following program will reproduce the error.
Code: [Select]
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import com.threed.jpct.*;
import com.threed.jpct.util.*;
public class Blitting {
private int width = 640, height = 480, granularity = (1000 / 40), numOfUpdates;
private long now, justNow = System.currentTimeMillis(), start, offset;
private boolean running = true;
private World world;
private KeyMapper keyMapper;
private Object3D box;
private FrameBuffer buf;
private KeyState keyState;
private Image fpsImage = new BufferedImage(200, 100, BufferedImage.TYPE_INT_ARGB);
public Blitting() {
Config.glFullscreen = false;
world = new World();
keyMapper = new KeyMapper();
box = Primitives.getBox(1, 1);
buf = new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_NORMAL);
world.setAmbientLight(50, 50, 50);
box.translate(0, 0, 5);
world.addObject(box);
world.buildAllObjects();
buf.enableRenderer(IRenderer.RENDERER_OPENGL);
buf.disableRenderer(IRenderer.RENDERER_SOFTWARE);
buf.optimizeBufferAccess();
World.setDefaultThread(Thread.currentThread());
while (running) {
now = System.currentTimeMillis();
offset = now - justNow;
numOfUpdates = 0;
if (offset >= granularity) {
justNow = now - (offset % granularity);
numOfUpdates = (int )(offset / granularity);
}
for (int i = 0; i < numOfUpdates; i++) {
update(System.currentTimeMillis() - start);
}
while ((keyState = keyMapper.poll()) != KeyState.NONE) {
poll(keyState);
}
buf.clear();
world.renderScene(buf);
world.draw(buf);
buf.update();
blit(buf);
buf.displayGLOnly();
}
System.exit(0);
}
protected void update(long elapsed) {
// TODO: update here
box.rotateY(0.01f);
}
protected void poll(KeyState keyState) {
if (keyState.getKeyCode() == KeyEvent.VK_ESCAPE) {
running = false;
}
// TODO: process your other key ere
}
protected void blit(FrameBuffer buffer) {
// TODO: make your additional 2D drawing here
Graphics g = fpsImage.getGraphics();
g.setColor(new Color(0.9f, 0.9f, 0.9f, 0.9f));
g.fillRect(0, 0, 200, 100);
fpsImage.flush();
PixelGrabber grabber = new PixelGrabber(fpsImage, 0, 0, -1, -1, false);
try {
if (grabber.grabPixels()) {
int[] data = buffer.getPixels();
System.out.println(data.length);
buffer.blit(data, 200, 100, 0, 0, 0, 0, 200, 100, FrameBuffer.TRANSPARENT_BLITTING);
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
new Blitting();
}
});
}
}