source: trunk/src/androidapp.cpp @ 712

Last change on this file since 712 was 712, checked in by sam, 12 years ago

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

  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <jni.h>
16#include <android/log.h>
17
18#include "core.h"
19#include "lolgl.h"
20#include "loldebug.h"
21
22using namespace lol;
23
24#include "interface.h"
25
26extern "C" void
27Java_org_zoy_LolEngine_LolRenderer_nativeInit(JNIEnv* env)
28{
29    __android_log_print(ANDROID_LOG_INFO, "LOL", "init");
30    Ticker::Setup(10.0f);
31    Video::Setup(320, 200);
32
33    new Interface();
34    new DebugFps(20, 20);
35}
36
37static 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);
71}
72
73extern "C" void
74Java_org_zoy_LolEngine_LolRenderer_nativeResize(JNIEnv* env, jobject thiz,
75                                                jint w, jint h)
76{
77    __android_log_print(ANDROID_LOG_INFO, "LOL", "resize w=%d h=%d", w, h);
78    Video::Setup(w, h);
79
80    TestPng(env);
81}
82
83extern "C" void
84Java_org_zoy_LolEngine_LolRenderer_nativeDone(JNIEnv* env)
85{
86    /* FIXME: clean up */
87}
88
89extern "C" void
90Java_org_zoy_LolEngine_LolGLSurfaceView_nativePause(JNIEnv* env)
91{
92    /* TODO: unimplemented */
93}
94
95/* Call to render the next GL frame */
96extern "C" void
97Java_org_zoy_LolEngine_LolRenderer_nativeRender(JNIEnv* env)
98{
99    Ticker::ClampFps();
100    Ticker::TickGame();
101    Ticker::TickDraw();
102}
103
Note: See TracBrowser for help on using the repository browser.