Ejemplo n.º 1
0
  /**
   * Starts and/or continue ping-ponging, begin capturing on the next available buffer, returns the
   * result of the previous {@link #capture()} call.
   *
   * @return the Texture containing the result.
   */
  public Texture capture() {
    endPending();

    if (writeState) {
      // set src
      texSrc = texture1;
      bufSrc = buffer1;

      // set result
      texResult = texture2;
      bufResult = buffer2;

      // write to other
      pending2 = true;
      buffer2.begin();
    } else {
      texSrc = texture2;
      bufSrc = buffer2;

      texResult = texture1;
      bufResult = buffer1;

      pending1 = true;
      buffer1.begin();
    }

    writeState = !writeState;
    return texSrc;
  }
Ejemplo n.º 2
0
  protected void renderParticles() {
    particleFrameBuffer.begin();
    batch.begin();

    Color initialColor = batch.getColor();

    Values<Entity> values = particleEntities.values();

    while (values.hasNext()) {
      Entity entity = values.next();
      ParticleComponent particle = entity.getComponent(ParticleComponent.class);
      ColorComponent color = entity.getComponent(ColorComponent.class);

      if (color != null) {
        batch.setColor(color.color);
      }

      particle.effect.draw(batch);

      batch.setColor(initialColor);
    }

    batch.end();
    particleFrameBuffer.end();

    batch.begin();
    batch.draw(particleRegion, 0.0f, 0.0f);
    batch.end();
  }
Ejemplo n.º 3
0
 /** Free the resources, if any. */
 public void dispose() {
   if (ownResources) {
     // make sure we delete what we own
     // if the caller didn't call {@link #reset()}
     owned1.dispose();
     owned2.dispose();
   }
 }
Ejemplo n.º 4
0
  public void dispose() {
    blurTargetA.dispose();
    blurTargetB.dispose();
    blurShader.dispose();

    batch.dispose();

    shapeRenderer.dispose();
  }
Ejemplo n.º 5
0
 public final void render() {
   if (outputBuffer != null) {
     outputBuffer.begin();
     realRender();
     outputBuffer.end();
   } else {
     realRender();
   }
 }
Ejemplo n.º 6
0
 public void clearManagedCaches() {
   Mesh.clearAllMeshes(app);
   Texture.clearAllTextures(app);
   ShaderProgram.clearAllShaderPrograms(app);
   FrameBuffer.clearAllFrameBuffers(app);
   Gdx.app.log("AndroidGraphics", Mesh.getManagedStatus());
   Gdx.app.log("AndroidGraphics", Texture.getManagedStatus());
   Gdx.app.log("AndroidGraphics", ShaderProgram.getManagedStatus());
   Gdx.app.log("AndroidGraphics", FrameBuffer.getManagedStatus());
 }
Ejemplo n.º 7
0
  // internal use
  // finish writing to the buffers, mark as not pending anymore.
  private void endPending() {
    if (pending1) {
      buffer1.end();
      pending1 = false;
    }

    if (pending2) {
      buffer2.end();
      pending2 = false;
    }
  }
Ejemplo n.º 8
0
  /** Call this when application is exiting. */
  public void dispose() {
    if (disposeFBO) frameBuffer.dispose();

    fullScreenQuad.dispose();

    pingPongBuffer1.dispose();
    pingPongBuffer2.dispose();

    blurShader.dispose();
    bloomShader.dispose();
    tresholdShader.dispose();
  }
Ejemplo n.º 9
0
 public void end() {
   newFrame.end();
   FrameBuffer oldFrame = newFrame;
   newFrame = cleanFrame;
   oldFrame.getColorBufferTexture().bind();
   {
     Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
     mShaderProgram.begin();
     {
       mScreenMesh.render(mShaderProgram, GL20.GL_TRIANGLE_FAN, 0, 4);
     }
     mShaderProgram.end();
   }
 }
  public void clearManagedCaches() {
    Mesh.clearAllMeshes(app);
    Texture.clearAllTextures(app);
    ShaderProgram.clearAllShaderPrograms(app);
    FrameBuffer.clearAllFrameBuffers(app);

    if (AndroidLiveWallpaperService
        .DEBUG) { // to prevent creating too many string buffers in live wallpapers
      Gdx.app.debug("AndroidGraphics", Mesh.getManagedStatus());
      Gdx.app.debug("AndroidGraphics", Texture.getManagedStatus());
      Gdx.app.debug("AndroidGraphics", ShaderProgram.getManagedStatus());
      Gdx.app.debug("AndroidGraphics", FrameBuffer.getManagedStatus());
    }
  }
