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;
@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》
分享到:
相关推荐
Android 3D游戏开发技术宝典:OpenGL ES 2.0书中的全部源代码。该书由浅入深的讲解了OpenGL ES 2.0在3D游戏开发中的各个方面,还给出了BN赛艇、火力篮球、夜鹰行动三个经典游戏的全部源代码。 由于此资源比较老,...
SDL Android 例子源码可用工程,实测编译通过在模拟器运行(SDL 2.0 for Android),工程目录名叫AndroidTst2,编译通过可用, sdl source code for android android source code for sdl 2.0 这个工程的文件夹...
在Eclipse中设置Android模拟器屏幕大小
本程序是在Eclipse中创建的一个Android Application,该项目中是在JNI中利用OpenGL ES库和OpenCV库进行一副图片的渲染。
13.6 opengl es 1.x与opengl es 2.0实现方案的对比 363 13.7 本章小结 364 第14章 片元着色器的妙用 365 14.1 程序纹理技术 365 14.1.1 砖块着色器 365 14.1.2 沙滩球着色器 367 14.2 数字图像...
使用 OpenGL ES 2.0 和 NDK 的 Android 阴影映射实现 这是从我的用于 MaliSDK 的 Shadow Mapping 实现到 Android 的移植。 所有 OpenGL 逻辑都是用 C++ 实现的,并使用 NDK 编译。 Activity 和 SurfaceView 对象是...
Android模拟器emulator.exe文件包含了很多参数,平时在Eclipse IDE中,模拟器运行被自动调用的,如果仅仅使用Android emulator或采用NetBean这样的开放环境又如何设置呢? 我们总结了一下模拟器的所有参数及使用方法...
android开发所使用的 模拟器系统源码,用于练习时需要跳转到模拟器自带页面时 ,设置隐式意图 , 查看意图过滤器等等。ceshiguo eclipse自带 AVD模拟器 和 genymotion模拟器
Eclipse下Android插件配置步骤 新手 请多多指教
SAPjar包(eclipse中Java使用JCO调用SAP中的RFC函数)
作者原创:如何将Android原生的Phone程序通过eclipse跑在模拟器上,让开发者轻松地修改调试Android源码里的Phone程序。
在eclipse中添加android ADT
eclipse android glsufaceview camera2 opengles2.0 shader 摄像头图像的实时滤镜(饱和度/灰底/冷暖色/放大镜/模糊/美颜)、镜像、纹理融合处理
Android应用编程基础文章,主要包括编译环境搭建,Eclipse与模拟器的选择和配置,真机调试方法等,资料来源于微价值网。
今天在Eclipse中运行Android项目时遇到”The connection to adb is down, and a severe error has occured”这个问题,如下图所示: 第一次遇到这个问题,上网查了一下原因,原来”The connection to adb is ...
OpenGL 2.0 examples HelloOpenGLES20 is Google’s basic framework example. 2D square and triangle with touch events to spin the triangle API 8 Opengl2ex1 uses a renderer (lessonOne from ...
Android 3D游戏开发技术宝典 OpengGL ES2.0的附书源码 与教程对应,也可以单独学习 内含的都是可直接导入到eclipse中的android工程 因资源太大,把bin文件夹删除了,使用时需要重新编译 如果文件有问题,可以联系我...
adb 请求 连接 模拟器 虚拟机
Windroye模拟器,作为ANDROID模拟器相当快速 支持ECLIPSE选择设备部署应用,查看LOGCAT, 基本上可以抛弃原生的卡成狗的GOOGLE自带模拟器
用于eclipse3.7以上版本,已经在eclipse3.7、3.8版本中亲自测试通过。 使用方法: 将解压后的文件夹“Activiti BPMN 2.0 designer”, 直接复制到eclipse根目录下的dropins目录中, 重启eclipse,即可生效