Auto texture map for arbitrary object.

How to automaticaly map a 2D texture to an object consisted of arbitrary number of polygons when you dont have a mapping of texture coords to polygons vertex coords?

if you dont want to generate them yourself, you can use glTexGen. It has a few modes how it will create the coordinates and you can specify some planes yourself.

Thats the trouble Ive encountered.
I cant properly do it, for example quadrics does it perfectly (sphere, cylinder etc. texture automaticaly applyed evenly and perfect).
I have also for example some kind of object (a shere or box like or something) and Ive done right with 1D texture auto generation but in case for 2D texture I enable both GL_S and GL_T coords but it doesnt fit properly, like it remains generating only for one coordinate?
Can anyone share a proper code snippet? pls.