Ejemplo n.º 11
0
  @Override
  public void draw() {
    // world_darkness.fill(darkness_color);

    FlxG.batch.end();
    frame_buffer.begin();
    FlxG.batch.begin();
    frame_buffer_fill.draw();
    player.drawGlow();
    world.firefish_group.callAll("drawGlow");
    FlxG.batch.end();
    frame_buffer.end();
    FlxG.batch.begin();

    super.draw();
  }
Ejemplo n.º 12
0
  public RenderingSystem() {
    super();

    this.sortedEntities = new Array<Entity>(100);
    this.batch = new SpriteBatch();
    this.camera = Env.game.getCamera();
    this.viewport = Env.game.getViewport();
    this.uiCamera = Env.game.getUICamera();
    this.uiViewport = Env.game.getUIViewport();
    this.sorter = new DepthSorter();
    this.shapeRenderer = new ShapeRenderer();
    this.box2DRenderer =
        new Box2DDebugRenderer(
            Env.drawBodies,
            Env.drawJoints,
            Env.drawABBs,
            Env.drawInactiveBodies,
            Env.drawVelocities,
            Env.drawContacts);

    this.particleFrameBuffer =
        new FrameBuffer(
            Pixmap.Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
    this.particleRegion = new TextureRegion(particleFrameBuffer.getColorBufferTexture());
    this.particleRegion.flip(false, true);

    this.skeletonRenderer = new SkeletonRenderer();

    if (Env.debug) {
      debugFont = Env.game.getAssets().get("data/ui/default.fnt", BitmapFont.class);
    }
  }
Ejemplo n.º 13
0
 public FboTarget(int width, int height) {
   this.width = width;
   this.height = height;
   fbo = new FrameBuffer(Format.RGBA8888, this.width, this.height, false);
   region = new TextureRegion(fbo.getColorBufferTexture());
   region.flip(false, true);
 }
Ejemplo n.º 14
0
  /** Call this after scene. Renders the bloomed scene. */
  public void render() {
    if (capturing) {
      capturing = false;
      frameBuffer.end();
    }

    Gdx.gl.glDisable(GL20.GL_BLEND);
    Gdx.gl.glDisable(GL20.GL_DEPTH_TEST);
    Gdx.gl.glDepthMask(false);

    gaussianBlur();

    if (blending) {
      Gdx.gl.glEnable(GL20.GL_BLEND);
      Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }

    pingPongTex1.bind(1);
    original.bind(0);
    bloomShader.begin();
    {
      fullScreenQuad.render(bloomShader, GL20.GL_TRIANGLE_FAN);
    }
    bloomShader.end();
  }
Ejemplo n.º 15
0
  public OrbRenderer(SpriteBatch batch, OrthographicCamera camera) {
    // this.batch = batch;
    // this.camera = camera;

    this.batch = new SpriteBatch();
    this.camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    orbs = new Array<Orb>();

    backgroundColor = new Color(0.8f, .8f, 0.6f, 1.0f);
    backgroundColorSpeed = 1f;

    shapeRenderer = new ShapeRenderer();

    blurTargetA =
        new FrameBuffer(
            Pixmap.Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
    blurTargetB =
        new FrameBuffer(
            Pixmap.Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
    fboRegion = new TextureRegion(blurTargetA.getColorBufferTexture());
    fboRegion.flip(false, true);
    blurAmount = 8f;

    initializeShaders();
  }
Ejemplo n.º 16
0
 /** Call this before rendering scene. */
 public void capture() {
   if (!capturing) {
     capturing = true;
     frameBuffer.begin();
     Gdx.gl.glClearColor(r, g, b, a);
     Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
   }
 }
Ejemplo n.º 17
0
  /** IMPORTANT NOTE CALL THIS WHEN RESUMING */
  public void resume() {
    bloomShader.begin();
    {
      bloomShader.setUniformi("u_texture0", 0);
      bloomShader.setUniformi("u_texture1", 1);
    }
    bloomShader.end();

    setSize(w, h);
    setTreshold(treshold);
    setBloomIntesity(bloomIntensity);
    setOriginalIntesity(originalIntensity);

    original = frameBuffer.getColorBufferTexture();
    pingPongTex1 = pingPongBuffer1.getColorBufferTexture();
    pingPongTex2 = pingPongBuffer2.getColorBufferTexture();
  }
Ejemplo n.º 18
0
  @Override
  public void render() {
    frameBuffer.begin();
    Gdx.graphics.getGL20().glViewport(0, 0, frameBuffer.getWidth(), frameBuffer.getHeight());
    Gdx.graphics.getGL20().glClearColor(0f, 1f, 0f, 1);
    Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT);
    Gdx.graphics.getGL20().glEnable(GL20.GL_TEXTURE_2D);
    texture.bind();
    meshShader.begin();
    meshShader.setUniformi("u_texture", 0);
    mesh.render(meshShader, GL20.GL_TRIANGLES);
    meshShader.end();
    frameBuffer.end();

    Gdx.graphics.getGL20().glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.graphics.getGL20().glClearColor(0.2f, 0.2f, 0.2f, 1);
    Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT);

    spriteBatch.begin();
    spriteBatch.draw(
        frameBuffer.getColorBufferTexture(),
        0,
        0,
        256,
        256,
        0,
        0,
        frameBuffer.getColorBufferTexture().getWidth(),
        frameBuffer.getColorBufferTexture().getHeight(),
        false,
        true);
    spriteBatch.end();
  }
Ejemplo n.º 19
0
 @Override
 public void onSurfaceCreated(javax.microedition.khronos.opengles.GL10 gl, EGLConfig config) {
   eglContext = ((EGL10) EGLContext.getEGL()).eglGetCurrentContext();
   setupGL(gl);
   logConfig(config);
   updatePpi();
   Mesh.invalidateAllMeshes(app);
   Texture.invalidateAllTextures(app);
   ShaderProgram.invalidateAllShaderPrograms(app);
   FrameBuffer.invalidateAllFrameBuffers(app);
   Gdx.app.log("AndroidGraphics", Mesh.getManagedStatus());
   Gdx.app.log("AndroidGraphics", Texture.getManagedStatus());
   Gdx.app.log("AndroidGraphics", ShaderProgram.getManagedStatus());
   Gdx.app.log("AndroidGraphics", FrameBuffer.getManagedStatus());
   Display display = app.getWindowManager().getDefaultDisplay();
   this.width = display.getWidth();
   this.height = display.getHeight();
   mean = new WindowedMean(5);
   this.lastFrameTime = System.nanoTime();
   gl.glViewport(0, 0, this.width, this.height);
   isSurfaceCreated = true;
 }
  private TextureRegion createBgIcon(String atlas, String region) {
    TextureAtlas a =
        new TextureAtlas(
            Gdx.files.absolute(
                Ctx.project.getProjectPath()
                    + "/"
                    + Project.ATLASES_PATH
                    + "/1/"
                    + atlas
                    + ".atlas"));
    AtlasRegion r = a.findRegion(region);
    FrameBuffer fbo =
        new FrameBuffer(
            Format.RGBA8888, 200, (int) (r.getRegionHeight() * 200f / r.getRegionWidth()), false);

    SpriteBatch fboBatch = new SpriteBatch();
    fboBatch.setColor(Color.WHITE);
    OrthographicCamera camera = new OrthographicCamera();
    camera.setToOrtho(false, fbo.getWidth(), fbo.getHeight());
    fboBatch.setProjectionMatrix(camera.combined);

    Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);
    fbo.begin();
    fboBatch.begin();
    fboBatch.draw(r, 0, 0, fbo.getWidth(), fbo.getHeight());
    fboBatch.end();

    TextureRegion tex = ScreenUtils.getFrameBufferTexture(0, 0, fbo.getWidth(), fbo.getHeight());
    //		tex.flip(false, true);

    fbo.end();
    Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);

    fbo.dispose();
    a.dispose();
    fboBatch.dispose();

    return tex;
  }
  @Override
  public void onSurfaceCreated(javax.microedition.khronos.opengles.GL10 gl, EGLConfig config) {
    eglContext = ((EGL10) EGLContext.getEGL()).eglGetCurrentContext(); // jw: added
    setupGL(gl);
    logConfig(config);
    updatePpi();

    Mesh.invalidateAllMeshes(app);
    Texture.invalidateAllTextures(app);
    ShaderProgram.invalidateAllShaderPrograms(app);
    FrameBuffer.invalidateAllFrameBuffers(app);

    if (AndroidLiveWallpaperService
        .DEBUG) { // to prevent creating too many string buffers in live wallpapers
      Gdx.app.debug("AndroidGraphics", Mesh.getManagedStatus());
      Gdx.app.debug("AndroidGraphics", Texture.getManagedStatus());
      Gdx.app.debug("AndroidGraphics", ShaderProgram.getManagedStatus());
      Gdx.app.debug("AndroidGraphics", FrameBuffer.getManagedStatus());
    }

    Display display = app.getWindowManager().getDefaultDisplay();
    this.width = display.getWidth();
    this.height = display.getHeight();
    mean = new WindowedMean(5);
    this.lastFrameTime = System.nanoTime();

    gl.glViewport(0, 0, this.width, this.height);

    // jw: moved to onSurfaceChanged (as in AndroidGraphics class)
    /*if (created == false) {
    	app.getListener().create();
    	created = true;
    	synchronized (this) {
    		running = true;
    	}
    }*/
  }
