示例#1
0
  private void init() {
    System.out.println("LWJGL VERSION " + Version.getVersion());

    if (!glfwInit()) {
      throw new IllegalStateException("Init failed");
    }

    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);

    winID = glfwCreateWindow(WORLD_X, WORLD_Y, "Cerberus", NULL, NULL);
    if (winID == NULL) throw new RuntimeException("FAILED TO CREATE WINDOW");

    glfwSetKeyCallback(
        winID,
        (window, key, scancode, action, mods) -> {
          if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
            glfwSetWindowShouldClose(winID, true);
          }
        });

    long priMon = glfwGetPrimaryMonitor();
    GLFWVidMode vidmod = glfwGetVideoMode(priMon);

    glfwSetWindowPos(winID, (vidmod.width() - WORLD_X) / 2, (vidmod.height() - WORLD_Y) / 2);
    glfwMakeContextCurrent(winID);
    glfwShowWindow(winID);
  }
示例#2
0
  public void init() {
    // if not true after being executed then it will fail. - THIS MUST RETURN TRUE IN ORDER TO
    // CONTINUE
    if (glfwInit() != GL_TRUE) {
      // Once GLFW is initialised - window can be created
      System.err.println("GLFW initialisation has failed");
      throw new IllegalStateException("Unable to initialize GLFW");
    }

    // indicate that the window we wish to create is to be made resizable
    glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);

    //           glfwCreateWindow(width, height, title, monitor, share)
    window = glfwCreateWindow(800, 600, "Mikes Tester Window", NULL, NULL);

    // if window is not populated with necessary bytes - then it fails
    if (window == NULL) {
      System.err.println("Failed to create window");
      glfwTerminate();
      throw new RuntimeException("Failed to create the GLFW window");
    }

    glfwSetKeyCallback(window, keyCallback = new Input());

    // Returns the video resolution of primary monitor
    GLFWVidMode vidMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    //

    int WIDTH = 300;
    int HEIGHT = 300;

    // Centre the window
    glfwSetWindowPos(window, (vidMode.width() - WIDTH) / 2, (vidMode.height() - HEIGHT) / 2);

    // Make the OpenGL context current
    glfwMakeContextCurrent(window);

    // library can detect the context and make the OpenGL bindings available for use.
    GL.createCapabilities();

    // Enable v-sync
    glfwSwapInterval(1);
    // show the window
    glfwShowWindow(window);

    // glClearColor(056f, 0.258f, 0.425f, 1.0f);

    glEnable(GL_DEPTH_TEST);

    System.out.println("OPenGL: " + glGetString(GL_VERSION));
  }
示例#3
0
  private void init() {
    // Setup an error callback. The default implementation
    // will print the error message in System.err.
    glfwSetErrorCallback(errorCallback = errorCallbackPrint(System.err));

    // Initialize GLFW. Most GLFW functions will not work before doing this.
    if (glfwInit() != GL11.GL_TRUE) 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, GL_TRUE); // We will detect this in our rendering loop
              }
            });

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

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

    // Make the window visible
    glfwShowWindow(window);
  }
示例#4
0
文件: Main.java 项目: Osoldier/Vox
  private void InitWindow() {

    GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    // Center window on the screen
    glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
    // Set window events callbacks
    glfwSetKeyCallback(window, keyCallback = new Input());
    glfwSetWindowSizeCallback(window, sizeCallback = new ResizeHandler());
    glfwSetMouseButtonCallback(window, mouseCallback = new MouseHandler());
    glfwSetWindowFocusCallback(window, focusCallback = new FocusCallback());

    glfwMakeContextCurrent(window);
    glfwSwapInterval(0);
    glfwShowWindow(window);
  }