Eclipse中通过Android模拟器调用OpenGL ES2.0函数操作步骤
1、? 先按照http://blog.csdn.net/fengbingchun/article/details/10439281中操作搭建好基本的Android開發環境;
2、? 打開Eclipse,-->Window-->AndroidVirtual Device Manager-->New-->AVD Name:Android_OpenGLES, Device:GalaxyNexus(4.65”,720*1280:xhdpi),Target:Android 4.3-API Level 18;Emulation Options中勾選Use HostGPU,點擊OK;
3、? 選中新建的Android_OpenGLES,-->Start-->Launch,如果運行失敗,則將其C:\Users\Spring\.android\avd\Android_OpenGLES.avd文件夾中的config.ini文件,將hw.ramSize=1024改為hw.ramSize=1024MB,保存,再次運行即會成功;
4、? 創建一個新工程,判斷設備是否支持OpenGL ES2.0;
5、? File-->New-->Project…-->Android-->Android ApplicationProject-->Next-->Application Name:FirstOpenGLProject,Package Name:com.firstopenglproject.android,MinimumRequired SDK:API 10, Android 2.3.3(Gingerbread)(this is the minimum versionwith full OpenGL ES 2.0 support), Next-->不勾選Create customlauncher icon,勾選Create activity,Next-->選中Blank Activity,Next-->Activity Name:FirstOpenGLProjectActivity-->Finish;
打開src-->com.firstopenglproject.android-->FirstOpenGLProjectActivity.java,將其內容改為:
?
package com.firstopenglproject.android;import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Toast;public class FirstOpenGLProjectActivity extends Activity {private GLSurfaceView glSurfaceView;private boolean rendererSet = false;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//setContentView(R.layout.activity_first_open_glproject);glSurfaceView = new GLSurfaceView(this);final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();final boolean supportsEs2 =configurationInfo.reqGlEsVersion >= 0x20000|| (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1&& (Build.FINGERPRINT.startsWith("generic")|| Build.FINGERPRINT.startsWith("unknown")|| Build.MODEL.contains("google_sdk")|| Build.MODEL.contains("Emulator")|| Build.MODEL.contains("Android SDK built for x86")));if (supportsEs2) {// Request an OpenGL ES 2.0 compatible context.glSurfaceView.setEGLContextClientVersion(2);// Assign our renderer.glSurfaceView.setRenderer(new FirstOpenGLProjectRenderer());rendererSet = true;} else {Toast.makeText(this, "This device does not support OpenGL ES 2.0.",Toast.LENGTH_LONG).show();return;}setContentView(glSurfaceView);} @Overrideprotected void onPause() {super.onPause();if (rendererSet) {glSurfaceView.onPause();}}@Overrideprotected void onResume() {super.onResume();if (rendererSet) {glSurfaceView.onResume();}}
}
?
?
?
7、 選中com.firstopenglproject.android,點擊右鍵-->New-->Class,Name:FirstOpenGLProjectRenderer-->Finish,其內容為:
?
package com.firstopenglproject.android;import static android.opengl.GLES20.GL_COLOR_BUFFER_BIT;
import static android.opengl.GLES20.glClear;
import static android.opengl.GLES20.glClearColor;
import static android.opengl.GLES20.glViewport;import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;import android.opengl.GLSurfaceView.Renderer;public class FirstOpenGLProjectRenderer implements Renderer {@Overridepublic void onSurfaceCreated(GL10 glUnused, EGLConfig config) {glClearColor(1.0f, 0.0f, 0.0f, 0.0f);}@Overridepublic void onSurfaceChanged(GL10 glUnused, int width, int height) {// Set the OpenGL viewport to fill the entire surface.glViewport(0, 0, width, height);}/*** OnDrawFrame is called whenever a new frame needs to be drawn. Normally,* this is done at the refresh rate of the screen.*/@Overridepublic void onDrawFrame(GL10 glUnused) {// Clear the rendering surface.glClear(GL_COLOR_BUFFER_BIT);}
}
8、選中工程,右鍵-->Run As-->Android Application,將會顯示空白紅色屏幕。
?
?
?
參考文獻:《OpenGL ES 2.0 for Android》
?
?
?
總結
以上是生活随笔為你收集整理的Eclipse中通过Android模拟器调用OpenGL ES2.0函数操作步骤的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Windows 7 64位机上搭建And
- 下一篇: 利用JNI技术在Android中调用C+