Code example for GLSurfaceView

Methods: setEGLContextClientVersion, setOnTouchListener, setRenderer

0
	private boolean mRendererSet = false;
	 
	@Override 
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mGlSurfaceView = new GLSurfaceView(this);
		 
		final ActivityManager activityManager =
        		(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
         
        final ConfigurationInfo configurationInfo =
        		activityManager.getDeviceConfigurationInfo();
         
        // OpenGL ES2 지원 여부, Build 버전 체크는 simulator 때문 
        final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000
        		|| (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1
        		&& (Build.FINGERPRINT.startsWith("generic")
        				|| Build.MODEL.contains("google_sdk") 
        				|| Build.MODEL.contains("Emulator")));
         
        final MainRenderer mainRenderer = new MainRenderer(this);
		 
         
        if (supportsEs2) {
        	mGlSurfaceView.setEGLContextClientVersion(2);
        	mGlSurfaceView.setRenderer(mainRenderer);
        	mRendererSet = true;
        } else { 
        	mRendererSet = false;
        	Toast.makeText(this, "This device does not support OpenGL ES 2.0",
        			Toast.LENGTH_LONG).show();
        	return; 
        } 
         
        mGlSurfaceView.setOnTouchListener(new View.OnTouchListener() {
			@Override 
			public boolean onTouch(View v, MotionEvent event) {
				if (event == null) return false;
				 
				// event x, y를 normalized device coordinate로 변환한다.