The version of my os is 2.2 and my phone always connected to the internet.
I comment out all of the initialization code,
This is the ImageTargets.cpp I had edited
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_setActivityPortraitMode(JNIEnv *, jobject, jboolean isPortrait)
{
LOG("IN setActivityPortraitMode");
isActivityInPortraitMode = isPortrait;
LOG("OUT setActivityPortraitMode");
}
JNIEXPORT int JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv *, jobject)
{
if(sflag==1){
LOG("111111");
int textureIndex=0;
//LOG("Java_com_qualcomm_QCARSamples_ImageTargets_GLRenderer_renderFrame");
// Clear color and depth buffer
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
LOG("222222222");
// Render video background:
QCAR::State state = QCAR::Renderer::getInstance().begin();
LOG("33333333");
// Did we find any trackables this frame?
for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)
{
// Get the trackable:
const QCAR::Trackable* trackable = state.getActiveTrackable(tIdx);
//QCAR::Matrix44F modelViewMatrix =
// QCAR::Tool::convertPose2GLMatrix(trackable->getPose());
// Choose the texture based on the target name:
//textureIndex = (!strcmp(trackable->getName(), "s1")) ? 1 : 2;
if(strcmp(trackable->getName(), "ftfm")){
textureIndex=1;
}
if(strcmp(trackable->getName(), "jtfm")){
textureIndex=2;
}
if(strcmp(trackable->getName(), "hb")){
textureIndex=3;
}
LOG("YOYUYOUOYOYY");
}
LOG("4444444444");
QCAR::Renderer::getInstance().end();
LOG("OUT 111 renderFrame");
return textureIndex;
}else{
LOG("ELSE IN renderFrame");
return 0;
}
}
void
configureVideoBackground()
{
// Get the default video mode:
LOG("the4");
QCAR::CameraDevice& cameraDevice = QCAR::CameraDevice::getInstance();
LOG("the5");
QCAR::VideoMode videoMode = cameraDevice.
getVideoMode(QCAR::CameraDevice::MODE_DEFAULT);
LOG("the6");
// Configure the video background
QCAR::VideoBackgroundConfig config;
config.mEnabled = true;
config.mSynchronous = true;
config.mPosition.data[0] = 0.0f;
config.mPosition.data[1] = 0.0f;
LOG("the7");
if (isActivityInPortraitMode)
{
//LOG("configureVideoBackground PORTRAIT");
config.mSize.data[0] = videoMode.mHeight
* (screenHeight / (float)videoMode.mWidth);
config.mSize.data[1] = screenHeight;
}
else
{
//LOG("configureVideoBackground LANDSCAPE");
config.mSize.data[0] = screenWidth;
config.mSize.data[1] = videoMode.mHeight
* (screenWidth / (float)videoMode.mWidth);
}
// Set the config:
LOG("the8");
QCAR::Renderer::getInstance().setVideoBackgroundConfig(config);
LOG("the9");
}
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_initApplicationNative(
JNIEnv* env, jobject obj, jint width, jint height)
{
LOG("Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_initApplicationNative");
// Store screen dimensions
screenWidth = width;
screenHeight = height;
// Handle to the activity class:
/* jclass activityClass = env->GetObjectClass(obj);
jmethodID getTextureCountMethodID = env->GetMethodID(activityClass,
"getTextureCount", "()I");
if (getTextureCountMethodID == 0)
{
LOG("Function getTextureCount() not found.");
return;
}
textureCount = (int) env->CallObjectMethod(obj, getTextureCountMethodID);
if (!textureCount)
{
LOG("getTextureCount() returned zero.");
return;
}
textures = new Texture*[textureCount];
jmethodID getTextureMethodID = env->GetMethodID(activityClass,
"getTexture", "(I)Lcom/qualcomm/QCARSamples/ImageTargets/Texture;");
if (getTextureMethodID == 0)
{
LOG("Function getTexture() not found.");
return;
}
// Register the textures
for (int i = 0; i < textureCount; ++i)
{
jobject textureObject = env->CallObjectMethod(obj, getTextureMethodID, i);
if (textureObject == NULL)
{
LOG("GetTexture() returned zero pointer");
return;
}
textures[i] = Texture::create(env, textureObject);
}*/
LOG("OUT initApplicationNative");
}
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_deinitApplicationNative(
JNIEnv* env, jobject obj)
{
LOG("Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_deinitApplicationNative");
LOG("in deinitApplicationNative");
// Release texture resources
if (textures != 0)
{
for (int i = 0; i < textureCount; ++i)
{
delete textures[i];
textures[i] = NULL;
}
delete[]textures;
textures = NULL;
textureCount = 0;
}
LOG("out deinitApplicationNative");
}
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_startCamera(JNIEnv *,
jobject)
{
LOG("Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_startCamera");
LOG("in startCamera");
// Initialize the camera:
if (!QCAR::CameraDevice::getInstance().init())
return;
// Configure the video background
configureVideoBackground();
// Select the default mode:
if (!QCAR::CameraDevice::getInstance().selectVideoMode(
QCAR::CameraDevice::MODE_DEFAULT))
return;
// Start the camera:
if (!QCAR::CameraDevice::getInstance().start())
return;
// Start the tracker:
QCAR::Tracker::getInstance().start();
// Cache the projection matrix:
const QCAR::Tracker& tracker = QCAR::Tracker::getInstance();
const QCAR::CameraCalibration& cameraCalibration =
tracker.getCameraCalibration();
//projectionMatrix = QCAR::Tool::getProjectionGL(cameraCalibration, 2.0f,
// 2000.0f);
LOG("out startCamera");
sflag=1;
}
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_stopCamera(JNIEnv *,
jobject)
{
LOG("Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_stopCamera");
LOG("in stopCamera");
QCAR::Tracker::getInstance().stop();
QCAR::CameraDevice::getInstance().stop();
QCAR::CameraDevice::getInstance().deinit();
sflag=0;
LOG("out stopCamera");
}
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_initRendering(
JNIEnv* env, jobject obj)
{
LOG("Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_initRendering");
LOG("in initRendering");
// Define clear color
// glClearColor(0.0f, 0.0f, 0.0f, QCAR::requiresAlpha() ? 0.0f : 1.0f);
// Now generate the OpenGL texture objects and add settings
/* for (int i = 0; i < textureCount; ++i)
{
glGenTextures(1, &(textures[i]->mTextureID));
glBindTexture(GL_TEXTURE_2D, textures[i]->mTextureID);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textures[i]->mWidth,
textures[i]->mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
(GLvoid*) textures[i]->mData);
}
#ifndef USE_OPENGL_ES_1_1
shaderProgramID = SampleUtils::createProgramFromBuffer(cubeMeshVertexShader,
cubeFragmentShader);
vertexHandle = glGetAttribLocation(shaderProgramID,
"vertexPosition");
normalHandle = glGetAttribLocation(shaderProgramID,
"vertexNormal");
textureCoordHandle = glGetAttribLocation(shaderProgramID,
"vertexTexCoord");
mvpMatrixHandle = glGetUniformLocation(shaderProgramID,
"modelViewProjectionMatrix");
#endif */
LOG("out initRendering");
}
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_updateRendering(
JNIEnv* env, jobject obj, jint width, jint height)
{
LOG("Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_updateRendering");
LOG("the1");
// Update screen dimensions
screenWidth = width;
screenHeight = height;
LOG("the2");
// Reconfigure the video background
configureVideoBackground();
LOG("the3");
}
#ifdef __cplusplus
}
#endif
This code clears the OpenGL color and depth buffers, at the start of the frame before you do your rendering. In most cases, if you are rendering the video to the background you can probably skip clearing the color buffer. This could cause a problem on devices that use multiple layers for the video instead of rendering it in OpenGL, however. You could try something like this to work across all devices:
The video background is drawn in the Renderer::begin method, when OpenGL is used to draw it (which is the case on most devices, including yours). Since the video covers the whole screen you do not need to clear the color buffer in this case.
Make sure that you have set the glClearColor before glClear is called:
You need to clear the depth buffer if GL_DEPTH_TEST is enabled, which is typically true if you are rendering 3D objects.
- Kim