Advertisement Jump to content
Sign in to follow this  

OpenGL gradient

This topic is 5129 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm drawing a rectangle like this:
      glColor4f(color1.r / 255.0, color1.g / 255.0, color1.b / 255.0, color1.a / 255.0);
      glVertex3d(x2, h - y1, 1);
      glColor4f(color2.r / 255.0, color2.g / 255.0, color2.b / 255.0, color2.a / 255.0);
      glVertex3d(x1, h - y1, 1);
      glColor4f(color3.r / 255.0, color3.g / 255.0, color3.b / 255.0, color3.a / 255.0);
      glVertex3d(x1, h - y2, 1);
      glColor4f(color4.r / 255.0, color4.g / 255.0, color4.b / 255.0, color4.a / 255.0);
      glVertex3d(x2, h - y2, 1);
I expected every corner of the rectangle would have another color (see, there's color1, color2, color3 and color4), but it doesn't work: instead, the whole rectangle has color4. What is it supposed to do? In the nehe tutorials, it works for the triangle with blue, red and green corners... Before drawing the rectangle, I already do the following OpenGL commands (It's a 2D engine btw):
    glClearColor(0, 0, 0, 0);
    glViewport(0, 0, screenWidth, screenHeight);
    glOrtho(0, screenWidth, 0, screenHeight, -1024, 1024);   


Share this post

Link to post
Share on other sites


Should be GL_SMOOTH if you want smooth shading. When using flat shading, the color that was current when the primitive was completed is the color that is used for rendering. In your case, color4 was the current color when the fourth vertex formed a complete quad.

Share this post

Link to post
Share on other sites
Original post by Lode

You'll want to use GL_SMOOTH, since the flat shading model doesn't use interpolated colours.

Edit: Beaten by 31 seconds. Grah. ;)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!