【发布时间】:2011-02-09 05:47:11
【问题描述】:
我正在尝试从 NDK 渲染一个 openGL es 表面,但在我的工作早期就停止了。我有一个类似于 NDK 中的 3d 示例的设置。我有一个从 GLSurface 视图继承的类和一个从 GLSurfaceView.Renderer 继承的类。在我的 .c 文件中,我有一个什么都不做的简单方法。它只是一个 void 函数,其中没有任何内容。我可以在继承自活动 onCreate 方法的类中调用此函数。
私有静态本机无效本机设置();
@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);
}
}
【问题讨论】:
标签: android opengl-es android-ndk glsurfaceview