osg for android (一) 簡單幾何物體的載入與顯示

來源:互聯網
上載者:User

標籤: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 (一) 簡單幾何物體的載入與顯示

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.