Reading Clicked Pixel Colors

Hay There,
Clearly I need to start my post with … I am new to OpenGl :wink:
I am trying to implement a way to color objects interactively, I mean there are squares that have the colors and the user picks a color to color a drawing something similar to what we can do with paint.
I have been reading a lot about picking but i am not able to grasp the whole idea yet… I know it can help and my idea is to pick the color of a pixel clicked if it is not white I would save it in a variable and when a white pixel is selected from the drawing I would fill this region with this selected color … I can’t find a simple example to guide me …
What I have come to is that I can use this method to pick the color of the pixel:
void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);

But the color it returns is the clear color… According to what I read I guess this means that I am not reading the pixel from the back buffer. I am trying to understand the code from this link:
http://www.lighthouse3d.com/opengl/picking/index.php3?color2

But I can’t put my hands on what I actually need for my code and frankly I can’t understand most of the code as I am in the beginning of my opengl course and these are just my first attempts in opengl :slight_smile:

So can anyone guide me to what I need to be looking for or a simple link that can help ??

Thanks for your time =)

You need to make sure you call glReadPixels AFTER you’ve drawn your squares to the backbuffer.

… and before swapbuffers.