Ignore:
Timestamp:
Mar 1, 2011, 7:02:18 PM (12 years ago)
Author:
sam
Message:

android: move the PNG loading test into the Image class. It now works.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/androidapp.cpp

    r712 r714  
    2424#include "interface.h"
    2525
     26namespace lol
     27{
     28jobject g_ctx;
     29JNIEnv *g_env;
     30};
     31
     32extern "C" void
     33Java_org_zoy_LolEngine_LolActivity_nativeInit(JNIEnv* env, jobject thiz)
     34{
     35    env->NewGlobalRef(thiz); /* FIXME: never released! */
     36    g_ctx = thiz;
     37}
     38
    2639extern "C" void
    2740Java_org_zoy_LolEngine_LolRenderer_nativeInit(JNIEnv* env)
    2841{
     42    g_env = env;
     43
    2944    __android_log_print(ANDROID_LOG_INFO, "LOL", "init");
    30     Ticker::Setup(10.0f);
     45    Ticker::Setup(30.0f);
    3146    Video::Setup(320, 200);
    3247
    3348    new Interface();
    3449    new DebugFps(20, 20);
    35 }
    36 
    37 static void TestPng(JNIEnv *env)
    38 {
    39     jclass cls = env->FindClass("org/zoy/LolEngine/LolActivity");
    40     jmethodID mid;
    41 
    42     /* Open image from resources */
    43     mid = env->GetStaticMethodID(cls, "openImage", "(Ljava/lang/String;)V");
    44     jstring name = env->NewStringUTF("ascii");
    45     env->CallStaticVoidMethod(cls, mid, name);
    46     env->DeleteLocalRef(name);
    47 
    48     /* Get image dimensions */
    49     mid = env->GetStaticMethodID(cls, "getWidth", "()I");
    50     jint w = env->CallStaticIntMethod(cls, mid);
    51     mid = env->GetStaticMethodID(cls, "getHeight", "()I");
    52     jint h = env->CallStaticIntMethod(cls, mid);
    53     __android_log_print(ANDROID_LOG_INFO, "LOL", "Loaded PNG %dx%d", w, h);
    54 
    55     /* Get pixels */
    56     jintArray arr = env->NewIntArray(w * h * 4);
    57     mid = env->GetStaticMethodID(cls, "getPixels", "([I)V");
    58     env->CallStaticVoidMethod(cls, mid, arr);
    59 
    60     /* Do something with the pixels */
    61     jint *data = env->GetIntArrayElements(arr, 0);
    62     __android_log_print(ANDROID_LOG_INFO, "LOL", "pixels %08x %08x %08x %08x",
    63                         (unsigned)data[0], (unsigned)data[1],
    64                         (unsigned)data[2], (unsigned)data[3]);
    65     env->ReleaseIntArrayElements(arr, data, 0);
    66     env->DeleteLocalRef(arr);
    67 
    68     /* Free image */
    69     mid = env->GetStaticMethodID(cls, "closeImage", "()V");
    70     env->CallStaticVoidMethod(cls, mid);
    7150}
    7251
     
    7756    __android_log_print(ANDROID_LOG_INFO, "LOL", "resize w=%d h=%d", w, h);
    7857    Video::Setup(w, h);
    79 
    80     TestPng(env);
    8158}
    8259
Note: See TracChangeset for help on using the changeset viewer.