Ejemplo n.º 22
0
  @Override
  public void drawChildren(SpriteBatch batch, float parentAlpha) {
    previousScene.setVisible(true);
    nextScene.setVisible(false);
    super.drawChildren(batch, parentAlpha);
    batch.end();
    nextSceneBuffer.begin();
    batch.begin();

    previousScene.setVisible(false);
    nextScene.setVisible(true);

    super.drawChildren(batch, parentAlpha);
    nextSceneBuffer.end();

    batch.flush();
    batch.setShader(maskShader);
    maskShader.setAttributef("a_offset", offset.x, offset.y, offset.z, 0);
    texture.bind(1);
    Gdx.gl.glActiveTexture(GL10.GL_TEXTURE0);
    Gdx.gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
    batch.draw(nextSceneBuffer.getColorBufferTexture(), 0, 0);
    batch.setShader(null);
  }
Ejemplo n.º 23
0
  private void gaussianBlur() {

    // cut bright areas of the picture and blit to smaller fbo

    original.bind(0);
    pingPongBuffer1.begin();
    {
      tresholdShader.begin();
      {
        // tresholdShader.setUniformi("u_texture0", 0);
        fullScreenQuad.render(tresholdShader, GL20.GL_TRIANGLE_FAN, 0, 4);
      }
      tresholdShader.end();
    }
    pingPongBuffer1.end();

    for (int i = 0; i < blurPasses; i++) {

      pingPongTex1.bind(0);

      // horizontal
      pingPongBuffer2.begin();
      {
        blurShader.begin();
        {
          blurShader.setUniformf("dir", 1f, 0f);
          fullScreenQuad.render(blurShader, GL20.GL_TRIANGLE_FAN, 0, 4);
        }
        blurShader.end();
      }
      pingPongBuffer2.end();

      pingPongTex2.bind(0);
      // vertical
      pingPongBuffer1.begin();
      {
        blurShader.begin();
        {
          blurShader.setUniformf("dir", 0f, 1f);

          fullScreenQuad.render(blurShader, GL20.GL_TRIANGLE_FAN, 0, 4);
        }
        blurShader.end();
      }
      pingPongBuffer1.end();
    }
  }
