Ejemplo n.º 1
0
 public ArrayList<String> available() {
   ArrayList<String> scenes = new ArrayList<String>();
   FileHandle[] files = Gdx.files.internal("bdx/scenes/").list("bdx");
   for (FileHandle file : files) {
     scenes.add(file.name().replace(".bdx", ""));
   }
   return scenes;
 }
Ejemplo n.º 2
0
  public static void init() {
    time = 0;
    profiler = new Profiler();
    display = new Display();
    scenes = new ArrayListScenes();
    sounds = new Sounds();
    music = new Music();
    mouse = new Mouse();
    gamepads = new ArrayListNamed<Gamepad>();

    for (int i = 0; i < Controllers.getControllers().size; i++) {
      gamepads.add(new Gamepad(i));
    }

    imaps = new InputMaps();
    keyboard = new Keyboard();
    fingers = new ArrayList<Finger>();
    components = new ArrayList<Component>();
    matShaders = new HashMap<String, ShaderProgram>();

    allocatedFingers = new ArrayList<Finger>();
    for (int i = 0; i < 10; ++i) {
      allocatedFingers.add(new Finger(i));
    }

    Gdx.input.setInputProcessor(new GdxProcessor(keyboard, mouse, allocatedFingers, gamepads));

    com.badlogic.gdx.graphics.glutils.ShaderProgram.pedantic = false;

    shaderProvider = new BDXShaderProvider();
    modelBatch = new ModelBatch(shaderProvider);
    spriteBatch = new SpriteBatch();
    spriteBatch.setBlendFunction(Gdx.gl.GL_SRC_ALPHA, Gdx.gl.GL_ONE_MINUS_SRC_ALPHA);
    frameBuffer = new RenderBuffer(spriteBatch);
    tempBuffer = new RenderBuffer(spriteBatch);
    advancedLightingOn = true;
  }
Ejemplo n.º 3
0
  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();
    }
  }