PDA

View Full Version : Gradient line



paleajed
08-09-2013, 06:59 AM
I am trying to draw a gradient line.

This does not work:

glBegin(GL_LINES)
glColor3f(r, g, b)
glVertex2f(x, y)
glColor3f(r2, g2, b2)
glVertex2f(x2, y2)
glEnd()

Any other method for getting a smooth gradient?

Carmine
08-09-2013, 11:02 AM
Need more info. 'This does not work' is a little vague.
What happens when you run this? Do you see anything?
If so, what do you see? Can you post a picture?

Hugo_the_Dwarf
08-09-2013, 02:24 PM
well you're just drawing a line from left to right, hard to see a 1 pixel long line. try a GL_TRIANGLE or GL_QUADS instead of GL_LINES so


glBegin(GL_QUADS)
glColor3f(r, g, b)
glVertex2f(x, y) //Top Left
glColor3f(r2, g2, b2)
glVertex2f(x2, y2)//Top Right
glColor3f(r2, g2, b2)
glVertex2f(x2, y + 20) //Bottom right
glColor3f(r, g, b)
glVertex2f(x, y2 + 20)//Bottom Left
glEnd()

if the gradient works, then you can go back to GL_LINES (since now you know it work, just hard to see)
Note I did not test this code. So take it with a grain of salt.

paleajed
08-09-2013, 04:36 PM
When using both my example code and hugo_the_dwarfs the line/quad is drawn solid in the last set glColor3f...

GClements
08-09-2013, 06:26 PM
When using both my example code and hugo_the_dwarfs the line/quad is drawn solid in the last set glColor3f...

That suggests that glShadeModel(GL_FLAT) is in effect. Use glShadeModel(GL_SMOOTH) to change it back.

paleajed
08-09-2013, 06:33 PM
Thank you very much, this was indeed the problem!