how to select a rectangle with mouse

I have 2 blue rectangles drawn with gl_line_loop.
if I click one of them with mouse I want it to be red. So an object selection problem.
I use ortho projection.

if you could give some sample code it would be very helpful.
Since I m extremely newbie, if you mention where should I put the code(mousedown,render?) it will would be nice for me.
Thanks for help.regards

Hi !

Here is one example that use GLUT:

There are lots of others, give google a quick search and you will get lots of examples.