Skip to main content
GameDev.net gamedev.net
🔒 Locked

gradient

Started by Lode Jan 6, 2005 at 5:36 PM 2 replies 600+ views
Original Post
Lode
Lode
I'm drawing a rectangle like this:

    glBegin(GL_QUADS);
      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);
    glEnd();
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):

    glShadeModel(GL_FLAT);
    glCullFace(GL_BACK);
    glFrontFace(GL_CCW);
    glClearColor(0, 0, 0, 0);
    glViewport(0, 0, screenWidth, screenHeight);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, screenWidth, 0, screenHeight, -1024, 1024);   

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glDisable(GL_TEXTURE_2D);
Brother Bob
Brother Bob
Quote:

glShadeModel(GL_FLAT);

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.
Brother Bob
Brother Bob
Quote:
Original post by HopeDagger
Edit: Beaten by 31 seconds. Grah. ;)

[totally]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.