`
老七的米店
  • 浏览: 46715 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Api Demo - .graphics(24)>>Cube

阅读更多
package com.example.android.apis.graphics;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;

import javax.microedition.khronos.opengles.GL10;

/**
 * A vertex shaded cube.
 */
class Cube
{
    public Cube()
    {
        int one = 0x10000;
      /*
       * 0x10000是出于OPENGL前期内存节约的考虑, 以INT型模拟FLOAT型来表示, 0x 0001 0000 前面4位表示小数点前,后4位表示小数点后,
       *所以0x10000表示浮点数的1。如果你用的是FloatBuffer,就可以知道此处应该写1.0
       */
        int vertices[] = {//顶点数组
                -one, -one, -one,
                one, -one, -one,
                one,  one, -one,
                -one,  one, -one,
                -one, -one,  one,
                one, -one,  one,
                one,  one,  one,
                -one,  one,  one,
        };

        int colors[] = {//颜色数组
                0,    0,    0,  one,
                one,    0,    0,  one,
                one,  one,    0,  one,
                0,  one,    0,  one,
                0,    0,  one,  one,
                one,    0,  one,  one,
                one,  one,  one,  one,
                0,  one,  one,  one,
        };

        byte indices[] = {//索引数组,即指定哪3个点构成一个面(三角形)
                0, 4, 5,    0, 5, 1,
                1, 5, 6,    1, 6, 2,
                2, 6, 7,    2, 7, 3,
                3, 7, 4,    3, 4, 0,
                4, 7, 6,    4, 6, 5,
                3, 0, 1,    3, 1, 2
        };


        ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4);//建立顶点缓冲 int类型占8个字节,Byte占2个所以*4;
        vbb.order(ByteOrder.nativeOrder());//设置为本地平台字节顺序。
        mVertexBuffer = vbb.asIntBuffer();//将Byte缓冲转为int缓冲。
        mVertexBuffer.put(vertices);//放入顶点数组
        mVertexBuffer.position(0);//置0;

        ByteBuffer cbb = ByteBuffer.allocateDirect(colors.length*4);//颜色缓冲
        cbb.order(ByteOrder.nativeOrder());
        mColorBuffer = cbb.asIntBuffer();
        mColorBuffer.put(colors);
        mColorBuffer.position(0);

        mIndexBuffer = ByteBuffer.allocateDirect(indices.length);//索引缓冲。
        mIndexBuffer.put(indices);
        mIndexBuffer.position(0);
    }

    public void draw(GL10 gl)
    {
        gl.glFrontFace(gl.GL_CW);//确定正面。
        gl.glVertexPointer(3, gl.GL_FIXED, 0, mVertexBuffer);//为画笔指定顶点坐标
        gl.glColorPointer(4, gl.GL_FIXED, 0, mColorBuffer);//为画笔指定顶点颜色
        gl.glDrawElements(gl.GL_TRIANGLES, 36, gl.GL_UNSIGNED_BYTE, mIndexBuffer);//索引法画图。
    }

    private IntBuffer   mVertexBuffer;
    private IntBuffer   mColorBuffer;
    private ByteBuffer  mIndexBuffer;
}

 

0
0
分享到:
评论

相关推荐

    cubedemo-0.3.7cubedemo-0.3.7

    cubedemo-0.3.7cubedemo-0.3.7cubedemo-0.3.7cubedemo-0.3.7cubedemo-0.3.7cubedemo-0.3.7cubedemo-0.3.7cubedemo-0.3.7cubedemo-0.3.7cubedemo-0.3.7cubedemo-0.3.7

    esapi-2.1.0.1_esapi-2.1.0.1_

    提供ESAPI jar包下载 esapi-2.1.0.1.jar

    spring4 mvc + jpa demo

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <jdk.version>1.7</jdk.version> <spring.version>4.0.1.RELEASE</spring.version> <spring-data-jpa.version>1.6.2.RELEASE</spring-...

    ProCamera2D

    - Camera Window >>DEMO - Cinematics >>DEMO - Content Fitter >>DEMO - Forward Focus >>DEMO - Geometry Boundaries - Limit Distance >>DEMO - Limit Speed >>DEMO - Numeric Boundaries >>DEMO - Pan ...

    Face-api.js静态页面版Demo

    JavaScript人脸识别库Face-api.js的示例,无需安装nodejs,iis本地直接看效果。注意调用摄像头不能用IP访问,只能localhost,远程预览需要HTTPS;iis无扩展名文件若出现404,需在mime类型中添加扩展名【.】类型...

    ViewPagerDemo-2013.1.24.zip

    ViewPagerDemo-2013.1.24.zip ViewPagerDemo-2013.1.24.zip ViewPagerDemo-2013.1.24.zip ViewPagerDemo-2013.1.24.zip

    demo-0.0.1-SNAPSHOT.jar

    返回json数组的科技头条的api数据jar包

    Api-dawn-api-demo.zip

    Api-dawn-api-demo.zip,道恩API解调API,一个api可以被认为是多个软件设备之间通信的指导手册。例如,api可用于web应用程序之间的数据库通信。通过提取实现并将数据放弃到对象中,api简化了编程。

    poi-5.2.0-API文档-中文版.zip

    包含翻译后的API文档:poi-5.2.0-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.apache.poi:poi:5.2.0; 标签:apache、poi、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index....

    Api-demo.zip

    Api-demo.zip,API平台的演示应用程序框架API平台演示,一个api可以被认为是多个软件设备之间通信的指导手册。例如,api可用于web应用程序之间的数据库通信。通过提取实现并将数据放弃到对象中,api简化了编程。

    autoconfig-demo.zip

    <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot...

    可keil编译sam3x_ek_bertos_http_demo

    根据atmel官方例程sam3x_ek_bertos_http_demo,自己...在keil->Project->Manage->Components,Environment,Books...->Folders/Externsions的 Use GCC的GNU-Tool Folder中指定arm-2012.03-56-arm-none-eabi.exe的安装目录

    oss-sdk-demo 阿里云开放云存储服务Demo

    阿里云青岛节点oss服务报错解决方式 The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. endpoint 根据自己选择的节点...

    jquery日历控件

    <div class="demo-description"> <p>The datepicker is tied to a standard form input field. Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay. Choose a ...

    open-api-sdk-2.0和jackson,京东宙斯开发jar包,宙斯API包

    open-api-sdk-2.0和jackson,京东宙斯开发jar包,宙斯API包,本人开发使用,open-api-sdk-2.0.jar,jackson-core-asl-1.9.8.jar,jackson-mapper-asl-1.9.8.jar,需要朋友可自行下载

    service-api-demo.rar

    此工程集成了nexus私服,配合我的“nexus搭建和基于spring boot2.x的配置,centos7"博客,可以使用spring boot集成nexus

    mybatis-3.2.7.jar-lib-source code API settings Timeout MyBatisDemo 常用例子

    mybatis-3.2.7.jar source code API configuration.xml settings defaultStatementTimeout 的设置 MyBatisDemo 常用例子 使用3种方法,编写mapper,操作数据库

    android-serialport-api 串口demo.zip

    这是很据android-serialport-api 自己简化的一个demo ,可以使用。原来android-serial-api的程序很多人反映都不能使用,所以自己写了这个,只有一个activity,可以做为你的学习参考。

    脚手架-ncpub-multipage-demo.zip

    为了便于NCC开发,前端需在Visual Studio Code中部署脚手架,脚手架里封装了与NCC后端关联的配置,实现前后端分离开发。

    GCD常用和不常用API说明GCD-Demo-master.zip

    GCD常用和不常用API说明GCD_Demo-master.zip

Global site tag (gtag.js) - Google Analytics