我目前正致力于将Android的San-Angeles示例转换为OpenGL ES 2.0,而不是当前的1.0(使用我自己的Demo版本)。我目前正在收到此错误,我无法弄清楚我哪里出错了。
06-24 11:02:48.246 2528-2528/com.example.SanAngeles E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.SanAngeles, PID: 2528
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.SanAngeles/com.example.SanAngeles.DemoActivity}: java.lang.IllegalStateException: setRenderer has already been called for this instance.
这是我的DemoActivity(我假设问题在于): package com.example.SanAngeles;
import android.app.Activity;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.MotionEvent;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
public class DemoActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGLView = new DemoGLSurfaceView(this);
setContentView(mGLView);
}
private GLSurfaceView mGLView;
static {
System.loadLibrary("sanangeles");
}
}
class DemoGLSurfaceView extends GLSurfaceView {
public DemoGLSurfaceView(Context context) {
super(context);
setEGLContextClientVersion(2);
mRenderer = new DemoRenderer();
setRenderer(mRenderer);
}
public boolean onTouchEvent(final MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
nativeTogglePauseResume();
}
return true;
}
DemoRenderer mRenderer;
private static native void nativeTogglePauseResume();
}
class DemoRenderer implements GLSurfaceView.Renderer {
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
nativeInit();
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
//gl.glViewport(0, 0, w, h);
nativeResize(w, h);
}
public void onDrawFrame(GL10 gl) {
nativeRender();
}
private static native void nativeInit();
private static native void nativeResize(int w, int h);
private static native void nativeRender();
private static native void nativeDone();
}
答案 0 :(得分:1)