In OpenGL, the best way is probably to render to a texture. There are different ways to do it, but the easiest is to use glCopyTexImage. Search for that phrase on google and you'll find plenty of detailed tutorials to help you through. glCopyTexImage can unfortunately be rather slow, so if speed is of critical importance you might want to use frame-buffer objects instead (FBO's), but that's a lot more complicated. My advice is to use glCopyTexImage and later switch to FBO's if your application turns out to be too slow.

The mathematical way is probably going to be very messy unless your surface can be expressed as a three-dimensional function, which is probably not the case. If you have, for example, a grid of deformed quads, I'm afraid your problem is a bit tougher than I can give any solid advice on straight away (other than the render to texture solution).