博观而约取,厚积而薄发。这篇文章主要讲述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:UsersSpring.androidavdAndroid_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;
@Override
protected 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);
}
@Override
protected void onPause() {
super.onPause();
if (rendererSet) {
glSurfaceView.onPause();
}
}@Override
protected 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 {
@Override
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
}@Override
public 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.
*/
@Override
public 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函数操作步骤】再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow
推荐阅读
- APP测试的内容
- abpCrudAppService自定义分页排序
- 4.Appium 安卓自动化(Andriod SDK)
- 区块链会员系统开发,制度钱包app开发
- Cause: java. lang.InstantiationException: tk.mybatis.mapper.provider.base.BaseInsertProvider
- 5.Appium 安卓自动化(UIAutomator)
- Android mk和Application mk文件语法规范说明及举例
- 趣享付APP再升级,剑指精准营销
- selector的使用,android:clickable="true"