I did wrote a program wich enters Fullscreen and loads two images.
I created a BufferStrategy with 2 buffers.
Now I want to draw these images into two buffers BEFORE I call “bufferStrategy.show()”
Is it possible to change the drawbuffer without calling “show()” in BufferStrategy?
My Sourcecode:
import javax.swing.;
import javax.imageio.ImageIO;
import java.awt.;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.AffineTransformOp;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.io.File;
public class Main extends JFrame {
private GraphicsDevice device = null;
private boolean isFullScreen = false;
private BufferStrategy bufferStrategy = null;
private BufferedImage bimg = null;
private BufferedImage nextBimg = null;
public Main(GraphicsDevice device) throws HeadlessException {
super(device.getDefaultConfiguration());
this.device = device;
createUI();
}
private void createUI() {
this.getContentPane().setLayout(new FlowLayout());
this.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
device.setFullScreenWindow(null);
System.exit(0);
}
}
public void keyTyped(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
});
}
private void begin() {
isFullScreen = device.isFullScreenSupported();
if (isFullScreen) {
// Fullscreen Mode
setUndecorated(true);
setResizable(false);
device.setFullScreenWindow(this);
this.createBufferStrategy(2);
bufferStrategy = this.getBufferStrategy();
doIt();
} else {
// Windowed Mode
pack();
setVisible(true);
}
}
private BufferedImage loadImage(String s) {
BufferedImage bi = null;
File f = new File(s);
try {
bi = ImageIO.read(f);
} catch (IOException e) {
System.err.println(e.getMessage());
}
return bi;
}
private void doIt() {
bimg = loadImage("test1.jpg");
nextBimg = loadImage("test2.jpg");
Graphics g = bufferStrategy.getDrawGraphics();
g.drawImage(bimg, 0, 0, this);
----> Here I need something to change the drawBuffer
g.drawImage(nextBimg, 0, 0, this);
bufferStrategy.show(); // [b]it should display image 1[/b]
g.dispose();
}
public static void main(String[] args) {
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = env.getDefaultScreenDevice();
Main testFullScreenBlend = new Main(device);
testFullScreenBlend.begin();
}
}