Pixel outlaw,
man thats a tough question. Basically what you want is called painters algorithm or sometimes depth sorting. To do a really good, foolproof job is tough coding. Have a look at painters algorithm on wiki to understand how tough this can get with mutual overlapping polygons.
So, what you need to do instead is work out if you can live with an approximation.
Maybe shockwave or one of the software poly render guys can give you better advice but essentially this is a HARD problem. OK heres a first example. This assumes most of your polygons are the same size and dont mutually overlap.
For each polygon you will draw pre-calculate a centre point and store this in an array. Also store an index for the polygon. When you draw this frame, transform the array of centre points by hand (ie not using opengl). Then sort this array on Z, being careful to also sort the index.
Now draw your real polygons in the correct order using the index.
This will not work in all circumstances.
http://www.sjbaker.org/steve/omniv/alpha_sorting.htmlAlpha polygons is the main reason most games writers dont rely on the transform pipeline of the hardware but do it themselves.
You might be able to do better, if you can live with some "artefacts". You say you have polyhedra. If they are convex polyhedra, what you could do is this:
- only draw front facing polygons
- sort centres of polyhedra (not polygons).
Still a lot of code but much faster.
Chris