Android GLSurfaceView类中的NDK调用
我正试图从NDK渲染openGL es曲面,但在我的工作早期就被停止了。我的设置与NDK中的3d示例类似。我有一个继承自GLSurface view的类和一个继承自GLSurfaceView.Renderer的类。在我的.c文件中,我有一个简单的方法,它什么也不做。它只是一个空函数,里面什么都没有。我可以在继承自activity onCreate方法的类中调用此函数。Android GLSurfaceView类中的NDK调用,android,opengl-es,android-ndk,glsurfaceview,Android,Opengl Es,Android Ndk,Glsurfaceview,我正试图从NDK渲染openGL es曲面,但在我的工作早期就被停止了。我的设置与NDK中的3d示例类似。我有一个继承自GLSurface view的类和一个继承自GLSurfaceView.Renderer的类。在我的.c文件中,我有一个简单的方法,它什么也不做。它只是一个空函数,里面什么都没有。我可以在继承自activity onCreate方法的类中调用此函数。 私有静态本机void nativeSetup() 程序运行良好。但是,如果我将调用(和声明)放入其中一个GLSURFACHEVI
私有静态本机void nativeSetup() 程序运行良好。但是,如果我将调用(和声明)放入其中一个GLSURFACHEVIEW类中,程序将立即失败(nativeSetup是有问题的调用)。我已经验证了在没有本机调用的情况下,一切都正常工作(绘制了彩色表面)。有人知道为什么我不能从GLSurface类调用本机代码吗 我的c文件:
#include <string.h>
#include <jni.h>
void Java_com_test_intro_nativeSetup( JNIEnv* env ){}
在c文件中是否重命名了本机函数?可能问题与此问题有关,因为JNI对navtive函数使用了特定的命名 查看并尝试使用
javah-jni$CLASS-FILE-WITH-NATIVE-METHODS$
获取c文件
希望这有帮助
ciao我忘了重命名该函数以与它所在的类匹配。非常感谢。
#include <string.h>
#include <jni.h>
void Java_com_test_intro_nativeSetup( JNIEnv* env ){}
package com.test;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.app.Activity;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
public class intro extends Activity {
static{
System.loadLibrary("graphrender");
}
private GLSurfaceView mGLView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mGLView = new GraphGLSurfaceView(this);
setContentView(mGLView);
}
}
class GraphGLSurfaceView extends GLSurfaceView {
GraphRenderer mRenderer;
public GraphGLSurfaceView(Context context) {
super(context);
mRenderer = new GraphRenderer();
setRenderer(mRenderer);
}
}
class GraphRenderer implements GLSurfaceView.Renderer {
private static native void nativeSetup();
private float _red = 0.9f;
private float _green = 0.2f;
private float _blue = 0.2f;
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
Log.d("intro", "Got to intro 4" );
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
gl.glViewport(0, 0, w, h);
nativeSetup();
//Log.d("intro", "Got to intro 2" + debugStr);
}
public void onDrawFrame(GL10 gl) {
Log.d("intro", "Got to intro 3");
gl.glClearColor(_red, _green, _blue, 1.0f);
// clear the color buffer to show the ClearColor we called above...
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
}
}