0

I work on a project with Vuforia. I use VideoPlayback sample from Vuforia.

When Vuforia detect a marker, a video play as overlay on this marker. I try to apply a chromakey on video overlay. I find this article http://pilcrowpipe.blogspot.fr/2013/03/chroma-keying-transparent-background.html

I try to implement the code but nothing work. I think this example use video background for chromakey but I want chromakey on overlay video. Am I right ?

In Vuforia Sample, I think I must change something in renderFrameWithState function.

if (NOT_READY != currentStatus) {
        // Convert trackable pose to matrix for use with OpenGL
        // ...

        /// TEST doesn't work
        //glDepthFunc(GL_LEQUAL);
        //glEnable(GL_BLEND);
        //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        ///

        // ...

        glUseProgram(shaderProgramID);

        glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, quadVertices);
        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, quadNormals);
        glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, texCoords);

        glEnableVertexAttribArray(vertexHandle);
        glEnableVertexAttribArray(normalHandle);
        glEnableVertexAttribArray(textureCoordHandle);

        // I think I must change something in code above...
        // But what and where ????
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, frameTextureID);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjectionVideo.data[0]);
        glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);
        glDrawElements(GL_TRIANGLES, kNumQuadIndices, GL_UNSIGNED_SHORT, quadIndices);

        glDisableVertexAttribArray(vertexHandle);
        glDisableVertexAttribArray(normalHandle);
        glDisableVertexAttribArray(textureCoordHandle);

        glUseProgram(0);
    }

I'm completely noob with OpenGL ES.

Anybody can help me ?

Thanks

kopacabana
  • 437
  • 3
  • 17

2 Answers2

0

After searching, I found the solution !

In VideoPlaybackEAGL.mm, I add this code in renderFrameWithState function.

if (NOT_READY != currentStatus) {
    // Convert trackable pose to matrix for use with OpenGL
    // ...

    /// It's work
    glDepthFunc(GL_LEQUAL);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    ///

    // ...

    glUseProgram(shaderProgramID);

    glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, quadVertices);
    glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, quadNormals);
    glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, texCoords);

    glEnableVertexAttribArray(vertexHandle);
    glEnableVertexAttribArray(normalHandle);
    glEnableVertexAttribArray(textureCoordHandle);

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, frameTextureID);
    glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjectionVideo.data[0]);
    glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);
    glDrawElements(GL_TRIANGLES, kNumQuadIndices, GL_UNSIGNED_SHORT, quadIndices);

    glDisableVertexAttribArray(vertexHandle);
    glDisableVertexAttribArray(normalHandle);
    glDisableVertexAttribArray(textureCoordHandle);

    glUseProgram(0);

    // Adding code above to resolve the problem...
    glDepthFunc(GL_LEQUAL);
    glEnable(GL_BLEND);
}

And it's work ! I change a little the vertex shader to correct z axis.

kopacabana
  • 437
  • 3
  • 17
0

the last

glEnable(GL_BLEND);

Should be:

glDisable(GL_BLEND);

in order to not freeze the background.

Thanks for the code!