开发框架介绍请参见:Opengl ES NDK实例开发之一:搭建开发框架
本章在上一章的基础上讲解顶点缓存数组(Vertex Buffer Object)即VBO的使用,使用VBO来实现金字塔和立方体的绘制,绘制的效果和上一章相同。这个系列教程主要是采用实例演示 Opengl ES 1.x NDK开发,对一些要点进行解释,因此对API的用法和说明较少,建议初学者可以参考Opengl ES 1.x的API手册。
>>>为什么要使用VBO?
VBO的数据存放在显卡内存中,能节省从系统内存复制到显卡内存中的时间,提高渲染的效率。
>>>VBO顶点缓存的使用范围?
VBO可以缓存顶点、颜色、纹理坐标、索引。
【实例讲解】
本章示例了VBO缓存顶点、颜色和索引的用法。
【实例源码】
[GLJNIActivity.java]
- /*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * author: mnorst@foxmail.com
- */
- package com.android.gljni;
- import com.android.gljni.GLJNIView;
- import android.app.Activity;
- import android.os.Bundle;
- public class GLJNIActivity extends Activity {
- GLJNIView mView;
- @Override
- protected void onCreate(Bundle icicle) {