2013-03-07 64 views
4

如何創建最大化的lwjgl窗口或以編程方式使已創建的顯示最大化?創建最大化的lwjgl窗口

注意:我不問如何設置全屏顯示模式。

+0

可能重複http://stackoverflow.com/questions/26769496/how-can-i -set-an-opengl-display-window-created-by-opengl-to-maximized) – Alex 2014-11-10 19:32:50

回答

0
Dimension screenDimensions = Toolkit.getDefaultToolkit().getScreenSize(); 
screenDimensions.width; 
screenDimensions.height; 
    // this gets the height and width of your screen 
    // and 
Display.setDisplayMode(new DisplayMode(screenDimensions.width, screenDimensions.height)); 
+0

這隻會創建窗口大小的屏幕,但它不會最大化 – Qualphey 2013-03-14 17:58:02

+0

當我運行我的程序時,最大化按鈕被禁用,它似乎最大化被刪除的窗口。如果您可以讓窗口在JFrame中運行,那麼您可以通過簡單的設置調用將其設置爲最大化。繼承人鏈接:http://lwjgl.org/wiki/index.php?title=Using_a_Resizeable_AWT_Frame_with_LWJGL – 2013-03-14 18:50:47

1

Display.setResizable(真)

這將使最大化按鈕。

0

我使用了網站上的LWJGL示例,它獲取了可能的displaymodes並將其設置爲全屏最佳效果。只需創建anoother類並使用此代碼!

public class DisplayConfig { 

//This is the Class that lets us switch between full screen 
//and window mode. 
public void setDisplayMode(int width, int height, boolean fullscreen){ 

    //If the display mode we are trying to achieve is already running 
    //we just jump straight back out. 
    if((Display.getDisplayMode().getWidth() == width) && 
      (Display.getDisplayMode().getHeight() == height) && 
      (Display.isFullscreen() == fullscreen)){ 
     return; 
    } 
    try{ 
     DisplayMode targetDisplayMode = null; 

     //if we are in full screen mode we will have to check and iterate 
     //through the computers available display modes to get back to 
     //where we started 
     if(fullscreen){ 
      DisplayMode[] modes = Display.getAvailableDisplayModes(); 
      int freq =0; 
      for (DisplayMode displayMode : modes) { 
       System.out.println(displayMode.getWidth()+" "+displayMode.getHeight()); 
      } 

      for (int i = 0; i < modes.length; i++) { 
       DisplayMode current = modes[i]; 
       if((current.getWidth() == width) && (current.getHeight() == height)){ 
        if((targetDisplayMode == null) || (current.getFrequency() >= freq)){ 
         if((targetDisplayMode == null) || (current.getBitsPerPixel() > targetDisplayMode.getBitsPerPixel())){ 
          targetDisplayMode = current; 
          freq = targetDisplayMode.getFrequency(); 
         } 
        } 
        if((current.getBitsPerPixel() == Display.getDesktopDisplayMode().getBitsPerPixel()) && 
          (current.getFrequency() == Display.getDesktopDisplayMode().getFrequency())){ 
         targetDisplayMode = current; 
         break; 
        } 
       } 
      } 
     } else { 
      targetDisplayMode = new DisplayMode(width, height); 
     } 
     if (targetDisplayMode == null){ 
      System.out.println("Failed to find value mode: "+width+"x"+height+" fs="+fullscreen); 
      return; 
     } 
     Display.setDisplayMode(targetDisplayMode); 
     Display.setFullscreen(fullscreen); 

    } catch (LWJGLException e){ 
     System.out.println("Unable to setup mode "+width+"x"+height+" fullscreen="+fullscreen + e); 
    } 
} 
} 

http://lwjgl.org/wiki/index.php?title=LWJGL_Basics_5_(Fullscreen)

的[I如何設置一個OpenGL顯示(窗口由OpenGL的創建)最大化?](