예제 #1
0
  @Override
  protected void init() {
    initializeProgram();

    try {
      cylinderMesh = new Mesh("UnitCylinder.xml");
      planeMesh = new Mesh("LargePlane.xml");
    } catch (Exception exception) {
      exception.printStackTrace();
      System.exit(-1);
    }

    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glFrontFace(GL_CW);

    glEnable(GL_DEPTH_TEST);
    glDepthMask(true);
    glDepthFunc(GL_LEQUAL);
    glDepthRange(0.0f, 1.0f);
    glEnable(GL_DEPTH_CLAMP);

    projectionUniformBuffer = glGenBuffers();
    glBindBuffer(GL_UNIFORM_BUFFER, projectionUniformBuffer);
    glBufferData(GL_UNIFORM_BUFFER, ProjectionBlock.SIZE, GL_DYNAMIC_DRAW);

    // Bind the static buffers.
    glBindBufferRange(
        GL_UNIFORM_BUFFER, projectionBlockIndex, projectionUniformBuffer, 0, ProjectionBlock.SIZE);

    glBindBuffer(GL_UNIFORM_BUFFER, 0);
  }
예제 #2
0
  void renderLoop() {
    long startTime = System.currentTimeMillis() + 5000;
    long fps = 0;

    while (glfwWindowShouldClose(window.handle) == GLFW_FALSE) {
      Runnable event;
      while ((event = events.poll()) != null) event.run();

      try {
        display();
      } catch (Exception e) {
        e.printStackTrace();
        break;
      }

      glfwSwapBuffers(window.handle);

      if (startTime > System.currentTimeMillis()) {
        fps++;
      } else {
        long timeUsed = 5000 + (startTime - System.currentTimeMillis());
        startTime = System.currentTimeMillis() + 5000;
        log(
            String.format(
                "%s: %d frames in 5 seconds = %.2f",
                getPlatformInfoStringUTF8(platform, CL_PLATFORM_VENDOR),
                fps,
                fps / (timeUsed / 1000f)));
        fps = 0;
      }
    }

    cleanup();

    window.signal.countDown();
  }