• 1. 首先需要一个OSG for android的环境.
  • (1).NDK 现在Eclipse 对NDK已经相当友好了,已经不需要另外cygwin的参与,具体可以参考
  • Android NDK开发篇(一):新版NDK环境搭建(免Cygwin,超级快)
  • (2).osg for android的编译,参考 osg for android学习之一:windows下编译(亲测通过) 建议编译OpenGL ES2版本.
  • 2.然后加载OSG自带的Example:osgAndroidExampleGLES2

  • (1)点击菜单键加载文件路径,输入/sdcard/osg/cow.osg(必须先往sdcard创建文件夹osg并把cow.osg放到该文件夹里边)

(2)接着经典的牛出现了:)

3.自带的example太多的代码,这样的代码无论对于NDK的初学者或OSG很不直观,所以本人重写了一个HelloWolrd for osg的例子。例子很简单,就是简单加载一个四边形并附上颜色。

(1)Java 代码:

package com.example.helloosg;import android.app.Activity;import android.opengl.GLSurfaceView;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.widget.TextView;public class MainActivity extends Activity {    private GLSurfaceView mGLSurfaceView;        @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        mGLSurfaceView = new GLSurfaceView(this);        mGLSurfaceView.setEGLContextClientVersion(2);        NDKRenderer renderer = new NDKRenderer();        this.mGLSurfaceView.setRenderer(renderer);        this.setContentView(mGLSurfaceView);    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.main, menu);        return true;    }    @Override    protected void onResume() {        // TODO Auto-generated method stub        super.onResume();        mGLSurfaceView.onResume();    }    @Override    protected void onPause() {        // TODO Auto-generated method stub        super.onPause();        mGLSurfaceView.onPause();    }    @Override    public boolean onOptionsItemSelected(MenuItem item) {        // Handle action bar item clicks here. The action bar will        // automatically handle clicks on the Home/Up button, so long        // as you specify a parent activity in AndroidManifest.xml.        int id = item.getItemId();        if (id == R.id.action_settings) {            return true;        }        return super.onOptionsItemSelected(item);    }}

更多相关文章

  1. android全平台编译ffmpeg以及x264与fdk-aac实践
  2. 为Android加入busybox工具
  3. Android之NDK开发
  4. Android开发知识概要
  5. Android的init过程(二):初始化语言(init.rc)解析
  6. Ubuntu上开发Android
  7. LTP(Linux Test Project) for Android的编译
  8. Android(安卓)WebView 用法
  9. Android快速开源框架--afinal

随机推荐

  1. Android——四种基本布局
  2. Android下实现一个Activity的全屏显示
  3. android selector状态详解
  4. Android系统自带样式(android:theme)详解
  5. android 资源引用
  6. android ImageView的属性android:scaleTy
  7. android在Gridview实现Textview跑马灯效
  8. android知识点记录
  9. Android实现LIstView条目单选和多选Radio
  10. Android(安卓)GridLayout 的 columnSpan