@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();
  }
Beispiel #2
0
 // int version
 protected T setParams(Parameter param, int value) {
   if (!programBegan) {
     programBegan = true;
     program.begin();
   }
   program.setUniformi(param.mnemonic(), value);
   return (T) this;
 }
Beispiel #3
0
 private void setupMatrices() {
   if (!Gdx.graphics.isGL20Available()) {
     GL10 gl = Gdx.gl10;
     gl.glMatrixMode(GL10.GL_PROJECTION);
     gl.glLoadMatrixf(projectionMatrix.val, 0);
     gl.glMatrixMode(GL10.GL_MODELVIEW);
     gl.glLoadMatrixf(transformMatrix.val, 0);
   } else {
     combinedMatrix.set(projectionMatrix).mul(transformMatrix);
     if (customShader != null) {
       customShader.setUniformMatrix("u_proj", projectionMatrix);
       customShader.setUniformMatrix("u_trans", transformMatrix);
       customShader.setUniformMatrix("u_projTrans", combinedMatrix);
       customShader.setUniformi("u_texture", 0);
     } else {
       shader.setUniformMatrix("u_projectionViewMatrix", combinedMatrix);
       shader.setUniformi("u_texture", 0);
     }
   }
 }
Beispiel #4
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();
  }
Beispiel #5
0
 public void setElement(SceneElement e) {
   super.setElement(e);
   RuntimeDrawable<?> r = (RuntimeDrawable<?>) assetHandler.getRuntimeAsset(transition.getMask());
   texture = r.getTextureHandle();
   offset = new Vector3();
   if (maskShader == null) {
     maskShader =
         new ShaderProgram(
             assetHandler.getTextFile("@binary/shaders/mask.vert"),
             assetHandler.getTextFile("@binary/shaders/mask.frag"));
     if (maskShader.getLog().length() != 0) logger.warn(maskShader.getLog());
     nextSceneBuffer = new FrameBuffer(Format.RGBA8888, 800, 600, false);
   }
   maskShader.begin();
   maskShader.setUniformi("mask_texture", 1);
   maskShader.setAttributef("a_sizes", 800, 600, r.getWidth(), r.getHeight());
   maskShader.end();
 }
  @Override
  public void render() {
    GL20 gl = Gdx.gl20;
    gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClearColor(0.7f, 0, 0, 1);
    gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    gl.glEnable(GL20.GL_TEXTURE_2D);
    shader.begin();
    shader.setUniformi("u_texture", 0);
    texture.bind();
    vbo.bind(shader);
    indices.bind();
    gl.glDrawElements(GL20.GL_TRIANGLES, 3, GL20.GL_UNSIGNED_SHORT, indices.getBuffer().position());
    indices.unbind();
    vbo.unbind(shader);
    shader.end();
  }
Beispiel #7
0
  private void initialize(
      int FBO_W,
      int FBO_H,
      FrameBuffer fbo,
      boolean hasDepth,
      boolean useBlending,
      boolean use32bitFBO) {
    blending = useBlending;
    Format format = null;

    if (use32bitFBO) {
      if (useBlending) {
        format = Format.RGBA8888;
      } else {
        format = Format.RGB888;
      }

    } else {
      if (useBlending) {
        format = Format.RGBA4444;
      } else {
        format = Format.RGB565;
      }
    }
    if (fbo == null) {
      frameBuffer =
          new FrameBuffer(format, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), hasDepth);
    } else {
      frameBuffer = fbo;
    }

    pingPongBuffer1 = new FrameBuffer(format, FBO_W, FBO_H, false);

    pingPongBuffer2 = new FrameBuffer(format, FBO_W, FBO_H, false);

    original = frameBuffer.getColorBufferTexture();
    pingPongTex1 = pingPongBuffer1.getColorBufferTexture();
    pingPongTex2 = pingPongBuffer2.getColorBufferTexture();

    fullScreenQuad = createFullScreenQuad();
    final String alpha = useBlending ? "alpha_" : "";

    bloomShader = BloomShaderLoader.createShader("screenspace", alpha + "bloom");

    if (useAlphaChannelAsMask) {
      tresholdShader = BloomShaderLoader.createShader("screenspace", "maskedtreshold");
    } else {
      tresholdShader = BloomShaderLoader.createShader("screenspace", alpha + "treshold");
    }

    blurShader = BloomShaderLoader.createShader("blurspace", alpha + "gaussian");

    setSize(FBO_W, FBO_H);
    setBloomIntesity(2.5f);
    setOriginalIntesity(0.8f);
    setTreshold(0.5f);

    bloomShader.begin();
    {
      bloomShader.setUniformi("u_texture0", 0);
      bloomShader.setUniformi("u_texture1", 1);
    }
    bloomShader.end();
  }
Beispiel #8
0
 // int
 protected void setParam(Parameter param, int value) {
   program.begin();
   program.setUniformi(param.mnemonic(), value);
   program.end();
 }