Domanda

What I'm trying to do here, is to load a OpenGL context when I click a item of the listview in main activity.

Simple as it looks! But I really don't know how to connect main activity with the OpenGL activity. Could any one give me some hint?

Thank you!!

EDIT: ADD some code here:

In main activity:

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

            }
        });

In 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);
}

}

(using some tutorial code for experiment)

Error Message:

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)

And the app "Unfortunately stopped"

È stato utile?

Soluzione

If you run your code on the emulator try to enable "use host gpu". Or if you can, try it on a real device. Emulator is pretty bad idea for openGl stuff becouse it is much slower than real device.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top