I have a bunch of transparent overlapping/intersecting objects that I would like to render somewhat nicely. I’m not worrying about polygon splitting at this point, only sorting. I think I understand what I have to do pretty well conceptually, but I haven’t found a good way to implement it yet. I’m not worried about the actual sorting algorithm either, I’m using qsort for now but may switch to radix/bucket sort if I need to.
Here’s an overview of my latest attempt. I can post code if anyone wants me to.
- Turn on feedback mode… glRenderMode(GL_FEEDBACK);
- Render the scene like normal.
- Turn off feedback mode… n_values = glRenderMode(GL_RENDER);
- Parse the feedback buffer into a list of triangles.
- Sort the triangles from the feedback buffer.
- Set up an orthographic projection to mimic the screen.
- Render each triangle from the feedback buffer in order.
The nice thing about this way is that you can sort polygons drawn with immediate mode/display lists/whatever. You can also draw objects using different projections and not have to worry about switching projection matrices for every other polygon after they’re sorted. You also don’t need to call gluProject on every vertex.
This way seems to work pretty well when using GL_3D_COLOR for the feedback buffer, but I haven’t been able to get textures working correctly yet. For one thing, you need to switch textures, but I think you could pass the texture id with glPassThrough(). The other problem is that the textures aren’t projected correctly because they’re being rendered in an orthographic projection… I’m not sure how to get around this problem, or if it’s even possible.
I’ve thought about using a vertex/fragment shader, or using a texture matrix, but I’m not experienced enough with OpenGL to know if either of those will work, or if they will, how to do it. Any suggestions?