コード例 #1
0
  /**
   * Sharecontext is for object sharing with multiple windows (1 Texture for all windows for
   * example). <br>
   * <br>
   * If the first window is destroyed than other windows will have a black texture. <br>
   * You can change the parent context with {@link Lwjgl3WindowController#changeParentWindow(long)}
   */
  public Lwjgl3WindowController(boolean shareContext) {
    Lwjgl3NativesLoader.load();

    if (glfwInit() != GL11.GL_TRUE) throw new IllegalStateException("Unable to initialize GLFW");

    glfwSetErrorCallback(errorCallback = errorCallbackPrint(System.err));
    windows = new Array<Lwjgl3Application>();
    queueWindows = new Array<Lwjgl3Application>();

    this.shareContext = shareContext;

    runnable =
        new Runnable() {

          @Override
          public void run() {

            while (running) {

              executeWindowRunnablesAndWait();
              executeWindowRunnables();
              if (jumpLoop) continue;
              for (int i = 0; i < windows.size; i++) {
                final Lwjgl3Application app = windows.get(i);

                if (app.running) {

                  if (app.init) app.loop(true);
                } else {
                  app.setGlobals();
                  app.disposeListener();
                  windows.removeIndex(i);
                  i--;

                  Runnable run =
                      new Runnable() {

                        @Override
                        public void run() {
                          app.dispose();
                        }
                      };
                  postMainRunnable(run);

                  glfwPostEmptyEvent();
                }
              }

              if (targetFPS != 0) {
                if (targetFPS == -1) Lwjgl3Application.sleep(100);
                else Sync.sync(targetFPS);
              }
            }
          }
        };

    windowThread = new Thread(runnable, "Lwjgl3WindowController");
  }
コード例 #2
0
ファイル: Lwjgl3Application.java プロジェクト: AldousP/libgdx
 static void initializeGlfw() {
   if (errorCallback == null) {
     Lwjgl3NativesLoader.load();
     errorCallback = GLFWErrorCallback.createPrint(System.err);
     GLFW.glfwSetErrorCallback(errorCallback);
     if (GLFW.glfwInit() != GLFW.GLFW_TRUE) {
       throw new GdxRuntimeException("Unable to initialize GLFW");
     }
   }
 }