Parcourir la source

android: Add a method for PNG loading. Highly hackish for now.

legacy
Sam Hocevar sam il y a 13 ans
Parent
révision
aec4ae3ccc
1 fichiers modifiés avec 38 ajouts et 0 suppressions
  1. +38
    -0
      src/androidapp.cpp

+ 38
- 0
src/androidapp.cpp Voir le fichier

@@ -34,12 +34,50 @@ Java_org_zoy_LolEngine_LolRenderer_nativeInit(JNIEnv* env)
new DebugFps(20, 20);
}

static void TestPng(JNIEnv *env)
{
jclass cls = env->FindClass("org/zoy/LolEngine/LolActivity");
jmethodID mid;

/* Open image from resources */
mid = env->GetStaticMethodID(cls, "openImage", "(Ljava/lang/String;)V");
jstring name = env->NewStringUTF("ascii");
env->CallStaticVoidMethod(cls, mid, name);
env->DeleteLocalRef(name);

/* Get image dimensions */
mid = env->GetStaticMethodID(cls, "getWidth", "()I");
jint w = env->CallStaticIntMethod(cls, mid);
mid = env->GetStaticMethodID(cls, "getHeight", "()I");
jint h = env->CallStaticIntMethod(cls, mid);
__android_log_print(ANDROID_LOG_INFO, "LOL", "Loaded PNG %dx%d", w, h);

/* Get pixels */
jintArray arr = env->NewIntArray(w * h * 4);
mid = env->GetStaticMethodID(cls, "getPixels", "([I)V");
env->CallStaticVoidMethod(cls, mid, arr);

/* Do something with the pixels */
jint *data = env->GetIntArrayElements(arr, 0);
__android_log_print(ANDROID_LOG_INFO, "LOL", "pixels %08x %08x %08x %08x",
(unsigned)data[0], (unsigned)data[1],
(unsigned)data[2], (unsigned)data[3]);
env->ReleaseIntArrayElements(arr, data, 0);
env->DeleteLocalRef(arr);

/* Free image */
mid = env->GetStaticMethodID(cls, "closeImage", "()V");
env->CallStaticVoidMethod(cls, mid);
}

extern "C" void
Java_org_zoy_LolEngine_LolRenderer_nativeResize(JNIEnv* env, jobject thiz,
jint w, jint h)
{
__android_log_print(ANDROID_LOG_INFO, "LOL", "resize w=%d h=%d", w, h);
Video::Setup(w, h);

TestPng(env);
}

extern "C" void


Chargement…
Annuler
Enregistrer