Android development-OpenGL ES 3D space and glDrawArrays

Source: Internet
Author: User

1. Four pyramid: composed of four triangles.

Ry: consists of six triangles.

Difficulty: when constructing the vertex coordinates of a 3D space, to make the object rotate around its own axis, the central coordinates of the object must always be (0.0f, 0.0f, 0.0f ),

And the triangles are drawn in a counter-clockwise order.

2.3D space rendering:

GL_APICALL void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count );

Parameter description:

Mode: drawing method. The following parameters are provided after OpenGL2.0: GL_POINTS, GL_LINES, GL_LINE_LOOP, GL_LINE_STRIP, GL_TRIANGLES, GL_TRIANGLE_STRIP, and GL_TRIANGLE_FAN.

First, which position in the array cache is drawn, generally 0.

Count, number of vertices in the array.

3. Draw the vertex array:

// Draw a triangle cone

For (int I = 0; I <4; I ++)

{

Gl. glDrawArrays (GL10.GL _ TRIANGLE_STRIP, I * 3, 3 );

}

// Draw a ry

For (int I = 0; I <6; I ++)

{

Gl. glDrawArrays (GL10.GL _ TRIANGLE_STRIP, I * 4, 4 );

}

[Appendix] constructing vertex Arrays:

[Java]

Int one = 0x10000;

// An array of four pyramid vertices:

Private IntBuffer triggerBuffer = IntBuffer. wrap (new int [] {

0, one, 0,

-One,-one, 0,

One,-one, one,

0, one, 0,

One,-one, one,

One,-one,-one,

0, one, 0,

One,-one,-one,

-One,

0, one, 0,

-One,

-One,-one, one

});

// An array of Four-body vertices:

Private IntBuffer quaterBuffer = IntBuffer. wrap (new int [] {

One, one,-one,

-One, one,-one,

One,

-One,

One,-one, one,

-One,-one, one,

One,-one,-one,

-One,

One,

-One,

One,-one, one,

-One,-one, one,

One,-one,-one,

-One,

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 one = 0x10000;

// An array of four pyramid vertices:

Private IntBuffer triggerBuffer = IntBuffer. wrap (new int [] {

0, one, 0,

-One,-one, 0,

One,-one, one,

0, one, 0,

One,-one, one,

One,-one,-one,

0, one, 0,

One,-one,-one,

-One,

0, one, 0,

-One,

-One,-one, one

});

// An array of Four-body vertices:

Private IntBuffer quaterBuffer = IntBuffer. wrap (new int [] {

One, one,-one,

-One, one,-one,

One,

-One,

One,-one, one,

-One,-one, one,

One,-one,-one,

-One,

One,

-One,

One,-one, one,

-One,-one, one,

One,-one,-one,

-One,

One, one,-one,

-One, one,-one,

-One,

-One, one,-one,

-One,-one, one,

-One,

One, one,-one,

One,

One,-one,-one,

One,-one, one,

});

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.