GaHingZ 发布的文章

OpenGL ES 开发笔记



2016/04/14


HelloOpenGlES

  • 先建项目,MainActivity

    public class MainActivity extends AppCompatActivity { private GLSurfaceView glSurfaceView; private boolean rendererSet = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //用GLSurfaceView 初始化OpenGL 为显示GL surface glSurfaceView=new GLSurfaceView(this); /*

    • 检查OpenGl ES版本
    • */ final ActivityManager activityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); final boolean supportEs2 =configurationInfo.reqGlEsVersion >=0x20000; Log.i("zjx",configurationInfo.reqGlEsVersion+";;;");//输出196608 16进制=0x30000 3.0版本 if(supportEs2){ //为了兼容2.0版本的 这边不设置Version为3 glSurfaceView.setEGLContextClientVersion(2); //传入一个自定义Renderer渲染器 glSurfaceView.setRenderer(new FirstRenderer()); rendererSet = true ; //显示在屏幕上 setContentView(glSurfaceView); } } @Override protected void onPause() { super.onPause(); //暂停surfaceView,释放OpenGl上下文 if(rendererSet){ glSurfaceView.onPause(); } }

      @Override protected void onResume() { super.onResume(); //继续后台渲染线程,续用OpenGL上下文 if(rendererSet){ glSurfaceView.onResume(); } } }


NDK-JNI开发笔记


2016/04/13

hello-jni项目(基于android studio 2.0)

(as2.2+ 可以用cmake 其实现,非常简单 不用.h文件 一开始的配置见 http://tools.android.com/tech-docs/external-c-builds 后面只要写个native方法 c文件中写对应的函数即可 )

  • 配置NDK 如果没下载NDK的话

    File->Settings Appearance & Behavior->System Settings ->Android SDK 右侧选择SDK Tools 勾选NDK更新 勾上更新重启项目。

local.properties里面如果没自动配置的话就这样配置(按上述步骤安装ndk 其目录就在sdk下)

## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Wed Apr 13 00:40:11 CST 2016
ndk.dir=E\:\\BaiduYunDownload\\adt-bundle-windows-x86_64-20140702\\sdk\\ndk-bundle
sdk.dir=E\:\\BaiduYunDownload\\adt-bundle-windows-x86_64-20140702\\sdk
  • 新建Project,一个Activity(xml中带一个TextView)
  • 新建一个NdkJniUtils类 声明原生方法getCString();

    public class NdkJniUtil { public native String getCString(); }

  • 生成C/C++ 头文件

法1: IDE:Build->MakeProject 得到class 编译之后的class在目录下