Android 3D Game Development tutorial-Part IV

Source: Internet
Author: User

These Android 3D Game Development articles are originally written by Martin, a German, at droidnova.com. lixinso is translated into Chinese.

The fourth part of this series shows how to add colors to triangles.

In the previous section, we created a second static triangle to verify that we rotate a triangle instead of the entire scenario. Here we delete this static triangle. Delete the initstatictriangle () function and delete two buffers: _ indexbufferstatic and _ vertexbufferstatic. At the same time, delete the last four rows in ondrawframe () used in the original static triangle.

The new ondrawframe () method is as follows:

Now we create a new buffer for saving color information. This _ colorbuffer is an object variable, but we need to define the color in the inittriangle () method and fill the buffer.

We have created an object variable _ colorbuffer (Row 4) of the floatbuffer type ). In the inittriangle () method, we allocated enough memory (lines 19-21) for the new color buffer ). Next, we create a float array (rows 23-27) with four values for each vertex. This structure is rgba (red, green, blue, alpha), so the first vertex is red, the second color is green, and the third color is blue. The last two parts are the same as the _ vertexbuffer. We put the color array in the buffer and set the position of the buffer to 0.

After all these preparations are completed, we begin to tell OpenGL ES to use our color array. This is done by using glenableclientstate () and glcolorpointer (), similar to vertexbuffer.

We enable color mode for the fifth line. In line 17, we set the color pointer. Parameter 4 indicates that rgba (rgba is exactly four values). You are familiar with the other parameters.

As you may have seen, we have commented out 15 lines, because we use color mode, so we no longer need glcolor4f. It will overwrite, so we can comment out or delete it.

Eclipse project source code reference: vortex Part IV

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.