NEHE OpenGL Tutorial Delphi Edition (3) ---- Coloring

zhaozj2021-02-16  44

carry on

In the previous section, I taught you a drawing method of triangle and quadrilateral. This section will teach you to add 2 different types of coloring methods to triangles and quadrangularities. Use Flat Coloring to give a fixed color to the quadrilateral coating. Use Smooth Coloring to mix different colors of the three vertices of the triangle together to create a beautiful color mix.

Continue to modify on the GLDRAW of the previous section.

Procedure gldraw (); begin glclear (gl_color_buffer_bit or gl_depth_buffer_bit); // Clear the screen and depth cache GLLoadIdentity (); // Reset the current model observation matrix

Gltranslatef (-1.5, 0.0, -6.0); // Left shift 1.5 unit, and move into the screen 6.0

Glbegin (GL_TRIANGLES); // Draw triangles

// Glcolor3f (r, g, b). The three parameters in parentheses are red, green, and blue three-color components. // The range of values ​​can range from 0, 0 to 1.0. Similar to the previously described clear screen background command.

// We set the color to red (pure red, no green, no blue). // The next line of code sets the first vertex of the triangle (triangular top point), // and use the current color (red) to draw. From now on, all the color of the object is red, / / ​​until we change red to something else.

Glcolor3f (1.0, 0.0, 0.0); // Set the current color to red glvertex3f (0.0, 1.0, 0.0); // on top

// The first red vertex has been set up. // Next we set the second green vertex. The top left vertex of the triangle is set to green. Glcolor3f (0.0, 1.0, 0.0); // Sets the current colored GlvertEX3F (-1.0, -1.0, 0.0); // The lower right vertex of the upper left // triangle. After setting the color to blue // glend (), the triangle will be filled. / / However, because each vertex has different colors, it looks that the color is ejected from each corner, // and just in the center of the triangle, three colors are mixed with each other. This is smooth coloring. Glcolor3f (0.0, 0.0, 1.0); // Set the current color to blue glvertex3f (1.0, -1.0, 0.0); // Right

Glend (); // Triangle Drawing End GltranslateF (3.0, 0.0, 0.0); // Right 3 unit

// Now we draw a monotonic colored - purple square. // The most important thing is to remember that all the stuffs drawn after setting the current colors are current colors. // Each project you created later will use color. // Even when you use a texture map, // Glcolor3F can still be used to adjust the tones of the texture. // Wait ...., then let go. // (Oh, the original book is blue, but I like purple)

Glbegin (GL_QUADS); // Draw Square Glcolor3f (0.6, 0.2, 2.0); // Set the current color to purple Glvertex3f (-1.0, 1.0, 0.0); // on the left GlvertEx3f (1.0, 1.0, 0.0); // GlvertEX3F (1.0, -1.0, 0.0); // Left GlvertEx3f (-1.0, -1.0, 0.0); // Right down glend (); // Square Drawing End End; run a look

转载请注明原文地址:https://www.9cbs.com/read-25042.html

New Post(0)