I don’t have any code that does this but this is the algorithm I would use:
Keep a list of vertices and a flag that when set to true draws the polygon with GL_POLYGON. Use a polygon mode of GL_FILL for a solid polygon or GL_LINE for the outline of a polygon.
In your init function:
set the flag to false
set the polygon mode to GL_LINE or GL_FILL
In your mouse function:
if the user clicks the left button:
add a vert to the list
if the user clicks the right button:
set the flag to true
In your display function:
if the flag is true:
draw the polygon with GL_POLYGON
To keep things simple you’ll probably want to use a 2-D orthographic projection, and remember that for many operations OpenGL is happier if you pass it the verteces in counterclockwise order. Sorry I don’t have code for you, but chapters 2 & 3 of the OpenGL Programming Guide (The Red Book) cover what you need to know.