Want to read pixels of 3D image into array

I have created a 3D image from several ellipsoids; now I want to read pixel values into a 3 x n memory array, modify pixel values, and redisplay as a modified 3D image. glReadPixels only reads 2D rectangle. Is there some other way to do this?

Only if you do it yourself, OpenGL transform the 3D data into a 2D image and there is never any 3D pixel data (xyz) available at any stage.

Mikael

You can use glReadPixels to get pixel data from the z-buffer, but that will only get you the z-value of the frontmost pixels, which is probably not what you want.

Although I suppose if you repeatedly sliced through the scene in both directions using a user clipping plane (or stepping the camera through the object and using the near clipping plane) you could reconstruct your 3D array from those slices.

But it would be complex to reconstruct, and since the z-buffer is usually non-linear, you’d still need to find a suitable formula to convert the z-buffer values to linear ones.

Its probably not much use (becauase it doesnt work properly…) but if you look at my post here -

http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=2;t=018595

It shows how to use glreadpixels and glulookat to get the values, as I say it doesnt work, and i cant get it to work, but you might be able to (tell me if you do!)

cheers

Dave

Thanks to everyone for their advice. I’ve decided to set up a clipping plane and advance it from -z to +z a slice at a time. This allows me to read the pixel values for each slice.
I have one other problem. Think of an egg. During the first couple of slices, I should only see the white of the egg until I get to the location of the yolk, and then I should see yolk surrounded by egg white. But I don’t.
The sphere is hollow. When I take the first slice, I see egg yolk. How do I get a solid sphere?