gluUnProject() - glReadPixels()

I get really strange values when I do my projection with gluUnProject.

One is supposed to put the screen coordinates as in-parameter to gluUnProject. Is it so easy that I can take the x/y values from the mouseevent I receive with a mouse click and use them as screen coordinates, what do I do with the z-coordinate?? I´ve read that one should use glReadPixels. But I don´t manage that…

some code:
GLdouble modelviewMatrix[16];
GLdouble projectionMatrix[16];
GLint viewport[4];
GLdouble winx,winy,winz;
GLdouble objx, objy, objz;
GLvoid* depth = 0; // is this right???

int x,y;
float z;
z = 0;

winx = (GLdouble) x;
winy = (GLdouble) 250-y; // window height - y
// get the z-value
//z = (float) *depth; // right???
winz = (GLdouble) z;

// here we should get the object coordinates from the screen coordinates
glGetDoublev(GL_MODELVIEW_MATRIX, modelviewMatrix);
glGetDoublev(GL_PROJECTION_MATRIX , projectionMatrix);


// the object coordinates are now stored in objx/y/z


Not sure but try

float depth;

I think that should be enough
the other option is

float depth[0];

You must define the size of the pointer, I don’t think you did that, but I never looked too hard.