OK i tried to create something smaller and easier to work with and it didn’t have any problems(I’m starting to think that Java has a well defined sense of humour :P). This however also leads me to think the problem is me doing something bad.
This thing consists of 2 items of code the main function and the window class. To use these 2 bits of code you need a jpeg called bg.jpg in the working directory. mines 800x600 but anything should in theory work. this however is all the code being used.
What actually happens is that when i alt-tab back to the app it fails to redraw the image leaving me with a blank screen. I’m also using java 1.4.1_01 so that might be part of the problem too.
(sorry for the spammage… would have linked to a website but realised that atm i don’t actually have one)
Main function isn’t anything truly special
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
public class InfiltratorMain {
static GraphicsEnvironment ge;
static GraphicsDevice gs;
static DisplayMode oldDisplay;
public static void main(String[] args) {
// Determine if full-screen mode is supported directly
ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
gs = ge.getDefaultScreenDevice();
// Create a window for full-screen mode; add a button to leave full-screen mode
BufferStrategyTest win = new BufferStrategyTest(gs.getDefaultConfiguration());
// If full screen is possible go full screen 800x600
if (gs.isFullScreenSupported()) {
gs.setFullScreenWindow(win);
if (gs.isDisplayChangeSupported()) {
oldDisplay = gs.getDisplayMode();
gs.setDisplayMode(new DisplayMode(800, 600, 16, oldDisplay.getRefreshRate()));
}
} else {
System.out.println("Full Screen Mode unavailable. emulation engaged");
gs.setFullScreenWindow(win);
}
win.resize();
win.createBufferStrategy(2);
win.start();
}
}
The window class is (in theory) responsible for handling input and output with the user.
import javax.swing.JWindow;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferStrategy;
public class BufferStrategyTest extends JWindow implements Runnable, MouseListener {
Thread t;
int width;
int height;
Image bgImage;
public BufferStrategyTest(GraphicsConfiguration gc) {
super(gc);
t = null;
bgImage = getToolkit().createImage("bg.jpg");
addMouseListener(this);
setIgnoreRepaint(true);
}
public void paint(Graphics g) {
// This function does nothing.. for painting see run()
}
// This tells the DrawnPanel that it has been resized so it needs to reset its size variables
public void resize() {
GraphicsDevice gs = getGraphicsConfiguration().getDevice();
width = gs.getDisplayMode().getWidth();
height = gs.getDisplayMode().getHeight();
}
public void start() {
resize();
if (t == null) {
t = new Thread(this);
t.setPriority(Thread.MIN_PRIORITY);
t.start();
}
}
public void stop() {
t = null;
}
// MouseListener Implementation
public void mouseClicked(MouseEvent e) {
this.stop();
System.exit(0);
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void run() {
BufferStrategy bs = this.getBufferStrategy();
while (t != null) {
Graphics g = bs.getDrawGraphics();
if (!bs.contentsLost()) {
g.drawImage(bgImage, 0, 0, width, height, this);
bs.show();
g.dispose();
}
t.yield();
}
}
}