Game Development Reference
In-Depth Information
Listing 5-15. Graphics Initialization
/**
* Fires when Doom graphics are initialized.
* params: img width, height
*/
void jni_init_graphics(int width, int height)
{
JNIEnv *env;
if ( !g_VM) {
printf("No JNI VM available.\n");
return;
}
(*g_VM)->AttachCurrentThread (g_VM, (void **) &env, NULL);
iSize = width * height;
// Create a new int[] used by jni_send_pixels
jImage = (*env)-> NewIntArray(env, iSize);
// Call doom.util.Natives.OnInitGraphics(w, h);
jmethodID mid = (*env)->GetStaticMethodID(env, jNativesCls
, CB_CLASS_IG_CB
, CB_CLASS_IG_SIG);
if (mid) {
(*env)->CallStaticVoidMethod(env, jNativesCls
, mid
, width, height);
}
}
Video Buffer Callback
The video buffer callback is critical, and it must be lean and mean. It gets called continuously
and must not create any objects (see Listing 5-16). Like the previous callback, it attaches to the
current thread. It also calls the static void method doom.jni.Natives.OnImageUpdate(int[] pixels) .
But before calling this method, it must set the pixels into the Java array ( jImage ):
(*env)->SetIntArrayRegion(env, jImage, 0, iSize, (jint *) data)
data is an array of integers already formatted as 32-bit ARGB pixels, as required by Android,
and iSize is the size of the display calculated in the previous callback.
 
Search WWH ::




Custom Search