(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;
@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);
}
}
顯而易見,如果你的項目是想要靈活高效,且極具顯示效果的的地圖界面那就用ogre,如果你是真對大型數據集提供精確的計算結果,及高難度的圖層疊加計算分析,那麼就用osg,另外提一句,osg是基於OpenGL接口開發的,而esri最近開發的arcgis for android API也是基於OpenGL的,你自己分析一下吧,看哪個更適合你的項目,一家之言,錯了勿噴,獨家手打,僅供參考。