selection with a polygon region


I need to write a function for selecting a set of entities with a polygon region (given by the user) on the screen.
A guy who left the company wrote a selection by a normal rectangle, looking at the code I see he used the selection mechanism that is described in chapter 13 of red book, I have not used these functions but looks easy to follow, what I don’t know about is the polygon region part… I hear that stencil buffer is used in cases like this, but never used it too, and after reading the red book I get a vague idea of who it works, I would like to see if someone could give me some directions.

Thanks in advance.