当前位置: 动力学知识库 > 问答 > 编程问答 >

opengl es - Retrofitting opengles 1.0 to 2.0 in Android NDK

问题描述:

I'm currently working on converting Android's San-Angeles example to OpenGL ES 2.0, instead of it's current 1.0 (using my own version of Demo). I am currently getting this error, and I just can't figure out where I'm going wrong.

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.

Here is my DemoActivity (Which I assume the issue is in):

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

}

网友答案:

You can peek at the source code for GlSurfaceView here (it'll also be somewhere in the sdk installed on your machine) documentation can be found here.

The relevant bit of info is that after you call SetRenderer once, you are not allowed to call the following afterwards:

  • SetRenderer (a second time)
  • setEGLContextFactory
  • setEGLWindowSurfaceFactory
  • setEGLConfigChooser
  • setEGLContextClientVersion

The code you've posted doesn't show that's what you've done, but I think you're probably calling one of these functions in code you haven't posted. The setEGL* functions need to be called before SetRenderer in order to work.

分享给朋友:
您可能感兴趣的文章:
随机阅读: