Log in or register to post comments

New project in eclipse

November 7, 2012 - 4:16am #1

Hello,

I'm experienced some problems building new projects in vuforia. I can build some samples but when I want to start from scratch I have a lot of problems. There are some template for this? Thank you.

New project in eclipse

November 9, 2012 - 4:47am #13

I see that you posted that the problem has disappeared in another post.

New project in eclipse

November 8, 2012 - 9:00am #12

Thank you!

 

But the ndk-build says me:

 

fatal error: QCAR/QCAR.h: No such file or directory

compilation terminated.

New project in eclipse

November 8, 2012 - 5:06am #11

Hi, these are some steps that you can follow to port ImageTargets to a native activity:

  1. Set the Project Build Target to Android 2.3 at a minimum.
  2. In ImageTargets.java, set the class to extend NativeActivity rather than Activity.
  3. Add the native-activity library to the static initializer block: static { loadLibrary(NATIVE_LIB_QCAR); loadLibrary(NATIVE_LIB_SAMPLE); loadLibrary("native-activity"); }
  4. Remove all references to mGlView and mRenderer in ImageTargets.java (these will be handled natively).
  5. Add the following to ImageTargets.java: private native void initRendering(); private native void updateRendering(int width, int height); private native void cacheJNIVars(); private native void setAnimating(int value); // Called from native public void onGLInitialized() { // Call native function to initialize rendering: initRendering(); // Call QCAR function to (re)initialize rendering after first use // or after OpenGL ES context was lost (e.g. after onPause/onResume): QCAR.onSurfaceCreated(); } // SurfaceHolder callback public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { super.surfaceChanged(holder, format, width, height); onSurfaceChanged(width, height); } public void onSurfaceChanged(int width, int height) { // Call native function to update rendering when render surface parameters have changed: updateRendering(width, height); // Call QCAR function to handle render surface size changes: QCAR.onSurfaceChanged(width, height); }
  6. Comment out the call to initApplicationNative(mScreenWidth, mScreenHeight) in the initApplicationAR method. Instead, call it right after the loadTextures() call in the onCreate method: mTextures = new Vector<Texture>(); loadTextures(); initApplicationNative(0, 0);
  7. Add the following to the end of the onCreate method: cacheJNIVars();
  8. Call onSurfaceChanged right after the call to onQCARInitializedNative() in updateApplicationStatus: // Native post initialization: onQCARInitializedNative(); onSurfaceChanged(mScreenWidth, mScreenHeight);
  9. Turn animating on and off when the camera is started or stopped: case APPSTATUS_CAMERA_STOPPED: // Call the native function to stop the camera stopCamera(); setAnimating(0); break; case APPSTATUS_CAMERA_RUNNING: // Call the native function to start the camera startCamera(); setProjectionMatrix(); setAnimating(1); break;
  10. Set android:hasCode="true" in the Android Manifest. Also, add the following meta-data just before the intent filters: <meta-data android:name="android.app.lib_name" android:value="native-activity" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>
  11. Find the native-activity sample in the Android NDK distribution. Copy main.c to the jni folder of the ImageTargets project. Change the filename to main.cpp.
  12. Add the following to the end of the Android.mk file: include $(CLEAR_VARS) LOCAL_MODULE := native-activity LOCAL_SRC_FILES := main.cpp LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2 LOCAL_STATIC_LIBRARIES := android_native_app_glue LOCAL_SHARED_LIBRARIES := QCAR-prebuilt ImageTargets LOCAL_ARM_MODE := arm include $(BUILD_SHARED_LIBRARY) $(call import-module,android/native_app_glue)
  13. In main.cpp, move the engine declaration from the android_main method to global space: struct engine engine;
  14. Add the following code to main.cpp: #ifdef __cplusplus extern "C" { #endif JavaVM* javaVM = NULL; jclass activityClass; jobject activityObj; extern void renderFrame(); JNIEXPORT void JNICALL Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_cacheJNIVars(JNIEnv *env, jobject jobj) { env->GetJavaVM(&javaVM); jclass cls = env->GetObjectClass(jobj); activityClass = (jclass) env->NewGlobalRef(cls); activityObj = env->NewGlobalRef(jobj); } JNIEXPORT int JNICALL Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_setAnimating(JNIEnv *, jobject, jint animating) { engine.animating = animating; } void onGLInitialized() { if (javaVM == NULL) { LOGI("Error: javaVM is NULL"); return; } JNIEnv *env; javaVM->AttachCurrentThread(&env, NULL); jmethodID method = env->GetMethodID(activityClass, "onGLInitialized", "()V"); if (method == NULL) { LOGI("Error: could not find onGLInitialized method"); return; } env->CallVoidMethod(activityObj, method); } #ifdef __cplusplus } #endif
  15. Replace the engine_init_display method with the following: static int engine_init_display(struct engine* engine) { // initialize OpenGL ES and EGL const EGLint attribs[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RED_SIZE, 5, EGL_GREEN_SIZE, 6, EGL_BLUE_SIZE, 5, //EGL_ALPHA_SIZE, 8, // assuming we don't need this EGL_DEPTH_SIZE, 16, EGL_STENCIL_SIZE, 0, EGL_NONE }; EGLint w, h, dummy, format; EGLint numConfigs; EGLConfig config; EGLSurface surface; EGLContext context; EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(display, 0, 0); /* Here, the application chooses the configuration it desires. In this * sample, we have a very simplified selection process, where we pick * the first EGLConfig that matches our criteria */ eglChooseConfig(display, attribs, &config, 1, &numConfigs); /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). * As soon as we picked a EGLConfig, we can safely reconfigure the * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format); surface = eglCreateWindowSurface(display, config, engine->app->window, NULL); const EGLint attrib_list_gl20[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; context = eglCreateContext(display, config, EGL_NO_CONTEXT, attrib_list_gl20); if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) { LOGW("Unable to eglMakeCurrent"); return -1; } eglQuerySurface(display, surface, EGL_WIDTH, &w); eglQuerySurface(display, surface, EGL_HEIGHT, &h); engine->display = display; engine->context = context; engine->surface = surface; engine->width = w; engine->height = h; engine->state.angle = 0; // Initialize GL state. //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glEnable(GL_CULL_FACE); //glShadeModel(GL_SMOOTH); glDisable(GL_DEPTH_TEST); onGLInitialized(); return 0; }
  16. Replace the engine_draw_frame method with the following: static void engine_draw_frame(struct engine* engine) { if (engine->display == NULL) { // No display. return; } // Call the ImageTargets.cpp renderFrame method renderFrame(); eglSwapBuffers(engine->display, engine->surface); }
  17. Comment out the following line in engine_handle_input: engine->animating = 1;
  18. In ImageTargets.cpp, change the method signatures of the following methods JNIEXPORT void JNICALL Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv *, jobject) // change to void renderFrame() JNIEXPORT void JNICALL Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_initRendering( JNIEnv* env, jobject obj) // change to JNIEXPORT void JNICALL Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_initRendering( JNIEnv* env, jobject obj) JNIEXPORT void JNICALL Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_updateRendering( JNIEnv* env, jobject obj, jint width, jint height) // change to JNIEXPORT void JNICALL Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_updateRendering( JNIEnv* env, jobject obj, jint width, jint height)
Unlike our typical samples, when using a NativeActivity the GL context is created well before the tracker is initialized. This is why some of the initialization methods need to be shuffled around.
This code does not handle the screen being turned off and on while the app is running (the camera will not resume). This requires some lifecycle investigation.

New project in eclipse

November 8, 2012 - 2:22am #10

It's very difficoult to me to use gameplay outside nativeactivity. I think I need to pass ImageTarget to NativeActivity, can you help me? Thanks.

New project in eclipse

November 7, 2012 - 9:25am #9

Ok. I'm trying the other thing.

New project in eclipse

November 7, 2012 - 9:18am #8

Yes, it is possible to go completely native, though not straigthforward; if at some point you will really need it, let me know.

 

New project in eclipse

November 7, 2012 - 9:06am #7

Thanks! It's going to be complicated.

Anyway, is possible to pass all imagetarget code to NativeActivity? Maybe I need someday.

New project in eclipse

November 7, 2012 - 7:43am #6

OK, good!

 Don't hesitate to share your issues here if you need some help while trying that process.

New project in eclipse

November 7, 2012 - 7:39am #5

Thanks, I think that your idea is better than mine... I'm going to try!

New project in eclipse

November 7, 2012 - 5:08am #4

I don;t know how exactly gameplay3d works, but I'm wondering if it is really necessary to go for a native activity (as that approach is possible but a bit complicated to setup and maybe not gaining much);

in general it should be possible to plug the gameplay3d functionalities into the native part of the samples; for instance, you could plug your gameplay3d-based rendering method inside the renderFrame method, by replacing the existing OpenGL calls;

so, I would suggest you try and investigate if that's possible; on the Java side, on the other hand, you can keep the Java code to a minimum, and do everything else in C++ anyway.

 

New project in eclipse

November 7, 2012 - 4:53am #3

Thank you!

And another question... I want to do all the staff of ImageTarget in NativeActivity, is there any example or advice? My goal is integrated vuforia with gameplay3d if it is possible and gameplay3d is all in c++.

Thanks another time!

New project in eclipse

November 7, 2012 - 4:32am #2

The best "templates" available are the samples themselves; in most cases, starting by copying the ImageTargets sample is a good way of doing that;

in Eclipse, after opening the ImageTargets sample, you can simply copy-paste it in the "Package Explorer"; this will make Eclipse to create a copy of your project, to which you can give a different name (such as "MyFirstVuforiaApp");

Then you must take care of the following:

The package name (such as "com.mycompany.myprojects") and the class names must be "aligned" with the function names in the JNI code, 

as explained also in this forum thread:

https://ar.qualcomm.at/content/could-not-find-method-androidhardwarecameragetnumberofcameras

 

I hope this helps.

Log in or register to post comments