Coloring: Jeff Molofee (Nehe) OpenGL Tutorial - Third Lesson

zhaozj2021-02-08  258

Jeff Molofee (nehe) OpenGL Tutorial Third lesson Translated by CKER I taught you to draw your triangle and quadrilateral drawing method. I will teach you to add 2 different types of coloring methods to triangles and quadramograms. 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 Drawglscene routine of the last class. The entire routine will be overwhered over. If you plan to modify the code of the previous class, just override the original DrawGlscene () with the following code. INT Drawglscene (GLVOID) // This process includes all draw code {glclear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the screen and depth cache GLLoadIndIndentity (); // Reset model observation matrix GLTranslateF (-1.5F, 0.0F, -6.0F); // Left shift 1.5 unit, and move into the screen 6.0 glbegin (GL_TRIANGLES); // Draw a triangle If you still remember the content of the previous class, this code draws a triangle on the left half of the screen. The next line of code is our first use of the command Glcolor3f (R, G, B). The three parameters in parentheses are red, green, and blue three-color components. The range range can range from 0, 0f to 1.0f. Similar to the previously described clear screen background command. We set the color to red (pure red, no green, no blue). The next row code sets the first vertex of the triangle (triangular top point) and draws with the current color (red). From now on, the color of all drawing objects is red until we change red to other colors. Glcolor3f (1.0F, 0.0F, 0.0F); // Set the current color to red GlvertEX3F (0.0F, 1.0F, 0.0F); // The first red vertex in the top is already set. Next we set the second green vertex. The top left vertex of the triangle is set to green. Glcolor3f (0.0F, 1.0F, 0.0F); // Set the current color to green glvertex3f (-1.0F, -1.0F, 0.0F); // Now set the third one is the last vertex. Set the color to blue before starting to draw. This will be the top right vertex of the triangle. After glend (), the triangle will be filled. However, because each vertex has different colors, it looks from ejecting from each corner and just in the center of the triangle, three colors are mixed with each other. This is smooth coloring. Glcolor3f (0.0F, 0.0F, 1.0F); // Set the current color to blue glvertex3f (1.0F, -1.0F, 0.0F); // Right lower glend (); // Triangle Draw End GLTranslateF (3.0f , 0.0F, 0.0F); // Right shift 3 units Now we draw a monotonous colored - blue 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 uses colors. Even when the texture map is completely used, GLCOLOR3F can still be used to adjust the tones of the texture. Wait ...., let's talk later. We must do what we need to set the color to the color we want (this example is blue), then draw the scene. Each vertex is blue because we didn't tell OpenGL to change the color of the vertex. The final result is ..... full-blue square. Besides, the square plotted in the clockwise means that we see the back of the quadrangular shape.

Glcolor3f (0.5F, 0.5F, 1.0F); // Disposable When the current color is set to blue glbegin (GL_QUADS); // Draw square GlvertEX3F (-1.0F, 1.0F, 0.0F); // On the left GlvertEX3F ( 1.0F, 1.0F, 0.0F); // On the upper right glvertex3f (1.0F, -1.0F, 0.0F); // The lower left GlvertEX3F (-1.0F, -1.0F, 0.0F); // Right glend () ; / / Square Draw End Return true; // Continue to run} Last to the title of the window mode. IF (Keys [vk_f1]) // F1 button presses? {keys [vk_f1] = false; // Fullscreen; / / Switch full screen / window mode // Rebuild the OpenGL window (Modify) if (! CreateGLWindow ("Nehe's Color Tutorial", 640, 480, 16, fullscreen) {return 0; // If the window is not created, the program exits In this lesson, I tried to explain how to explain how to add monotonic and smooth coloring effects for your OpenGL polygon. Changing the red green zone in the code to see what the last y is. If you have any comments or suggestions, please give me email. If you think there is something wrong or improve, please tell me. I want to be the best OpenGL tutorial and interested in your feedback. {Translator: NEHE's document seems very simple, it seems very much. But if you want to come to such a master, have you seen a few? Or that sentence, I am not a master, I hope you are sincere. } The following is the source code download link.

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

New Post(0)