Chapter 2 of OpenGl learning and Chapter 2 of opengl

Source: Internet
Author: User

Chapter 2 of OpenGl learning and Chapter 2 of opengl

After openGl is basically drawn, it's time to move from a plane to a three-dimensional one. Now, to draw a Golden Triangle, the main problem is the fixed-point array, GL10.GL _ TRIANGLES,

GL_TRIANGLES-this parameter means OpenGL uses three vertices to form a graph. Therefore, in the first three vertices, vertex 1, vertex 2, and vertex 3 are used to form a triangle. After that, use the three vertices in the next group to form a triangle until the end of the array.
 

So we can use this to draw a golden triangle. The Code has not changed much, but the changes in the vertex array:


// Golden Triangle Array
Private float [] mTriangleArray = {


0.0f, 1.0f, 0.0f,


-1.0f,-1.0f, 1.0f,


1.0f,-1.0f, 1.0f,





0.0f, 1.0f, 0.0f,


1.0f,-1.0f, 1.0f,


1.0f,-1.0f,-1.0f,





0.0f, 1.0f, 0.0f,


1.0f,-1.0f,-1.0f,


-1.0f,-1.0f,-1.0f,





0.0f, 1.0f, 0.0f,


-1.0f,-1.0f,-1.0f,


-1.0f,-1.0f, 1.0f


};

// Golden Triangle color array
Private float [] mColorArray = {


1.0f, 0.0f, 0.0f, 1.0f,


0.0f, 1.0f, 0.0f, 1.0f,


0.0f, 0.0f, 1.0f, 1.0f,





1.0f, 0.0f, 0.0f, 1.0f,


0.0f, 0.0f, 1.0f, 1.0f,


0.0f, 1.0f, 0.0f, 1.0f,





1.0f, 0.0f, 0.0f, 1.0f,


0.0f, 1.0f, 0.0f, 1.0f,


0.0f, 0.0f, 1.0f, 1.0f,





1.0f, 0.0f, 0.0f, 1.0f,


0.0f, 0.0f, 1.0f, 1.0f,


0.0f, 1.0f, 0.0f, 1.0f,


};

Then, when plotting, put gl. glDrawArrays (GL10.GL _ TRIANGLES, 0, 12 );

The last parameter of this method is changed to 12 because it is drawn using 12 vertices.



This is to draw a golden triangle, and draw a rectangle, which is a little different from this, etc. The horse went to work and waited for two days to study.

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.