Hey everybody,
I’m having a bit of a problem here. I’m remaking a Mario game, and everything worked fine with the scrolling until I added fullscreen support. Whenever you move and the scrolling takes effect, I see quite a bit of “tearing.” It’s mostly visible on the pipe. The game is here: http://www.myexh.com/~gonav341/Mario.php (it is WebStart, but I use PHP to change the header to JNLP; my host doesn’t support JNLP). It can’t be my rendering code (or scrolling code) either because in windowed mode, it works perfectly fine.
I also tried using the -Dsun.java2d.opengl=True (when running with a .bat file) and this fixed the problem perfectly. But as this can’t be enabled in a JAR (or via WebStart), I can’t use it to fix this problem. Maybe there’s a method built in Java to enable the 2D OpenGL pipeline?
Or maybe it’s just my code I’m using to enter fullscreen? I use the following (to create the Frame and BufferStrategy and enter FSEM):
// Create the Frame.
frame = new Frame("Mario");
frame.add(this);
frame.setResizable(false);
frame.setUndecorated(true);
frame.pack();
frame.setVisible(true);
// Initialize the back buffer.
createBufferStrategy(2);
buffer = getBufferStrategy();
screen = (Graphics2D)buffer.getDrawGraphics();
// Set the display mode and enter fullscreen mode.
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
if (gd.isFullScreenSupported()) {
gd.setFullScreenWindow(frame);
if (gd.isDisplayChangeSupported()) {
try {
int refresh = gd.getDisplayMode().getRefreshRate();
gd.setDisplayMode(new DisplayMode(gameW, gameH, 32, refresh));
} catch(Exception e) {
gd.setFullScreenWindow(null);
System.out.println("No suitable display mode was found. Switching back to windowed mode.");
}
} else {
gd.setFullScreenWindow(null);
System.out.println("Display mode change not supported. Switching back to windowed mode.");
}
} else {
System.out.println("Fullscreen mode not supported. Using windowed mode.");
}
Note: this refers to the Canvas in which my BufferStrategy is created for.
I appreciate the help. Thanks in advanced.