issue #1190: Updated HelloLua.java and Cocos2dxGLSurfaceView.java, make HelloLua app support opengles2.0.

This commit is contained in:
James Chen 2012-04-26 12:06:51 +08:00
parent 8d63e9f1bd
commit 394622f538
2 changed files with 33 additions and 9 deletions

View File

@ -24,22 +24,34 @@ THE SOFTWARE.
package org.cocos2dx.hellolua; package org.cocos2dx.hellolua;
import org.cocos2dx.lib.Cocos2dxActivity; import org.cocos2dx.lib.Cocos2dxActivity;
import org.cocos2dx.lib.Cocos2dxGLSurfaceView; import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
import org.cocos2dx.lib.Cocos2dxRenderer;
import android.app.ActivityManager;
import android.content.Context; import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
public class HelloLua extends Cocos2dxActivity{ public class HelloLua extends Cocos2dxActivity{
protected void onCreate(Bundle savedInstanceState){ protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (detectOpenGLES20()) {
// get the packageName,it's used to set the resource path // get the packageName,it's used to set the resource path
String packageName = getApplication().getPackageName(); String packageName = getApplication().getPackageName();
super.setPackageName(packageName); super.setPackageName(packageName);
mGLView = new LuaGLSurfaceView(this); mGLView = new LuaGLSurfaceView(this);
setContentView(mGLView); setContentView(mGLView);
mGLView.setEGLContextClientVersion(2);
mGLView.setCocos2dxRenderer(new Cocos2dxRenderer());
}
else {
Log.d("activity", "don't support gles2.0");
finish();
}
} }
@Override @Override
@ -54,7 +66,16 @@ public class HelloLua extends Cocos2dxActivity{
mGLView.onResume(); mGLView.onResume();
} }
private GLSurfaceView mGLView; private boolean detectOpenGLES20()
{
ActivityManager am =
(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo info = am.getDeviceConfigurationInfo();
return (info.reqGlEsVersion >= 0x20000);
}
private LuaGLSurfaceView mGLView;
static { static {
System.loadLibrary("cocosdenshion"); System.loadLibrary("cocosdenshion");

View File

@ -145,10 +145,13 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
initView(); initView();
} }
protected void initView() { public void setCocos2dxRenderer(Cocos2dxRenderer renderer){
mRenderer = new Cocos2dxRenderer(); mRenderer = renderer;
setFocusableInTouchMode(true);
setRenderer(mRenderer); setRenderer(mRenderer);
}
protected void initView() {
setFocusableInTouchMode(true);
textInputWraper = new TextInputWraper(this); textInputWraper = new TextInputWraper(this);