コード例 #1
0
ファイル: Bdx.java プロジェクト: colepram/bdx
 public static void restart() {
   dispose();
   for (Scene scene : new ArrayList<Scene>(scenes)) {
     scenes.remove(scene);
     scene.end();
   }
   if (profiler.scene != null) profiler.scene.end();
   init();
   scenes.add(firstScene);
 }
コード例 #2
0
ファイル: Bdx.java プロジェクト: colepram/bdx
  public static void resize(int width, int height) {
    spriteBatch.getProjectionMatrix().setToOrtho2D(0, 0, width, height);

    if (frameBuffer != null) frameBuffer.dispose();
    if (tempBuffer != null) tempBuffer.dispose();

    frameBuffer =
        new RenderBuffer(
            spriteBatch); // Have to recreate all render buffers and adjust the projection matrix as
                          // the window size has changed
    tempBuffer = new RenderBuffer(spriteBatch);
    for (Scene scene : scenes) {

      if (scene.lastFrameBuffer != null) scene.lastFrameBuffer.dispose();

      scene.lastFrameBuffer = new RenderBuffer(null);
    }
  }
コード例 #3
0
ファイル: Bdx.java プロジェクト: colepram/bdx
 public void add(int index, Scene scene) {
   super.add(index, scene);
   if (scene.objects == null) scene.init();
 }
コード例 #4
0
ファイル: Bdx.java プロジェクト: colepram/bdx
 public boolean add(Scene scene) {
   boolean ret = super.add(scene);
   if (scene.objects == null) scene.init();
   return ret;
 }
コード例 #5
0
ファイル: Bdx.java プロジェクト: colepram/bdx
  public static void main() {
    profiler.start("__graphics");
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    profiler.stop("__graphics");

    // -------- Update Input --------
    time += TICK_TIME;
    ++GdxProcessor.currentTick;
    fingers.clear();
    for (Finger f : allocatedFingers) {
      if (f.down() || f.up()) fingers.add(f);
    }
    // ------------------------------

    for (Component c : components) {
      if (c.state != null) c.state.main();
    }

    profiler.stop("__input");

    for (Scene scene : (ArrayListScenes) scenes.clone()) {
      scene.update();

      profiler.start("__render");

      // ------- Render Scene --------

      if (scene.filters.size() > 0) {
        frameBuffer.begin();
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
      }

      Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT);
      modelBatch.begin(scene.camera.data);
      for (GameObject g : scene.objects) {
        if (g.visible() && g.insideFrustum()) {
          modelBatch.render(g.modelInstance, scene.environment);
        }
      }
      modelBatch.end();

      if (scene.filters.size() > 0) {

        frameBuffer.end();

        scene.lastFrameBuffer.getColorBufferTexture().bind(1);
        Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0);

        for (ShaderProgram filter : scene.filters) {

          filter.begin();
          filter.setUniformf("time", Bdx.time);
          filter.setUniformi("lastFrame", 1);
          filter.setUniformf("screenWidth", Bdx.display.size().x);
          filter.setUniformf("screenHeight", Bdx.display.size().y);
          filter.end();

          tempBuffer.clear();

          int width = (int) (Gdx.graphics.getWidth() * filter.renderScale.x);
          int height = (int) (Gdx.graphics.getHeight() * filter.renderScale.y);

          if (tempBuffer.getWidth() != width || tempBuffer.getHeight() != height)
            tempBuffer = new RenderBuffer(spriteBatch, width, height);

          frameBuffer.drawTo(tempBuffer, filter);

          if (!filter.overlay) frameBuffer.clear();

          tempBuffer.drawTo(frameBuffer);
        }

        frameBuffer.drawTo(null); //  Draw to screen
        scene.lastFrameBuffer.clear();
        frameBuffer.drawTo(scene.lastFrameBuffer);
      }

      // ------- Render physics debug view --------

      Bullet.DebugDrawer debugDrawer = (Bullet.DebugDrawer) scene.world.getDebugDrawer();
      debugDrawer.drawWorld(scene.world, scene.camera.data);

      profiler.stop("__render");
    }
    mouse.wheelMove = 0;

    profiler.updateVariables();
    if (profiler.visible()) {
      profiler.updateVisible();

      // ------- Render profiler scene --------

      Scene profilerScene = profiler.scene;
      profilerScene.update();
      Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT);
      modelBatch.begin(profilerScene.camera.data);
      for (GameObject g : profilerScene.objects) {
        if (g.visible()) {
          modelBatch.render(g.modelInstance, profilerScene.environment);
        }
      }
      modelBatch.end();
    }
    if (profiler.gl.isEnabled()) {
      profiler.gl.updateFields();
    }
  }