Nexus 设备中的 OpenGL2.0 渲染问题(Android 中的 Vuforia)

Problems with OpenGL2.0 rendering in Nexus devices (Vuforia in Android)

我正在尝试在程序找到目标时用 png 图像替换茶壶。我正在使用 vuforia 4。

这是我使用的代码:

private void renderFrame() {

    State state = mRenderer.begin();
    mRenderer.drawVideoBackground();
    if (Renderer.getInstance().getVideoBackgroundConfig().getReflection() == VIDEO_BACKGROUND_REFLECTION.VIDEO_BACKGROUND_REFLECTION_ON)
        GLES20.glFrontFace(GLES20.GL_CW); // Front camera
    else
        GLES20.glFrontFace(GLES20.GL_CCW); // Back camera

    if (state.getNumTrackableResults() == 0)
        displayMessage("nothing");
    // did we find any trackables this frame?
    for (int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++) {

        TrackableResult result = state.getTrackableResult(tIdx);
        Trackable trackable = result.getTrackable();
        ImageTarget itarget = (ImageTarget) trackable;

        Log.d("USER", itarget.getName());
        Matrix44F modelViewMatrix_Vuforia = Tool
                .convertPose2GLMatrix(result.getPose());
        float[] modelViewMatrix = modelViewMatrix_Vuforia.getData();
        float[] modelViewProjection = new float[16];
        Matrix.translateM(modelViewMatrix, 0, 0.0f, 0.0f,
                OBJECT_SCALE_FLOAT);
        Matrix.scaleM(modelViewMatrix, 0, OBJECT_SCALE_FLOAT,
                OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT);
        Matrix.translateM(modelViewMatrix, 0, 0.0f, 0.0f, 0.0f);
        Vec3F targetSize = itarget.getSize();
        Matrix.scaleM(modelViewMatrix, 0, targetSize.getData()[0],
                targetSize.getData()[1], 1.0f);
        Matrix.multiplyMM(modelViewProjection, 0, vuforiaAppSession
                .getProjectionMatrix().getData(), 0, modelViewMatrix, 0);

        GLES20.glUseProgram(shaderProgramID);

        if (!mActivity.isExtendedTrackingActive()) {

            GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT,
                    false, 0, mTeapot.getVertices());
            GLES20.glVertexAttribPointer(normalHandle, 3, GLES20.GL_FLOAT,
                    false, 0, mTeapot.getNormals());
            GLES20.glVertexAttribPointer(textureCoordHandle, 2,
                    GLES20.GL_FLOAT, false, 0, mTeapot.getTexCoords());
            GLES20.glEnableVertexAttribArray(vertexHandle);
            GLES20.glEnableVertexAttribArray(normalHandle);
            GLES20.glEnableVertexAttribArray(textureCoordHandle);

            int index = 0;
            if (itarget.getName().equals("ERMITA-2-1")) {
                index = 1;
            }
            GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,
                    mTextures.get(index).mTextureID[0]);
            GLES20.glUniform1i(texSampler2DHandle, 0);
            // pass the model view matrix to the shader
            GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false,
                    modelViewProjection, 0);
            GLES20.glEnable(GLES20.GL_BLEND);
            GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA,
                    GLES20.GL_ONE_MINUS_SRC_ALPHA);
            GLES20.glDrawElements(GLES20.GL_TRIANGLES, 6,
                    GLES20.GL_UNSIGNED_SHORT, mTeapot.getIndices());
            GLES20.glDisable(GLES20.GL_BLEND);

            lastTrackableId = -1;

            GLES20.glDisableVertexAttribArray(vertexHandle);
            GLES20.glDisableVertexAttribArray(normalHandle);
            GLES20.glDisableVertexAttribArray(textureCoordHandle);
            //
        } else {
            GLES20.glDisable(GLES20.GL_CULL_FACE);
            GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT,
                    false, 0, mBuildingsModel.getVertices());
            GLES20.glVertexAttribPointer(normalHandle, 3, GLES20.GL_FLOAT,
                    false, 0, mBuildingsModel.getNormals());
            GLES20.glVertexAttribPointer(textureCoordHandle, 2,
                    GLES20.GL_FLOAT, false, 0,
                    mBuildingsModel.getTexCoords());

            GLES20.glEnableVertexAttribArray(vertexHandle);
            GLES20.glEnableVertexAttribArray(normalHandle);
            GLES20.glEnableVertexAttribArray(textureCoordHandle);

            GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,
                    mTextures.get(0).mTextureID[0]);
            GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false,
                    modelViewProjection, 0);
            GLES20.glUniform1i(texSampler2DHandle, 0);
            GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0,
                    mBuildingsModel.getNumObjectVertex());

            SampleUtils.checkGLError("Renderer DrawBuildings");
        }
        SampleUtils.checkGLError("Render Frame");
    }

    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    // GLES20.glDisable(GLES20.GL_BLEND);
    mRenderer.end();
}

它适用于某些设备,例如 Galaxy S2 和通用平板电脑。我遇到的问题出现在以下设备上:

Nexus 4: Android 5.1: 识别目标(打印日志),屏幕上出现一些奇怪的东西。它似乎设法渲染了纹理,但它立即消失了。

Nexus 10:Android 5.1:识别目标(打印日志)但什么都不做,根本不渲染。没有错误消息。

一加一:Android 4.4:与 Nexus 10 相同。

有什么想法吗?

我也在 Vuforia 开发论坛上发布了这个问题,但它似乎是渲染问题而不是 Vuforia 问题。

通过添加解决:

GLES20.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

就在renderFrame方法的最开始