about filling colors to a polygon

hi
I am new to opengl and I am trying to fill color to a polygon.
I want to give separate color to outline of polygon and another solid color inside polygon.
i found glcolor() function where it fills total area with only one color.

can anybody guide me on this issue?
please send me the sample code if any.

thank you

Hi,

After your polygon rendering, you’ll need to redraw your vertices but as a GL_LINE_LOOP,instead of GL_POLYGON in order to draw the outline. You could also glDisable(GL_DEPTH_TEST) in order to overwrite the edges for sure.

in a nutshell :

glColor(solid_color)
glBegin(GL_POLYGON)
glVertex Commands here
glEnd
glDisable(GL_DEPTH_TEST)
glColor(outline_color)
glBegin(GL_LINE_LOOP)
glVertex Commands here
glEnd
glEnable(GL_DEPTH_TEST)

Or you could use glPolygonMode, where you change mode to GL_LINE, draw polygon normally, & change back to GL_FILL, instead of that line loop.

thank you for ur quick reply.

i have one more question.
can i fill one color to one side of a line and another for other side?

Mmm I didn’t get this one, on the same line 2 different colours? if this is the case, well, you should render the lines twice by offseting each one by a tiny bit along the lines’ ‘normal’ vectors (positive & negative direction,for outwards & inwards to the poly).

Or if you mean to interpolate colour from one point of the line to the other, just specify a colour for each vertex inside glBegin/ glEnd og the GL_LINE_LOOP.
& if you want interpolation of the colours across the lines, be sure to specify glShadeModel(GL_SMOOTH)