Ejemplo n.º 24
0
  public void render(float delta) {
    updateOrbs(delta);

    blurTargetA.begin();
    Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.setShader(null);
    // resizeBatch(FBO_SIZE, FBO_SIZE);
    renderOrbs(OrbPart.Light);
    blurTargetA.end();

    blurTargetB.begin();
    Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1f);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    batch.setShader(blurShader);
    batch.begin();
    blurShader.setUniformf("dir", 1f, 0f);
    fboRegion.setTexture(blurTargetA.getColorBufferTexture());
    batch.draw(fboRegion, 0, 0);
    batch.flush();
    blurTargetB.end();

    generateBackground(delta);

    Gdx.gl.glClearColor(backgroundColor.r, backgroundColor.g, backgroundColor.b, 0f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    // resizeBatch(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    batch.end();

    // renderOrbs(OrbPart.Dark);

    batch.begin();
    blurShader.setUniformf("dir", 0f, 1f);
    fboRegion.setTexture(blurTargetB.getColorBufferTexture());
    batch.draw(fboRegion, 0, 0);
    batch.setShader(null);
    batch.end();
  }
Ejemplo n.º 25
0
 public void end() {
   fbo.end();
 }
Ejemplo n.º 26
0
 public void begin() {
   fbo.begin();
 }
