Example usage for android.opengl GLES20 glGenFramebuffers

List of usage examples for android.opengl GLES20 glGenFramebuffers

Introduction

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

Prototype

public static native void glGenFramebuffers(int n, int[] framebuffers, int offset);

Source Link

Usage

From source file:Main.java

/**
 * Creates a new frame buffer object.  This is typically used when rendering to textures.
 *
 * @return GL handle to frame buffer//w  ww.j a v a2s. com
 */
public static int createFrameBuffer() {
    int[] frameBufferHandles = new int[1];
    GLES20.glGenFramebuffers(1, frameBufferHandles, 0);
    return frameBufferHandles[0];
}

From source file:eu.sathra.SathraActivity.java

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    if (mParams.width == 0 && mParams.height == 0) {
        mParams.width = width;/*ww w. j av a 2 s . c  om*/
        mParams.height = height;
    } else if (mParams.width == 0) {
        float screenRatio = width / (float) height;
        mParams.width = (int) (mParams.height * screenRatio);
    } else if (mParams.height == 0) {
        float screenRatio = height / (float) width;
        mParams.height = (int) (mParams.width * screenRatio);
    }

    gl.glViewport(0, 0, width, height);// mParams.width, mParams.height);

    Log.debug(String.format(SURFACE_CREATE_MSG_FORMAT, width, height, mParams.width, mParams.height));

    if (!mWasInitiated) {
        GLES20.glGenFramebuffers(1, buf, 0);
        GLES20.glGenTextures(1, tex, 0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex[0]);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
        IntBuffer tmp = ByteBuffer.allocateDirect(mParams.width * mParams.height * 4)
                .order(ByteOrder.nativeOrder()).asIntBuffer();
        GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, mParams.width, mParams.height, 0,
                GLES20.GL_RGBA, GLES20.GL_UNSIGNED_SHORT_4_4_4_4, tmp);

        shad = new Sprite(new Texture(tex[0], mParams.width, mParams.height));
        shad.setPivot(0.5f, 0.5f);

        onEngineInitiated();

        mWasInitiated = true;
    }
}