0

我在这里要做的是在我单击主要活动中的列表视图项目时加载 OpenGL 上下文。

看起来很简单!但我真的不知道如何将主要活动与 OpenGL 活动联系起来。任何人都可以给我一些提示吗?

谢谢!!

编辑:在这里添加一些代码:

在主要活动中:

listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            Intent launchGL = new Intent(getApplicationContext(), OpenGLActivity.class);  
            startActivity(launchGL);

            }
        });

在 OpenGL 活动中:

public class OpenGLActivity extends Activity {

private GLSurfaceView mGLSurfaceView;

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

    mGLSurfaceView = new GLSurfaceView(this);

    // Check if the system supports OpenGL ES 2.0.
    final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
    final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;

    if (supportsEs2)
    {
        // Request an OpenGL ES 2.0 compatible context.
        mGLSurfaceView.setEGLContextClientVersion(2);

        // Set the renderer to our demo renderer, defined below.
        mGLSurfaceView.setRenderer(new MyRenderer());
    }
    else
    {
        // This is where you could create an OpenGL ES 1.x compatible
        // renderer if you wanted to support both ES 1 and ES 2.
        return;
    }

    setContentView(mGLSurfaceView);
}

}

(使用一些教程代码进行实验)

错误信息:

07-19 19:59:06.945: E/AndroidRuntime(1451): FATAL EXCEPTION: GLThread 108
07-19 19:59:06.945: E/AndroidRuntime(1451): java.lang.IllegalArgumentException: No configs match configSpec
07-19 19:59:06.945: E/AndroidRuntime(1451):     at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:863)
07-19 19:59:06.945: E/AndroidRuntime(1451):     at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1024)
07-19 19:59:06.945: E/AndroidRuntime(1451):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1401)
07-19 19:59:06.945: E/AndroidRuntime(1451):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

以及“不幸停止”的应用程序

4

1 回答 1

0

如果您在模拟器上运行代码,请尝试启用“使用主机 gpu”。或者,如果可以,请在真实设备上试用。模拟器对于 openGl 的东西来说是个坏主意,因为它比真实设备慢得多。

于 2013-07-19T20:26:36.763 回答