A simple opengl example of Android using cle
Using common language extension(cle) as interface middleware, you need not care about JNI. The programming may be simple. This example is copied from ndk example hello-gl2 with a small change to use cle.
The C code is as follows:
++ #include "vsopenapi.h"
…
-- bool setupGraphics(int w, int h) {
++ bool setupGraphics(void *object,int w, int h) {
…
}
-- void renderFrame() {
++ void renderFrame(void *object) {
…
}
-- extern "C" {
-- JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_init
(JNIEnv * env, jobject obj, jint width, jint height);
-- JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_step
(JNIEnv * env, jobject obj);
--};
-- JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_init
(JNIEnv * env, jobject obj, jint width, jint height)
-- {
-- setupGraphics(width, height);
-- }
-- JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_step(JNIEnv * env, jobject obj)
-- {
-- renderFrame();
-- }
++ VS_BOOL StarCoreService_Init(class ClassOfStarCore *starcore)
++ {
++ void *AtomicClass,*step_AtomicFunction,*init_AtomicFunction;
++ class ClassOfBasicSRPInterface *BasicSRPInterface;
++ class ClassOfSRPInterface *SRPInterface;
++
++ //--init star core
++ BasicSRPInterface = starcore ->GetBasicInterface();
++ SRPInterface = BasicSRPInterface ->GetSRPInterface
(BasicSRPInterface->QueryActiveService(NULL),"","");
++
++ //---Create Atomic Class, for define function, no attribute
++ AtomicClass = SRPInterface ->CreateAtomicObjectSimple
("TestItem","GLTestClass",NULL,NULL,NULL);
++ step_AtomicFunction = SRPInterface ->CreateAtomicFunctionSimple
(AtomicClass,"step","void step();",NULL,NULL,VS_FALSE,VS_FALSE);
++ init_AtomicFunction = SRPInterface ->CreateAtomicFunctionSimple
(AtomicClass,"init","VS_BOOL init(VS_INT32 width,VS_INT32 height);",
NULL,NULL,VS_FALSE,VS_FALSE);
++ //---Set Function Address
++ SRPInterface -> SetAtomicFunction(init_AtomicFunction,(void *)setupGraphics);
++ SRPInterface -> SetAtomicFunction(step_AtomicFunction,(void *)renderFrame);
++ SRPInterface -> Release();
++ return VS_TRUE;
++ }
++ void StarCoreService_Term(class ClassOfStarCore *starcore)
++ {
++ return;
++ }
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Here we give our module name and sourcefile(s)
LOCAL_CFLAGS += -Wno-write-strings -DENV_ANDROID
LOCAL_CPPFLAGS += -Wno-write-strings -fexceptions -DENV_ANDROID
LOCAL_LDFLAGS += -Wno-write-strings -DENV_ANDROID
LOCAL_C_INCLUDES += ../../../../../android/workspace/include
#--------source file
MODULE_CXXSRCS := gl_code.cpp
LOCAL_SRC_FILES := ${MODULE_CXXSRCS}
LOCAL_LDLIBS := ../../../../../android/workspace/libs/armeabi/libstarlib.a -llog -lGLESv2
LOCAL_MODULE := gltest
include $(BUILD_SHARED_LIBRARY)
java code:
…
++ import com.srplab.www.starcore.*;
…
class GL2JNIView extends GLSurfaceView {
…
++ StarCoreFactory starcore;
++ static StarObjectClass GlObject;
…
private void init(boolean translucent, int depth, int stencil) {
…
++ StarCoreFactory starcore= StarCoreFactory.GetFactory();
++ StarServiceClass Service=starcore._InitSimple("test","123",0,0,"");
++ Service._CheckPassword(false);
++ Service._DoFile("","/data/data/com.srplabgl.gltest/lib/libgltest.so","");
++ GlObject = Service._GetObject("GLTestClass")._New();
…
}
…
private static class Renderer implements GLSurfaceView.Renderer {
public void onDrawFrame(GL10 gl) {
++ GlObject._Call("step");
}
public void onSurfaceChanged(GL10 gl, int width, int height) {
++ GlObject._Call("init",width,height);
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// Do nothing.
}
}
The example code can be downloaded from here.
In more complicated cases, using JNI method will be much more difficult because programmers have to manage references, callbacks, parameter translations. cle provides a powerful and flexible method for Java call other languages such as C/C++.
The following picture is a wrap library for Android of anti-grain geomet, which will be released soon after.

Please visit http://code.google.com/p/cle-for-android to get more information about cle.
Post Comment
PU38Ei Really enjoyed this article post.Really thank you! Want more.
4sfkLv It as not that I want to duplicate your web site, but I really like the design. Could you tell me which style are you using? Or was it especially designed?
7UVumG Piece of writing writing is also a fun, if you be familiar with after that you can write if not it is complicated to write.
gO7Y0f Hey, thanks for the blog article.Much thanks again. Cool.
wQVrCf I think this is a real great post. Really Cool.
ScCYTf Great blog article.Thanks Again. Fantastic.
Excellent post. I lived with Borderline Personality for 25 years bofree the phrase gained prominence and info on BPD became available. Many shrinks say it isn't a real diagnosis, but I know otherwise. It nearly killed me.