Original Basic OpenGL Tutorial (i) Polygon drawing

Source: Internet
Author: User

1. OpenGL development Environment Construction Reference http://brothergrup.iteye.com/blog/1602471

2. Fill the color of the triangle:

The Fill color function for Glcolor (3/4) * (R,G,B) 3 or 4 means that the numeric type rgb/rgba;* represents Rgba (B,i.) will eventually be mapped to [0-1].

How to map is to take the value of the Write/current type maximum value such as Byte is -128~127 glcolor3b (1,0,0) equivalent to glcolor3f (1/127f,0,0) less than 0 when 0 processing

void Renderscene (void)
{
........

Each vertex is assigned a value of red
glvertex3f ( -0.5,-0.5,0.0);
GLCOLOR3B (127,0,0);

glvertex3f (0.5,0.0,0.0);
GLCOLOR3B (127,0,0);

glvertex3f (0.0,0.5,0.0);
GLCOLOR3B (127,0,0);
..........
}

3. Draw Quadrilateral

Note Four vertices are drawn in order, clockwise or counterclockwise when you select Quad mode.

void Renderscene (void)
{
Glbegin (gl_quads); Quadrilateral Pattern Drawing

glvertex3f ( -0.5,-0.5,0.0);
glcolor3f (1.0,0,0);

glvertex3f (0.5,-0.5,0.0);
glcolor3f (1.0,0,0);

glvertex3f (0.5,0.5,0.0);
glcolor3f (1.0,0,0);

glvertex3f ( -0.5,0.5,0.0);
glcolor3f (1.0,0,0);

Glend ();
}

If the order of 3,4 vertices is reversed, chaos occurs.

(2) Draw quadrilateral when drawing mode is triangular

Next article about drawing polygons using an indexed method

Original Basic OpenGL Tutorial (i) Polygon drawing

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.