OpenGL Learning Chapter II

Source: Internet
Author: User

OpenGL graphics Basic Drawing, it is beginning from the plane to think three-dimensional transfer, now draw a golden Triangle appearance, in fact, the main or fixed-point array of problems, gl10.gl_triangles the main role of this parameter,

Gl_triangles-This parameter means that theOpenGLuse three vertices to compose a graph. So, at the beginning of the three vertices, the vertices will be used1, Vertex2, Vertex3to form a triangle. When finished, the triangle is formed using the next set of three vertices until the end of the array.

So we can use this to draw a golden Triangle, the code is actually not much change, just the vertex array changes:


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 put gl.gldrawarrays (gl10.gl_triangles, 0, 12) at the time of drawing;

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



This is to draw a golden triangle, and draw a rectangle, that is a little different from this and so on, immediately off work, and so on two days in the study

OpenGL Learning Chapter II

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.