2011-02-09 60 views
0

我想从NDK渲染一个openGL es表面,但在工作早期就停止了。我有一个类似于NDK中3d例子的设置。我有一个继承自GLSurface视图的类和一个继承自GLSurfaceView.Renderer的类。在我的.c文件中,我有一个简单的方法,没有任何问题。这只是一个没有任何内容的无效函数。我可以在继承自activity的onCreate方法的类中调用此函数。
private static native void nativeSetup();在GLSurfaceView类中的NDK调用

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    mGLView = new GraphGLSurfaceView(this); 
    setContentView(mGLView); 
    nativeSetup(); 
} 

该程序工作正常。但是,如果我将调用(和声明)放在其中一个GLSurfaceView类中,程序立即失败(nativeSetup是有问题的调用)。我已经证实,没有本地调用(绘制彩色表面),一切正常。有没有人有任何想法,为什么我不能从GLSurface类调用本地代码?

我的C文件:

#include <string.h> 
#include <jni.h> 

void Java_com_test_intro_nativeSetup(JNIEnv* env){} 

在非工作方式我的Java文件:?

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); 
    } 
} 

回答

2

在C文件并重新命名您的本地函数也许问题是与此相关的问题,导致JNI为导航功能使用特定的命名。

看看here并尝试使用javah -jni $CLASS-FILE-WITH-NATIVE-METHODS$来获取c文件。

希望这有助于。

ciao

+0

我忘了重命名该函数去与它所在的类。谢谢。 – Hohohodown 2011-02-09 14:14:11