Author Topic: FrameBuffer.blit() - int[] version  (Read 3421 times)

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
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();
}
});
}
}
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: FrameBuffer.blit() - int[] version
« Reply #1 on: October 16, 2007, 05:23:27 pm »
Oops...it's fixed now. I've updated the release version with this fix.