Example usage for android.opengl GLES20 glClear

List of usage examples for android.opengl GLES20 glClear

Introduction

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

Prototype

public static native void glClear(int mask);

Source Link

Usage

From source file:helloopengles.example.com.MyGLRenderer.java

@Override
public void onDrawFrame(GL10 unused) {
    float[] scratch = new float[16];

    // Draw background color
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    // Draw square
    mSquare.draw(mScale);//  w  w w  .  j  a  v  a 2  s  . c o  m
}

From source file:com.dmitrybrant.android.cardboardmpo.MainActivity.java

@Override
public void onDrawEye(Eye eye) {
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    // Apply the eye transformation to the camera.
    Matrix.multiplyMM(view, 0, eye.getEyeView(), 0, camera, 0);

    // TODO: Do something with the head transform (e.g. pan the photo around)
    // For now, just reset the view matrix, so that the photo is in the center at all times.
    Matrix.setIdentityM(view, 0);//  w w  w.  j  a v  a 2  s  . com

    float[] perspective = eye.getPerspective(Z_NEAR, Z_FAR);
    if (eye.getType() == 1) {
        Matrix.multiplyMM(modelView, 0, view, 0, rectLeftEye.getModelMatrix(), 0);
        Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0);
        rectLeftEye.draw(modelViewProjection);
    } else {
        Matrix.multiplyMM(modelView, 0, view, 0, rectRightEye.getModelMatrix(), 0);
        Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0);
        rectRightEye.draw(modelViewProjection);
    }
}

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

@Override
public void onDrawFrame(GL10 gl) {
    if (mSimulation) {

        setChanged();//  ww  w . j a  v  a 2 s  .c o  m
        notifyObservers();

        GLES20.glClearColor(1, 1, 1, 1);
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

        // Draw particles
        showFrameRate();

        mWorldLock.lock();

        try {

            drawBackgroundTexture();

            mWorldLock.stepWorld();

            mParticleRenderer.onDrawFrame(gl);

            mSolidWorld.onDrawFrame(gl);

            if (DEBUG_DRAW) {
                mDebugRenderer.onDrawFrame(gl);
            }
        } finally {
            mWorldLock.unlock();
        }

    }
}

From source file:com.wlanjie.streaming.camera.CameraView.java

@Override
public void onDrawFrame(GL10 gl) {
    GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    mSurfaceTexture.updateTexImage();//from   w w  w . j a  v a2  s  .  com

    mSurfaceTexture.getTransformMatrix(mSurfaceMatrix);
    Matrix.multiplyMM(mTransformMatrix, 0, mSurfaceMatrix, 0, mProjectionMatrix, 0);
    mEglCore.setTextureTransformMatrix(mTransformMatrix);
    mEglCore.onDrawFrame(mTextureId);
    mHandler.sendEmptyMessage(0);
}

From source file:com.watabou.noosa.Game.java

@Override
public void onDrawFrame(GL10 gl) {
    if (instance() == null || width() == 0 || height() == 0) {
        return;/*from  w  w  w . j av a  2 s.  co m*/
    }

    if (paused) {
        GLES20.glScissor(0, 0, width(), height());
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
        return;
    }

    SystemTime.tick();
    long rightNow = SystemTime.now();
    step = (now == 0 ? 0 : rightNow - now);
    now = rightNow;

    step();

    NoosaScript.get().resetCamera();
    GLES20.glScissor(0, 0, width(), height());
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    draw();
}

From source file:eu.sathra.SathraActivity.java

@SuppressLint("WrongCall")
@Override//ww w . java  2  s.c om
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();
}

From source file:com.kentdisplays.synccardboarddemo.MainActivity.java

/**
 * Draws a frame for an eye. The transformation for that eye (from the camera) is passed in as
 * a parameter./*from w  w  w . j  a v  a  2  s  .co  m*/
 * @param transform The transformations to apply to render this eye.
 */
@Override
public void onDrawEye(EyeTransform transform) {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
    GLES20.glClearColor(0f, 0f, 0f, 1.00f); // Dark background so text shows up well

    mPositionParam = GLES20.glGetAttribLocation(mGlProgram, "a_Position");
    mNormalParam = GLES20.glGetAttribLocation(mGlProgram, "a_Normal");
    mColorParam = GLES20.glGetAttribLocation(mGlProgram, "a_Color");

    GLES20.glEnableVertexAttribArray(mPositionParam);
    GLES20.glEnableVertexAttribArray(mNormalParam);
    GLES20.glEnableVertexAttribArray(mColorParam);
    checkGLError("mColorParam");

    // Apply the eye transformation to the camera.
    Matrix.multiplyMM(mView, 0, transform.getEyeView(), 0, mCamera, 0);

    // Set the position of the light
    Matrix.multiplyMV(mLightPosInEyeSpace, 0, mView, 0, mLightPosInWorldSpace, 0);
    GLES20.glUniform3f(mLightPosParam, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);

    // Draw the pages.
    for (Page page : mPages) {
        page.draw(transform.getPerspective(), mView);
        checkGLError("Drawing page");
    }

    // Set mModelView for the floor, so we draw floor in the correct location
    Matrix.multiplyMM(mModelView, 0, mView, 0, mModelFloor, 0);
    Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(), 0, mModelView, 0);
    drawFloor(transform.getPerspective());
}

