android - 在 Android 中清除 OpenGL 显示。

标签 android opengl-es

我有一个类可以通过 bool 值确定是否应该绘制一个正方形。问题是,即使 bool 值是假的,正方形也会保持不变。我的问题是,如果 bool 值出现错误,我该如何删除绘制的正方形?

public void onDrawFrame(GL10 unused) {

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

    // Set the camera position (View matrix)
    Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    // Calculate the projection and view transformation
    Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);

    // Draw square
    Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f);

    // Combine the rotation matrix with the projection and camera view
    Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);

    if (drawObject == true) {
    mSquare.draw(mMVPMatrix);
    }

    // Draw Square
}

最佳答案

好的,我找到了答案。

创建一个方法:

public void clearBuffers(boolean color, boolean depth, boolean stencil) {
    int bits = 0;
    if (color) {
        bits = GLES20.GL_COLOR_BUFFER_BIT;
    }
    if (depth) {
        bits |= GLES20.GL_DEPTH_BUFFER_BIT;
    }
    if (stencil) {
        bits |= GLES20.GL_STENCIL_BUFFER_BIT;
    }
    if (bits != 0) {
        GLES20.glClear(bits);
    }
}

然后调用它:

    clearBuffers(true, true, true);

清除屏幕上的所有内容。

关于android - 在 Android 中清除 OpenGL 显示。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15007129/

相关文章:

android - 为什么使用 Messenger 而不是将引用传递给 Handler?

java - Android - 在同一类中传递 uri/string/int

java - 为什么 glDeleteTextures() 在 OpenGL ES 2.0 中有三个参数?

Android - 如何摆脱 3D 对象的黑色背景并查看相机 View ?

java - 当我尝试运行新的示例应用程序时,无法在Flutter中打开xmltree错误

Android,使用超声波传输信号

android - 恢复时间内存优化

java - FloatBuffer 损坏问题

android - 关于 Android 中高性能绘图的提示

iphone - 我需要 OpenGL ES 1.1 来渲染带有纹理的对象,而其他对象只需要简单的顶点绘制和颜色