【发布时间】:2013-07-19 18:37:05
【问题描述】:
我在这里要做的是在我单击主活动中的列表视图项目时加载 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);
}
});
在OpenGLActivity中:
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)
而应用程序“不幸停止了”
【问题讨论】:
-
像普通视图一样创建GLSurfaceView并设置渲染器。
-
@MarcinGawel 是的,但我真的不知道我在这里做错了什么,添加了代码片段
-
有什么错误或发生了什么?
-
@MarcinGawel 通过调试器似乎一直到 new MyRender() 并停止,然后“不幸的是应用程序已停止”
-
请显示 StackTrace
标签: android listview opengl-es onitemclick