   alpha problem
  HI,I'm getting the hang of loading and binding textures with alpha transparency. However, I've come across what I think is a well known problem with a well known solution.When I draw a quad, and bind it with a texture that has transparency, the transparent sections do not display the objects behind them correctly.For example, Supposing i first render a model of a hill with some rocks and stuff. None of this mesh contains any transparency.Then I render some trees; the trunks do not use transparency, but each branch is a single quad which is textured, and the opaque parts of the image makes up the leaves. The meshes for the ground and the rocks are drawn behind the trees, but the trees do not display correctly. The ones which were drawn last do not show behind the ones which were drawn first. Instead, they are over-written by a tree which was drawn after them.How do I solve this problem? I hear its something to do with the Z order of each polygon.   
  In order to use alpha blend, you need to reordering the object yourself. you can't  use z-order depth test. this is because of when the blend function is enable the blending object will use the current pixel at the time their drown. to calculate new color. so if that time your pixel isn't the correct one the color itself will be wrong.   ;  so... I need to look into a new internal mesh format? BSP perhaps?What I don't understand, is why does OpenGL not just leave the pixels how they were when the last object was rendered? Why is a pixel with no alpha transparency get overwritten by a pixel of a polygon which is BEHIND it in the z-order?[edit: technical errors];Quote:Original post by shotgunnutterso... I need to look into a new internal mesh format? BSP perhaps?What I don't understand, is why does OpenGL not just leave the pixels how they were when the last object was rendered? Why is a pixel with no alpha transparency get overwritten by a pixel of a polygon which is BEHIND it in the z-order?[edit: technical errors]The format does not have anything to do with ordering the polygons from the back to front. You just do it with a sorting algorithm.It should not be the case that a pixel of a polygon is getting overwritten by a pixel of a polygon which is behind which has alpha blending on. But that can be the case if you forgot to set off transparancy or you disabled depth testing.;  There are some methods to render things like grasse or leaves without sorting.1.Only use alpha testing: a fragment is discarded if it's alpha is below a certain threshold. This is quite fast and doesn't need depth sorting. The drawback are somewhat sharp and pixelized edges.2. Use alpha to coverage. Look here for an example.   ;  I tried your first suggestion and it worked perfectly. Too perfectly in fact. Surely it can't be that easy? Whats the catch of using alpha testing?Once I get my texture database system working I look forward to having alpha masked grass and stuff. My game design is a GTA3 clone, which I'm making for learning purposes, and using masked polygons will enable me to have a large city with a lot of details.So, thanks to everybody here who helped.;Quote:Original post by shotgunnutterWhats the catch of using alpha testing?On modern GPUs, alpha testing disables certain optimization : early zATI calls there tech hyper-Z or hierarchal Z and for sure, nVidia has a similar thing.Render these alpha test needing objects last so that the previous stuff benefit from early Z. To fully benefit, objects should be rendered front to back if they don't need transparency.You code should look like thisgClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFER_BIT);//Render non-transparent stuff, front to back. Perhaps do a rough sortRenderObjects1();//Render transparent stuff back to frontRenderObjects2();//Render the grass, fences, tree leaves//and now, things run slowerRenderObjects3();SwapBuffers();