Game Development Reference
In-Depth Information
Naming Native Functions
The native function declared in the Java code must match the function name declared in the native
C/C++ code based on certain formatting, as follows:
1.
The function starts with “Java.”
It is followed by the package name “ robs_gldemo_robsgl20tutorial ” from
the example in Listing 11-1.
2.
This is followed by the class name “ GLES20TriangleRenderer ” from the
example in Listing 11-1.
3.
Next comes the function name “ RobsstringFromJNI ” from the example in
Listing 11-1.
4.
See the full function name in Listing 11-2.
Listing 11-2. The Native RobsstringFromJNI() Function
jstring
Java_robs_gldemo_robsgl20tutorial_GLES20TriangleRenderer_RobsstringFromJNI (JNIEnv* env, jobject thiz
)
{
return (*env)->NewStringUTF(env, "Rob's String Text Message!");
}
Native Function Parameters
The parameter list for a native function always starts with a pointer to JNIEnv, which is the Java
Interface Pointer, for example, env in our native function from Listing 11-2.
JNIEnv* env
The second parameter is a reference to the object, if the native function is nonstatic, for example,
thiz in our native function example from Listing 11-2.
jobject thiz
However, if the native function is static, the second parameter is a reference to its Java class.
 
Search WWH ::




Custom Search