From source file:com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.java

/**
 * Draws a frame for an eye.//from ww  w  .j  a  v a2s .  c  o m
 *
 * @param eye The eye to render. Includes all required transformations.
 */
@Override
public void onDrawEye(Eye eye) {
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    checkGLError("colorParam");

    // Apply the eye transformation to the camera.
    Matrix.multiplyMM(view, 0, eye.getEyeView(), 0, camera, 0);

    // Set the position of the light
    Matrix.multiplyMV(lightPosInEyeSpace, 0, view, 0, LIGHT_POS_IN_WORLD_SPACE, 0);

    // Build the ModelView and ModelViewProjection matrices
    // for calculating cube position and light.
    float[] perspective = eye.getPerspective(Z_NEAR, Z_FAR);
    Matrix.multiplyMM(modelView, 0, view, 0, modelCube, 0);
    Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0);
    drawCube();

    float[] mRotationCube = new float[16];
    //Not sure if we can just reuse modelView like this
    Matrix.multiplyMM(modelView, 0, view, 0, modelMiniCube, 0);
    //Matrix.multiplyMM(mRotationCube, 0, view, 0, modelView, 0);

    //Not working 
    //float[] ident = new Matrix(eye.getPerspective(Z_NEAR, Z_FAR));
    //Matrix.setIdentityM(ident, 0); //Cheating so that we have relative hand movement
    //end not working

    Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0);
    //Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, mRotationCube, 0);

    //doesn't work :(
    //Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelMiniCube, 0);

    drawMiniCube();

    // Set modelView for the floor, so we draw floor in the correct location
    Matrix.multiplyMM(modelView, 0, view, 0, modelFloor, 0);
    Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0);
    drawFloor();
}

From source file:com.tumblr.cardboard.Tumblr3DActivity.java

/**
 * Draws a frame for an eye. The transformation for that eye (from the camera) is passed in as
 * a parameter.//from w  w w  . ja  v a2s. co  m
 *
 * @param eye The transformations to apply to render this eye.
 */
@Override
public void onDrawEye(Eye eye) {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    mPositionParam = GLES20.glGetAttribLocation(mGlProgram, "a_Position");
    mNormalParam = GLES20.glGetAttribLocation(mGlProgram, "a_Normal");
    mColorParam = GLES20.glGetAttribLocation(mGlProgram, "a_Color");
    mRectTextureCoordinateParam = GLES20.glGetAttribLocation(mGlProgram, "a_TexCoordinate");

    GLES20.glEnableVertexAttribArray(mPositionParam);
    GLES20.glEnableVertexAttribArray(mNormalParam);
    GLES20.glEnableVertexAttribArray(mColorParam);
    checkGLError("mColorParam");

    // Apply the eye transformation to the camera.
    Matrix.multiplyMM(mView, 0, eye.getEyeView(), 0, mCamera, 0);

    // Set the position of the light
    Matrix.multiplyMV(mLightPosInEyeSpace, 0, mView, 0, mLightPosInWorldSpace, 0);
    GLES20.glUniform3f(mLightPosParam, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);

    // Set mModelView for the floor, so we draw floor in the correct location
    Matrix.multiplyMM(mModelView, 0, mView, 0, mModelFloor, 0);
    Matrix.multiplyMM(mModelViewProjection, 0, eye.getPerspective(Z_NEAR, Z_FAR), 0, mModelView, 0);
    drawFloor(eye.getPerspective(Z_NEAR, Z_FAR));

    // Build the ModelView and ModelViewProjection matrices
    // for calculating rect position and light.
    for (int i = 0; i < mModelRect.length; i++) {
        Matrix.multiplyMM(mModelView, 0, mView, 0, mModelRect[i], 0);
        Matrix.multiplyMM(mModelViewProjection, 0, eye.getPerspective(Z_NEAR, Z_FAR), 0, mModelView, 0);
        drawRect(i);
    }
}

From source file:com.sveder.cardboardpassthrough.MainActivity.java

/**
 * Prepares OpenGL ES before we draw a frame.
 * @param headTransform The head transformation in the new frame.
 *///from ww  w. ja  va2 s  .  co  m
@Override
public void onNewFrame(HeadTransform headTransform) {
    //        GLES20.glUseProgram(mGlProgram);
    //
    //        mModelViewProjectionParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVP");
    //        mLightPosParam = GLES20.glGetUniformLocation(mGlProgram, "u_LightPos");
    //        mModelViewParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVMatrix");
    //        mModelParam = GLES20.glGetUniformLocation(mGlProgram, "u_Model");
    //        mIsFloorParam = GLES20.glGetUniformLocation(mGlProgram, "u_IsFloor");
    //
    //        // Build the Model part of the ModelView matrix.
    //        Matrix.rotateM(mModelCube, 0, TIME_DELTA, 0.5f, 0.5f, 1.0f);
    //
    //        // Build the camera matrix and apply it to the ModelView.
    //        Matrix.setLookAtM(mCamera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
    //
    //        headTransform.getHeadView(mHeadView, 0);
    //
    //        checkGLError("onReadyToDraw");

    float[] mtx = new float[16];
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
    surface.updateTexImage();
    surface.getTransformMatrix(mtx);

}