Opengl1

Android

簡介

使用方法

開發工具

開始寫程式

視覺化介面

視覺元件

對話元件

核心物件

事件處理

資料儲存

查詢功能

影音功能

繪圖功能

網路功能

衛星地圖

特殊功能

資源管理

裝置管理

系統核心

問題與回答

刷機升級

常用軟體

Eclipse

教學錄影

訊息

相關網站

參考文獻

最新修改

簡體版

English

專案下載:OpenGL1.zip

執行結果

OpenGL1Run.png

程式範例:OpenGL1.java

package ccc.android;
 
import android.app.Activity;
import android.os.Bundle;
import android.content.Context;  
import android.opengl.GLSurfaceView;
import javax.microedition.khronos.egl.EGLConfig;  
import javax.microedition.khronos.opengles.GL10;  
 
public class OpenGL1 extends Activity {
 
      private GlView mGlView;  
 
      public void onCreate(Bundle savedInstanceState){  
        super.onCreate(savedInstanceState);  
        mGlView = new GlView(this);  
        setContentView(mGlView);  
      }  
}
 
class GlView extends GLSurfaceView{  
 
      private GlRender mGlRender;   
 
      public GlView(Context context){  
        super(context);  
 
        mGlRender = new GlRender();  
        setRenderer(mGlRender);  
      }  
}  
 
class GlRender implements GLSurfaceView.Renderer{  
 
      @Override  
      public void onSurfaceCreated(GL10 gl,EGLConfig config){  
        gl.glClearColor( 0.0f, 1.0f, 0.0f, 1.0f);// 3D背景色rgba  
      }  
 
      @Override  
      public void onSurfaceChanged(GL10 gl,int w,int h){  
        gl.glViewport( 0, 0, w, h );  
        gl.glMatrixMode( GL10.GL_PROJECTION);  
        gl.glLoadIdentity();
        float ratio;  
        ratio = (float)w/h;  
        gl.glFrustumf(-ratio,ratio,-1,1,1,500);  
      }  
 
      @Override  
      public void onDrawFrame(GL10 gl){  
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);  
        gl.glMatrixMode(GL10.GL_MODELVIEW);  
        gl.glLoadIdentity();  
      }  
}

參考文獻

  1. Max の 3D Studio, 2010年11月1日星期一【教學】Android OpenGL ES 3D基本框架建立 — http://ig-max.blogspot.com/2010/11/android-opengl-es-3d.html

Facebook

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License