在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ Android/ 創(chuàng)建實例應(yīng)用 OpenGLDemos 程序框架
繪制線段 Line Segment
投影變換 Projection
繪制迷你太陽系
繪制一個球體
繪制三角形 Triangle
OpenGL 光照模型
三維坐標(biāo)系及坐標(biāo)變換初步
定義 3D 模型的前面和后面
繪制一個 20 面體
顏色 Color
Depth Buffer
材質(zhì)及光照示例
基本幾何圖形定義
關(guān)于EGL
導(dǎo)言
Viewing 和 Modeling(MODELVIEW) 變換
FrameBuffer
設(shè)置光照效果 Set Lighting
Viewport 變換
階段小結(jié)
繪制點 Point
OpenGL ES API 命名習(xí)慣
通用的矩陣變換指令
關(guān)于 OpenGL ES
創(chuàng)建實例應(yīng)用 OpenGLDemos 程序框架
OpenGL ES 管道(Pipeline)
GLSurfaceView

創(chuàng)建實例應(yīng)用 OpenGLDemos 程序框架

有了前面關(guān)于 Android OpenGL ES 的介紹,可以開始創(chuàng)建示例程序 OpenGLDemos。

使用 Eclipse 創(chuàng)建一個 Android 項目

  • Project Name: OpenGLDemos
  • Build Target: Android 1.6 ( >1.5 即可)
  • Application Name: Android OpenGL ES Demos
  • Package Name: com.pstreets.opengl.demo
  • Create Activity:AndroidOpenGLDemo

采用 Android ApiDemos 類似的方法,AndroidOpenGLDemo 為一 ListActivity ,可以使用 PackageManager 讀取所有 Category 為 guidebee.intent.category.opengl.SAMPLE_CODE 的 Activity。 Android ApiDemos 示例解析(2): SimpleAdapter,ListActivity,PackageManager

創(chuàng)建一個 OpenGLRenderer 實現(xiàn) GLSurfaceView.Renderer 接口:

public class OpenGLRenderer implements Renderer {
 private final IOpenGLDemo openGLDemo;
 public OpenGLRenderer(IOpenGLDemo demo){
 openGLDemo=demo;
 }
 public void onSurfaceCreated(GL10 gl, EGLConfig config) {
 // Set the background color to black ( rgba ).
 gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
 // Enable Smooth Shading, default not really needed.
 gl.glShadeModel(GL10.GL_SMOOTH);
 // Depth buffer setup.
 gl.glClearDepthf(1.0f);
 // Enables depth testing.
 gl.glEnable(GL10.GL_DEPTH_TEST);
 // The type of depth testing to do.
 gl.glDepthFunc(GL10.GL_LEQUAL);
 // Really nice perspective calculations.
 gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
 GL10.GL_NICEST);
 }
 public void onDrawFrame(GL10 gl) {
 if(openGLDemo!=null){
 openGLDemo.DrawScene(gl);
 }
 }
 public void onSurfaceChanged(GL10 gl, int width, int height) {
 // Sets the current view port to the new size.
 gl.glViewport(0, 0, width, height);
 // Select the projection matrix
 gl.glMatrixMode(GL10.GL_PROJECTION);
 // Reset the projection matrix
 gl.glLoadIdentity();
 // Calculate the aspect ratio of the window
 GLU.gluPerspective(gl, 45.0f,
 (float) width / (float) height,
 0.1f, 100.0f);
 // Select the modelview matrix
 gl.glMatrixMode(GL10.GL_MODELVIEW);
 // Reset the modelview matrix
 gl.glLoadIdentity();
 }
}  

為簡潔起見,為所有的示例定義了一個接口 IOpenGLDemo,

public interface IOpenGLDemo {
 public void DrawScene(GL10 gl);
}  

DrawScene 用于實際的 GL 繪圖示例代碼,其它的初始化工作基本就由 GLSurfaceView 和 OpenGLRenderer 完成,其中 onSurfaceCreated 和 onSurfaceChanged 中的代碼含義現(xiàn)在無需了解,后面會有具體介紹,只要知道它們是用來初始化 GLSurfaceView 就可以了。

最后使用一個簡單的例子 “Hello World” 結(jié)束本篇,“Hello World” 使用紅色背景刷新屏幕。

public class HelloWorld extends Activity
   implements IOpenGLDemo{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow()
         .setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        mGLSurfaceView = new GLSurfaceView(this);
        mGLSurfaceView.setRenderer(new OpenGLRenderer(this));
        setContentView(mGLSurfaceView);
    }
    public void DrawScene(GL10 gl) {
        gl.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
        // Clears the screen and depth buffer.
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT
          | GL10.GL_DEPTH_BUFFER_BIT);
    }
    @Override
    protected void onResume() {
        // Ideally a game should implement
        // onResume() and onPause()
        // to take appropriate action when the
        //activity looses focus
        super.onResume();
        mGLSurfaceView.onResume();
    }
    @Override
    protected void onPause() {
        // Ideally a game should implement onResume()
        //and onPause()
        // to take appropriate action when the
        //activity looses focus
        super.onPause();
        mGLSurfaceView.onPause();
    }
    private GLSurfaceView mGLSurfaceView;
}  

其對應(yīng)在 AndroidManifest.xml 中的定義如下:

<activity android:name=”.HelloWorld” android:label=”@string/activity_helloworld”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”guidebee.intent.category.opengl.SAMPLE_CODE” />
</intent-filter>
</activity>  

http://wiki.jikexueyuan.com/project/opengl-es-guide/images/45.png" alt="" />

本例下載