標籤:android style blog http io color os ar java
- 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 代碼:
(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;@Overrideprotected 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);}@Overridepublic 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;}@Overrideprotected void onResume() {// TODO Auto-generated method stubsuper.onResume();mGLSurfaceView.onResume();}@Overrideprotected void onPause() {// TODO Auto-generated method stubsuper.onPause();mGLSurfaceView.onPause();}@Overridepublic 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);}}
osg for android (一) 簡單幾何物體的載入與顯示