为什么我不能在轻量级Java游戏库中启动全屏?

时间:2015-10-17 11:16:40

标签: java lwjgl

我想在 轻量级Java游戏库(lwjgl) 中启用全屏。我有一个全屏支持的显示模式,但由于某种原因它仍然没有变为全屏:

    public static void main(String[] args)
    {   
        Alpha_Core engine = new Alpha_Core();
        setDisplayMode(1280,720, "FullScreenMode"); 
        engine.Init_Program_Loop();
    }

    public static void setDisplayMode(int width, int height, String title)
    {       
        Display.setTitle(title);
        try 
        {
//          DisplayMode[] modes = Display.getAvailableDisplayModes();
//          
//          for (int i=0;i<modes.length;i++) {
//              DisplayMode current = modes[i];
//              System.out.println(current.getWidth() + "x" + current.getHeight() + "x" +
//                                  current.getBitsPerPixel() + " " + current.getFrequency() + "Hz");
//          }

            Display.setDisplayMode(new DisplayMode(width, height));
            Display.setFullscreen(true);
            Display.create();
            Keyboard.create();
            Mouse.create();
        } 
        catch (LWJGLException e) 
        {
            e.printStackTrace();
        }
    }

我缺少什么,是否与BitsPerPixel有关?

1 个答案:

答案 0 :(得分:0)

我认为你正在寻找这个:

DisplayMode displayMode = null;
        DisplayMode[] modes = Display.getAvailableDisplayModes();

         for (int i = 0; i < modes.length; i++)
         {
             if (modes[i].isFullscreenCapable())
               {
                    displayMode = modes[i];
               }
         }

替换

Display.setDisplayMode(new DisplayMode(width, height));

使用

Display.setDisplayMode(displayMode);

或者,为了向您展示完整的代码,

public static void main(String[] args)
{   
    Alpha_Core engine = new Alpha_Core();
    setDisplayMode(1280,720, "FullScreenMode"); 
    engine.Init_Program_Loop();
}

public static void setDisplayMode(int width, int height, String title)
{       
    Display.setTitle(title);
    DisplayMode displayMode = null;
        DisplayMode[] modes = Display.getAvailableDisplayModes();
         for (int i = 0; i < modes.length; i++)
         {
             if (modes[i].isFullscreenCapable())
               {
                    displayMode = modes[i];
               }
         }
        Display.setDisplayMode(displayMode);
        Display.setFullscreen(true);
        Display.create();
        Keyboard.create();
        Mouse.create();
    } 
    catch (LWJGLException e) 
    {
        e.printStackTrace();
    }
}