Example usage for android.opengl GLES20 GL_FRAMEBUFFER

List of usage examples for android.opengl GLES20 GL_FRAMEBUFFER

Introduction

In this page you can find the example usage for android.opengl GLES20 GL_FRAMEBUFFER.

Prototype

int GL_FRAMEBUFFER

To view the source code for android.opengl GLES20 GL_FRAMEBUFFER.

Click Source Link

Usage

From source file:Main.java

public static void unBindFrameBuffer() {
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
}

From source file:Main.java

public static void bindFrameTexture(int frameBufferId, int textureId) {
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBufferId);
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D,
            textureId, 0);//w w  w .  j a  v a  2 s .  c o m
}

From source file:Main.java

/**
 * Make a given frameBuffer and texture render targets active. Example of setup for rendering to viewport: PheiffGLUtils.bindFrameBuffer(0, -1, -1);
 * <p/>/*from   w  ww  . j  a v  a 2s . c  om*/
 * Example of setup for rendering to a texture: PheiffGLUtils.bindFrameBuffer(frameBufferHandle, colorRenderTextureHandle, depthRenderTextureHandle);
 *
 * @param frameBufferHandle        GL handle to a frame buffer object to use OR 0 for the main framebuffer (viewport)
 * @param colorRenderTextureHandle GL handle to the texture where colors should be rendered or -1 to not use this feature
 * @param depthRenderTextureHandle GL handle to the texture where depth information should be rendered  or -1 to not use this feature
 */
public static void bindFrameBuffer(int frameBufferHandle, int colorRenderTextureHandle,
        int depthRenderTextureHandle) {
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBufferHandle);
    if (frameBufferHandle != 0) {
        GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D,
                colorRenderTextureHandle, 0);
        GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_TEXTURE_2D,
                depthRenderTextureHandle, 0);
    }
}

From source file:com.google.fpl.liquidfunpaint.renderer.ParticleRenderer.java

private void drawParticleSystemToScreen(DrawableParticleSystem dps) {
    dps.onDrawFrame();/*www.ja  va  2 s  .c o  m*/

    // Draw the particles
    drawParticles(dps);

    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glViewport(0, 0, PhysicsLoop.getInstance().sScreenWidth, PhysicsLoop.getInstance().sScreenHeight);

    // Copy the water particles to screen
    mWaterScreenRenderer.draw(mTransformFromTexture);

    // Copy the other particles to screen
    mScreenRenderer.draw(mTransformFromTexture);
}

From source file:com.google.fpl.liquidfunpaint.ParticleRenderer.java

/**
 * This should only execute on the GLSurfaceView thread.
 *//*  w  w w .j a va 2 s  . c om*/
public void draw() {
    // Per frame resets of buffers
    mParticlePositionBuffer.rewind();
    mParticleColorBuffer.rewind();
    mParticleWeightBuffer.rewind();
    mParticleRenderList.clear();

    ParticleSystem ps = Renderer.getInstance().acquireParticleSystem();
    try {
        int worldParticleCount = ps.getParticleCount();
        // grab the most current particle buffers
        ps.copyPositionBuffer(0, worldParticleCount, mParticlePositionBuffer);
        ps.copyColorBuffer(0, worldParticleCount, mParticleColorBuffer);
        ps.copyWeightBuffer(0, worldParticleCount, mParticleWeightBuffer);

        GLES20.glClearColor(0, 0, 0, 0);

        // Draw the particles
        drawParticles();

        GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
        GLES20.glViewport(0, 0, Renderer.getInstance().sScreenWidth, Renderer.getInstance().sScreenHeight);

        // Draw the paper texture.
        TextureRenderer.getInstance().drawTexture(mPaperTexture, Renderer.MAT4X4_IDENTITY, -1, -1, 1, 1);

        // Copy the water particles to screen
        mWaterScreenRenderer.draw(mTransformFromTexture);

        // Copy the other particles to screen
        mScreenRenderer.draw(mTransformFromTexture);
    } finally {
        Renderer.getInstance().releaseParticleSystem();
    }
}

From source file:eu.sathra.SathraActivity.java

@SuppressLint("WrongCall")
@Override/*from w  w  w  . jav a  2s . co m*/
public void onDrawFrame(GL10 gl) {
    gl.glViewport(0, 0, this.getScreenWidth(), this.getScreenHeight());
    // Update time variables
    mTimeDelta = System.currentTimeMillis() - mLastDrawTimestamp;
    mLastDrawTimestamp = System.currentTimeMillis();
    mTime += mTimeDelta;
    mVirtualTimeDelta = (long) (mTimeDelta * getTimeScale());
    mVirtualTime += mVirtualTimeDelta;

    // Setup defaults
    gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

    // Clear BG
    float r = (float) Color.red(mParams.bgColor) / 255;
    float g = (float) Color.green(mParams.bgColor) / 255;
    float b = (float) Color.blue(mParams.bgColor) / 255;
    float a = (float) Color.alpha(mParams.bgColor) / 255;
    gl.glClearColor(r, g, b, a);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    GLES20.glBlendEquation(GLES20.GL_FUNC_ADD);

    gl.glMatrixMode(GL10.GL_TEXTURE);
    gl.glLoadIdentity();

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

    // gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);

    mRootNode.onDraw(gl, mVirtualTime, mVirtualTimeDelta);

    // Draw lights and shadows
    gl.glMatrixMode(GL10.GL_TEXTURE);
    gl.glLoadIdentity();
    gl.glScalef(1, -1, 1); // Frame Buffers are upside down
    gl.glMatrixMode(GL10.GL_MODELVIEW);

    CameraNode activeCam = CameraNode.getActiveCamera();

    if (activeCam != null) {
        shad.setPosition(0, 0);// this.getResolutionWidth()/2,
        // this.getResolutionHeight()/2);//activeCam.getAbsoluteX(),
        // activeCam.getAbsoluteY());
    }

    gl.glBlendFunc(GL10.GL_DST_COLOR, GL10.GL_ONE_MINUS_SRC_ALPHA);

    shad.draw(gl);

    gl.glViewport(0, 0, this.getResolutionWidth(), this.getResolutionHeight()); // SDfDSFSDFS
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, buf[0]);
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D,
            tex[0], 0);

    // Clear shadow
    r = (float) Color.red(mParams.ambientColor) / 255;
    g = (float) Color.green(mParams.ambientColor) / 255;
    b = (float) Color.blue(mParams.ambientColor) / 255;
    a = (float) Color.alpha(mParams.ambientColor) / 255;

    gl.glClearColor(r, g, b, a);
    GLES20.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    // TODO: CONCURENT MOD EXCEPTION
    try {
        Dyn4jPhysics.getInstance().getWorld().updatev(mVirtualTimeDelta * MILISECONDS_TO_SECONDS);
    } catch (ConcurrentModificationException e) {

    }

    // if (mIsRunning)
    onUpdate(mVirtualTime, mVirtualTimeDelta);

    // Update fps counter
    mFPS = 1000f / mTimeDelta;

    // mDebugView.postInvalidate();

    // System.gc();
}