Jump to content
  • Advertisement
Sign in to follow this  
TommyA

[java] Problems with Full Screen Exclusive Mode

This topic is 4379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my game I use fullscreen exclusive mode when the game runs in fullscreen. In windowed mode the game (so far a black background and an fps counter) runs fine, but when I enter fullscreen mode, the background and fps counter aren't drawn. I can see that the render method is called when I debug, and the graphics context (g) is not null. So why nothing seems drawn to the screen, is a riddle to me. The render method is displayed below:
private void render(Graphics g)
{
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
    stats.render(g);
}
and the active rendering loop looks like this:
while (running)
{
    // Drawing section.
    g = bs.getDrawGraphics();
    if (g != null)
    {
        try
        {
            // Render graphics
            render(g);
        }
        finally
        {
            g.dispose();
        }
    }
    bs.show();
    stats.updateFps();
    stats.synchronize(prefs.getIntegerSetting("game.stats.fps.limit"));
}
bs is my BufferStrategy object, which I use for doublebuffering. I have disabled repaint through setIgnoreRepaint for both the frame and the canvas object I paint to. Any suggestions to what might be wrong here?

Share this post


Link to post
Share on other sites
Advertisement
The buffer strategy are setup in the function shown below:

private void showGameWindow()
{
wndGame.setVisible(true);

// Set double/triple... buffering.
canvas.createBufferStrategy(prefs.getIntegerSetting("game.graphics.bufferstrategy"));
bs = canvas.getBufferStrategy();
}


The full screen exclusive mode is setup in this function:

private boolean setupFullscreen(boolean fullscreen, int width, int height, int bpp)
{
boolean result = false;

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = ge.getDefaultScreenDevice();

if (fullscreen && device.isFullScreenSupported())
{
if (isDisplayModeSupported(device, width, height, bpp))
{
try
{
// Remove unnecessary parts of the window. And maximize window to full screen mode.
wndGame.setUndecorated(true);
device.setFullScreenWindow(wndGame);

// Check display mode change supported.
if (device.isDisplayChangeSupported())
{
// Store the oldmode for later restore, set the new mode.
oldMode = device.getDisplayMode();
device.setDisplayMode(new DisplayMode(width, height, bpp, DisplayMode.REFRESH_RATE_UNKNOWN));
result = true;
}
else
{
// Restore window to old state.
wndGame.setUndecorated(false);
device.setFullScreenWindow(null);
result = false;
}
}
catch (Exception ex)
{
ex.printStackTrace();
// Error occured, restore to defaults.
device.setFullScreenWindow(null);
device.setDisplayMode(oldMode);
result = false;
}
}
}

return result;
}


The frame is setup in this function:
private void setupGameWindow(String title, int width, int height)
{
wndGame = new JFrame(title);
canvas = new Canvas();

// NO! we don't want useless redrawing...
wndGame.setIgnoreRepaint(true);
canvas.setIgnoreRepaint(true);

wndGame.setSize(width, height);
wndGame.getContentPane().add(canvas);

wndGame.setResizable(false);
wndGame.validate(); // Do not use pack, it will fuck up, when combined with fullscreen mode. (displayable).

wndGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}


These functions are called in my Game class constructor:
public Game()
{
prefs = Preferences.getInstance();
prefs.setSetting("game.graphics.width", 1280);
prefs.setSetting("game.graphics.height", 800);
prefs.setSetting("game.graphics.fullscreen", true);
prefs.setSetting("game.graphics.bpp", 32);
prefs.setSetting("game.graphics.bufferstrategy", 2);

System.out.println(prefs);

setupGameWindow(prefs.getStringSetting("game.window.title"),
prefs.getIntegerSetting("game.graphics.width"),
prefs.getIntegerSetting("game.graphics.height"));

isFullscreen = setupFullscreen(prefs.getBooleanSetting("game.graphics.fullscreen"),
prefs.getIntegerSetting("game.graphics.width"),
prefs.getIntegerSetting("game.graphics.height"),
prefs.getIntegerSetting("game.graphics.bpp"));

prepareGame();

showGameWindow();

GameThread thread = new GameThread();
thread.start();
}


Hope this can clarify things :)

Share this post


Link to post
Share on other sites
Swing and AWT do not play well together. I would recommend dropping the use of Canvas and get your buffer strategy directly from the JFrame.

If you are not convinced, post the full code so I can copy it and try it out myself.

Share this post


Link to post
Share on other sites
Great that worked :), thanks you so much, it did drop my fps running full screen though :( but that is another issue. But thanks for the help :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!