Ejemplo n.º 27
0
  @Override
  public void draw(Batch batch, float parentAlpha) {
    oldPro.set(batch.getProjectionMatrix());
    oldView.set(batch.getTransformMatrix());

    Rectangle temp = null;
    if (useFbo) {
      batch.end();
      try {
        // problem with libgdx, should'nt need try catch.
        temp = ScissorStack.popScissors();
      } catch (IllegalStateException ignored) {
      }
      fbo.begin();
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    }

    // camera.setX(camera.getX()+1);
    // camera.setRotation(camera.getRotation()+2);

    camera.track(view);
    camera.apply(ortho);
    ortho.update();
    batch.setProjectionMatrix(ortho.projection);
    batch.setTransformMatrix(ortho.view);

    if (useFbo) {
      batch.begin();
    }

    Iterator<PObject> iter = view.getIterator();
    while (iter.hasNext()) {
      PSprite sprite = (PSprite) iter.next();
      sprite.draw(batch, spriteReference);
    }

    if (useFbo) {
      batch.end();
      fbo.end();
    }

    batch.setProjectionMatrix(oldPro);
    batch.setTransformMatrix(oldView);

    if (useFbo) {
      if (temp != null) {
        ScissorStack.pushScissors(temp);
      }

      Color oldColor = batch.getColor();
      batch.setColor(tint);
      batch.begin();

      batch.draw(
          fbo.getColorBufferTexture(),
          0,
          0,
          getWidth(),
          getHeight(),
          0,
          0,
          fbo.getWidth(),
          fbo.getHeight(),
          false,
          true);

      batch.setColor(oldColor);
    }
  }
Ejemplo n.º 28
0
 /** When needed graphics memory could be invalidated so buffers should be rebuilt. */
 public void rebind() {
   texture1 = buffer1.getColorBufferTexture();
   texture2 = buffer2.getColorBufferTexture();
 }
Ejemplo n.º 29
0
  @Override
  public void create() {
    FlxG.setBgColor(Breath.bgcolor);

    frame_buffer = new FrameBuffer(Pixmap.Format.RGBA8888, FlxG.width, FlxG.height, true);

    title_text =
        new FlxText(4, 24, 290, "\"I Can Hold My Breath Forever\"\nUse arrow keys to move.");
    title_text.setFormat(GardeniaFont, 8, 0xffffffff);

    PlayState.world_darkness = new FlxSprite(0, 0);
    world_darkness.scrollFactor.x = world_darkness.scrollFactor.y = 0;
    world_darkness.setPixels(
        new AtlasRegion(
            frame_buffer.getColorBufferTexture(),
            0,
            0,
            frame_buffer.getWidth(),
            frame_buffer.getHeight()));
    world_darkness.framePixels.flip(false, true);
    world_darkness.blend = "multiply";
    world_darkness.setAlpha(0);
    world_darkness.visible = false;

    frame_buffer_fill = new FlxSprite(0, 0);
    frame_buffer_fill.makeGraphic(FlxG.width, FlxG.height, darkness_color);
    frame_buffer_fill.scrollFactor.x = frame_buffer_fill.scrollFactor.y = 0;

    world = new World();

    background = new FlxSprite(0, 0, BackgroundImage);

    // Add restore point sprites
    notes = new FlxGroup();
    for (RestorePoint note : world.airbubble_restore_points.values()) {
      if (note.note) {
        notes.add(note);
      }
    }

    player = new Player(4 * World.TILE_SIZE, 9 * World.TILE_SIZE, world_darkness);

    darkness = new FlxSprite(0, 0);
    darkness.makeGraphic(FlxG.width, FlxG.height, 0xff000000);
    darkness.scrollFactor.x = darkness.scrollFactor.y = 0;
    darkness.setAlpha(0.0f);

    oxygen_timer_display = new FlxText(0, 0, FlxG.width, "10");
    oxygen_timer_display.setFormat(null, 160, 0xffffff, "center");
    oxygen_timer_display.setAlpha(0.0f);
    oxygen_timer_display.scrollFactor.x = oxygen_timer_display.scrollFactor.y = 0;

    story_overlay = new StoryOverlay(8, 2);

    world.walls_map.follow();
    // FlxG.followAdjust(0.5, 0.5);
    // FlxG.follow(player, 2.5);
    FlxG.camera.follow(player);

    // this.add(world.walls_map);
    // this.add(world.water_map);
    this.add(background);
    this.add(world.firefish_group);
    this.add(world.octopus);
    this.add(notes);
    this.add(player);
    this.add(world_darkness);
    this.add(darkness);
    this.add(oxygen_timer_display);
    this.add(story_overlay);
    this.add(title_text);
  }
Ejemplo n.º 30
0
 @Override
 public void destroy() {
   frame_buffer.dispose();
 }