A
André Wagner
Hello,
I'm writing a videogame emulator in Java, that'll run in a applet.
The process I use to draw the image in the applet is the following:
1. The emulator process its data. During this processing, the video
card is drawing to the "TV set", which means the emulator is drawing
in a BufferedImage.
2. When a whole frame is drawn, I call repaint() on the emulador.
3. This makes the paint() method of the applet to be called, draws the
bufferedImage on the screen, like this:
public void paint(Graphics g)
{
g.drawImage(video.image, 0, 0, this);
}
Well, the problem is: drawImage returns immediately. So while
drawImage is drawing the bufferedImage on the screen, the
bufferedImage is already being changed by the emulator.
So when drawImage finishes drawing the bufferedImage on the screen,
the pixels in bufferedImage are already different, and this cases
"frame tearing" on the screen.
I think a way to avoid this is to wait until the image finished
drawing on the screen. But I don't know how to do it, I tried using a
ImageObserver but it just wasn't called.
So, does anyone knows how can I do this? Or, maybe, does anyone knows
a better way to implement all this?
Best regards,
André
I'm writing a videogame emulator in Java, that'll run in a applet.
The process I use to draw the image in the applet is the following:
1. The emulator process its data. During this processing, the video
card is drawing to the "TV set", which means the emulator is drawing
in a BufferedImage.
2. When a whole frame is drawn, I call repaint() on the emulador.
3. This makes the paint() method of the applet to be called, draws the
bufferedImage on the screen, like this:
public void paint(Graphics g)
{
g.drawImage(video.image, 0, 0, this);
}
Well, the problem is: drawImage returns immediately. So while
drawImage is drawing the bufferedImage on the screen, the
bufferedImage is already being changed by the emulator.
So when drawImage finishes drawing the bufferedImage on the screen,
the pixels in bufferedImage are already different, and this cases
"frame tearing" on the screen.
I think a way to avoid this is to wait until the image finished
drawing on the screen. But I don't know how to do it, I tried using a
ImageObserver but it just wasn't called.
So, does anyone knows how can I do this? Or, maybe, does anyone knows
a better way to implement all this?
Best regards,
André