This page concerns the Vuforia Engine API version 9.8 and earlier. It has been deprecated and will no longer be actively updated.
These code snippets show how to freeze the video background without stopping the tracker.
The video background freezing functionality is enabled by the begin() method of the Renderer class, which optionally accepts a custom State parameter.
The following code sample shows how this functionality can be enabled by holding the State object at a given frame and reusing the same state in a subsequent frame:
C++:
Vuforia::State frozenState; // adding global variable
void
renderFrame(JNIEnv* env, jobject obj, bool renderFrozenFrame, bool freezeCurrent)
{
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Vuforia::State state;
if ( renderFrozenFrame )
{
// Get the state from Vuforia and mark the beginning of a rendering section
state = Vuforia::Renderer::getInstance().begin( frozenState );
}
else
{
state = Vuforia::Renderer::getInstance().begin();
if ( freezeCurrent )
{
frozenState = state;
// Release camera
Vuforia::CameraDevice::getInstance().stop();
Vuforia::CameraDevice::getInstance().deinit();
}
}
// Explicitly render the Video Background
Vuforia::Renderer::getInstance().drawVideoBackground();
// Your rendering code
// Finish rendering
Vuforia::Renderer::getInstance().end();
}
Java:
State frozenState;
void
renderFrame(bool renderFrozenFrame, bool freezeCurrent)
{
// Clear color and depth buffer
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
State state;
if ( renderFrozenFrame )
{
// Get the state from Vuforia and mark the beginning of a rendering section
state = Renderer.getInstance().begin( frozenState );
}
else
{
state = Renderer.getInstance().begin();
if ( freezeCurrent )
{
frozenState = state;
// Release camera
CameraDevice.getInstance().stop();
CameraDevice.getInstance().deinit();
}
}
// Explicitly render the Video Background
Renderer.getInstance().drawVideoBackground();
// Your rendering code
// Finish rendering
Renderer.getInstance().end();
}