2016-11-30 29 views
0

我正在下面有初始化代碼來創建窗口教程目的假GLFW_VISIBILE提示的同時結合OpenGL上下文

private void init() { 
    // Setup an error callback. The default implementation 
    // will print the error message in System.err. 
    errorCallback = GLFWErrorCallback.createPrint(System.err); 
    glfwSetErrorCallback(errorCallback); 

    // Initialize GLFW. Most GLFW functions will not work before doing this. 
    if (!glfwInit()) { 
     throw new IllegalStateException("Unable to initialize GLFW"); 
    } 

    // Configure our window 
    glfwDefaultWindowHints(); // optional, the current window hints are already the default 
    glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation 
    glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable 

    int WIDTH = 300; 
    int HEIGHT = 300; 

    // Create the window 
    window = glfwCreateWindow(WIDTH, HEIGHT, "Hello World!", NULL, NULL); 
    if (window == NULL) { 
     throw new RuntimeException("Failed to create the GLFW window"); 
    } 

    // Setup a key callback. It will be called every time a key is pressed, repeated or released. 
    glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() { 
     @Override 
     public void invoke(long window, int key, int scancode, int action, int mods) { 
      if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { 
       glfwSetWindowShouldClose(window, true); // We will detect this in our rendering loop 
      } 
     } 
    }); 

    // Get the resolution of the primary monitor 
    GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); 
    // Center our window 
    glfwSetWindowPos(
      window, 
      (vidmode.width() - WIDTH)/2, 
      (vidmode.height() - HEIGHT)/2 
    ); 

    // Make the OpenGL context current 
    glfwMakeContextCurrent(window); 
    // Enable v-sync 
    glfwSwapInterval(1); 

    // Make the window visible 
    glfwShowWindow(window); 
} 

通知的glfwWindowHint(GLFW_VISIBLE, GL_FALSE);提示被禁用,則創建窗口,設置後關鍵回調,綁定opengl上下文,它再次啓用glfwShowWindow(window);

該文檔不建議做這樣的事情,並刪除這兩行似乎並沒有改變任何東西。 爲什麼先禁用提示

教程:https://lwjglgamedev.gitbooks.io/3d-game-development-with-lwjgl/content/chapter1/chapter1.html

回答

3

它禁止visablity所以它可以設置大小,改變位置,並初始化上下文,而不必見證它的客戶端。從GLFW docs窗口Visablity部分:

窗口模式的窗口可以創建最初是隱藏與 GLFW_VISIBLE窗口提示。 Windows創建隱藏完全是 用戶不可見,直到顯示。如果您需要在顯示前進一步設置窗口,例如將其移動到 特定位置,這可能會很有用。

特殊照顧程序遵循確切例如通過調用

glfwSetWindowPos(
      window, 
      (vidmode.width() - WIDTH)/2, 
      (vidmode.height() - HEIGHT)/2 
    ); 
+0

沒有看到文檔中,謝謝! – jthort

+0

讓我看看那個複選標記! ;) –

+0

必須等待特定的時間才能接受 – jthort