コード例 #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
ファイル: Mandelbrot.java プロジェクト: SilverTiger/lwjgl3
  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();
  }
コード例 #3
0
  public void addTexture(BufferedImage img, Vector2f[] v) {
    subimages.add(img);

    coordinates.add(v[0]);
    coordinates.add(v[1]);
    coordinates.add(v[2]);

    Vector2f drawloc = new Vector2f();

    for (boolean done = false; !done; ) {
      try {
        drawloc = tg.nearestSpace(img);
        done = true;
      } catch (Exception e) {
        if (e.getLocalizedMessage() == "enlarge") {
          atlas =
              new BufferedImage(
                  atlas.getWidth() * 2, atlas.getHeight() * 2, BufferedImage.TYPE_INT_ARGB);
          tg.enlarge(atlas);
          for (int i = 0; i < drawingcoords.size(); i++) {
            tg.useup(drawingcoords.get(i), subimages.get(i));
          }
        }
      }
    }
    drawingcoords.add(drawloc);

    atlasgraphics = atlas.getGraphics();

    atlasgraphics.setColor(new Color(0.0f, 0.0f, 0.0f, 0.0f));
    atlasgraphics.fillRect(0, 0, atlas.getWidth(), atlas.getHeight());

    for (int i = 0; i < drawingcoords.size(); i++) {
      atlasgraphics.drawImage(
          (Image) subimages.get(i),
          (int) drawingcoords.get(i).x,
          (int) drawingcoords.get(i).y,
          null);
    }

    realtexcoods.clear();

    for (int i = 0; i < subimages.size(); i++) {
      Vector2f vec = new Vector2f();

      vec =
          converttoimagesizes(
              coordinates.get(i * 3), drawingcoords.get(i), subimages.get(i), atlas);
      realtexcoods.add(vec);

      vec =
          converttoimagesizes(
              coordinates.get((i * 3) + 1), drawingcoords.get(i), subimages.get(i), atlas);
      realtexcoods.add(vec);

      vec =
          converttoimagesizes(
              coordinates.get((i * 3) + 2), drawingcoords.get(i), subimages.get(i), atlas);
      realtexcoods.add(vec);
    }

    tg.useup(drawloc, img);

    TextureUtils util = new TextureUtils();
    util.binddata(atlas, texID);

    //		File outputfile = new File("saved @ " + this.hashCode() + ".png");
    //	    try {
    //			ImageIO.write(atlas, "png", outputfile);
    //		} catch (IOException e) {
    //			e.printStackTrace();
    //		}
  }