2013-07-19 20 views
0

我在這裏要做的是加載一個OpenGL上下文,當我點擊主活動中的列表視圖項時。從列表視圖項加載OpenGL點擊

看起來很簡單!但我真的不知道如何將主要活動與OpenGL活動連接起來。任何人都可以給我一些提示嗎?

謝謝!

編輯:ADD這裏一些代碼:

在主要活動:

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) 

和應用程序「不幸的是停止」

+0

像普通視圖一樣創建[GLSurfaceView](http://developer.android.com/reference/android/opengl/GLSurfaceView.html)並設置渲染器。 –

+0

@MarcinGawel是的,但我真的不知道我在做什麼錯在這裏,添加代碼段 – Imemmaw

+0

任何錯誤或發生了什麼? –

回答

0

如果您在模擬器上試運行您的代碼,以使「使用主機GPU」。或者如果可以的話,可以在真實設備上試用。模擬器對於openGl的東西來說是個不錯的主意,因爲它比真實的設備慢得多。

+0

哈哈感謝兄弟! – Imemmaw