opengl es-未能在android上执行此c++代码
opengl es - failed to execute this c++ code on android
我正在尝试从java调用本机opengl方法。一切都可以编译,但我仍然在android日志猫中得到这个可怕的错误
ERROR/AndroidRuntime(536): java.lang.UnsatisfiedLinkError:init
at com.deo.Glut.Init(Native Method)
根据oracle
如果Java虚拟机找不到适当的母语定义声明为本机的方法
我不明白为什么模拟器找不到我的本机方法。//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)
{}
我首先声明,然后尝试从java调用上面的方法,这导致了错误。
package com.deo;
public class Glut//java class that declares my native methods(srccomdeoGlut.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 :(
}
然后尝试从我的自定义渲染器调用它们
public Glut myglut;
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{ myglut= new Glut();
myglut.init();
}
请帮忙下载项目文件的链接
因为您的文件是一个cpp文件,所以您需要围绕导出的函数使用extern "C" { }
。否则,编译器将破坏函数名,Java将找不到它要查找的函数名。
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- C++,系统无法执行指定的程序
- 使用C++中的模板和运算符重载执行矩阵运算
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 执行函数时导致崩溃的变量
- 无论条件是否为true,if总是在c++中执行
- 当函数模板参数是具有默认参数的类模板时,函数模板参数的推导如何执行
- 在C++中对T*类型执行std::move的意外行为
- 使用QProcess执行命令,并将结果存储在QStringList中
- 如何在没有信号的情况下从C++执行QML插槽
- 如何确认我的constexpr表达式实际上已经在编译时执行
- C++17中的并行执行策略
- QML按钮点击功能执行顺序
- 程序在执行程序的其余部分之前退出
- 为什么catch中的代码没有被执行
- C++从其他 constexpr 创建 lambda 不能按顺序执行 Constexpr
- 将执行、作业和WinAPI相乘
- 对字符数组中的元素执行逐位操作
- 为什么g++在未执行的代码处标记强制转换错误
- 如何使用原子指针执行双缓冲