Dr *_*Deo 2 c++ java-native-interface opengl-es android-ndk
我试图从java调用本机opengl方法.一切都编译好,但我仍然在android log cat中得到这个可怕的错误
ERROR/AndroidRuntime(536): java.lang.UnsatisfiedLinkError:init
at com.deo.Glut.Init(Native Method)
Run Code Online (Sandbox Code Playgroud)
据甲骨文说
如果Java虚拟机无法找到声明为native的方法的相应本机语言定义,则抛出UnsatisfiedLinkError
我无法弄清楚为什么模拟器无法找到我的原生方法.// glut.cpp中的本机方法(jni/glut.cpp)
#include<jni.h>//compiled using cgwin and ndk-build on windows xp
#include<gles/gl.h>
#include<math.h>
static void gluPerspective(GLfloat fovy, GLfloat aspect,
GLfloat zNear, GLfloat zFar)//android ndk lacks glu tool kit (unbelievable)
{
#define PI 3.1415926535897932f
GLfloat xmin, xmax, ymin, ymax;
ymax = zNear * (GLfloat)tan(fovy * PI / 360);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustumx((GLfixed)(xmin * 65536), (GLfixed)(xmax * 65536),
(GLfixed)(ymin * 65536), (GLfixed)(ymax * 65536),
(GLfixed)(zNear * 65536), (GLfixed)(zFar * 65536));
#undef PI
}
JNIEXPORT void JNICALL Java_com_deo_Glut_display
(JNIEnv *, jobject)
{
glClearColor(1,1,0,1);
glClear(GL_COLOR_BUFFER_BIT);
}
JNIEXPORT void JNICALL Java_com_deo_Glut_reshape
(JNIEnv *, jobject, jint width, jint height)
{
glViewport(0,0,width,height);
if(height==0)height=1;//prevent a divide by zero error in case it ever tries to occur
glMatrixMode(GL_PROJECTION);
gluPerspective(50,width/height,1,1000);
glMatrixMode(GL_MODELVIEW);
}
JNIEXPORT void JNICALL Java_com_deo_Glut_init
(JNIEnv *, jobject)
{}
Run Code Online (Sandbox Code Playgroud)
我首先声明然后尝试从java调用上面的方法导致错误.
package com.deo;
public class Glut//java class that declares my native methods(src\com\deo\Glut.java)
{
static
{
System.loadLibrary("glut");
}
public native void display();
public native void reshape(int width, int height);
public native void init();//this is somehow generating an error :(
}
Run Code Online (Sandbox Code Playgroud)
然后尝试从我的自定义渲染器中调用它们
public Glut myglut;
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{ myglut= new Glut();
myglut.init();
}
Run Code Online (Sandbox Code Playgroud)
请帮助 下载项目文件的链接