Nanashi-soft○プログラマ専用○AndroidでOpenGL ES 2.0プログラミング○
package jp.testndk;基本的に,Javaだけで組むのと同じです
import android.app.Activity;
import android.os.Bundle;
import android.opengl.*;
import javax.microedition.khronos.egl.*;
import javax.microedition.khronos.opengles.*;
public class testndk extends Activity {
GLSurfaceView glview;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
glview = new GLSurfaceView(this);
glview.setEGLContextClientVersion(2);
glview.setRenderer(new testRenderer());
setContentView(glview);
}
}
class testRenderer implements GLSurfaceView.Renderer{
static {
System.loadLibrary("hello-jni");
}
public native void NDKonSurfaceCreated();
public native void NDKonSurfaceChanged(int w,int h);
public native void NDKonDrawFrame();
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
NDKonSurfaceCreated();
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
NDKonSurfaceChanged(w, h);
}
public void onDrawFrame(GL10 gl) {
NDKonDrawFrame();
}
}
#include <jni.h>この関数名は,規則があって,こう書かなければなりません
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
void Java_jp_testndk_testRenderer_NDKonSurfaceCreated(JNIEnv* env)
{
}
void Java_jp_testndk_testRenderer_NDKonSurfaceChanged(JNIEnv* env, jobject obj, jint w, jint h)
{
}
void Java_jp_testndk_testRenderer_NDKonDrawFrame(JNIEnv* env)
{
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
LOCAL_PATH := $(call my-dir)そして,Cygwinコマンドラインからビルドする
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
LOCAL_LDLIBS := -lGLESv2
include $(BUILD_SHARED_LIBRARY)
$ cd /cygdrive/c/「パス名」そうすると,libs/armeabi/libhello-jni.soが生成されます
$ ndk-build
Install : libhello-jni.so => libs/armeabi/libhello-jni.so