0

I am currently working on a Graphics Engine for a 2D game with OpenGL, but I have issues implementing a viable solution for partial transparency, since opaque objects need to be drawn first, and transparent objects from back to front.

Specifically, I want to be able to pass render commands in an arbitrary order, and let the Engine handle the sorting.

My current approach is that I simply collect all vertices and textures of each transparent object in a sorted list, and at the and of each frame, I simply draw them from this list.

Although I get correct results, this is obviously not a viable solution, due to a lot of copy instructions. In case I have a few thousand partially transparent particles, this approach does not work at all due to its low performance.

I did not find any other way to implement this for 2D Graphics, so my question is: What is the most common approach to this ? Are there any sources where I can read more about this topic?

I use glBlendFunc(GL_SOURCE_ALPHA, GL_ONE_MINUS_SRC_ALPHA) by the way.

  • 2
    For a 2D game managing depth / rendering order is generally easier (e.g., using layers and controlled rendering order by layer). 3D game engines usually use some version of BSP tree for the bulk of the geometry which automatically allows one to render front-to-back (or vice versa). – wcochran Jul 04 '20 at 20:04
  • see [OpenGL - How to create Order Independent transparency?](https://stackoverflow.com/a/37783085/2521214) do not forget to check also the links in `Zouch` answer too – Spektre Jul 05 '20 at 07:41

0 Answers0