简体   繁体   中英

Best way to do alpha blending with OpenGL?

I'm drawing 2D Polygons, actually I'm drawing lots of triangles and using GLUOrtho2D. I noticed that by zooming out I got much better frame rates. I realized I was maxing out the graphics card's fill rate, not drawing too many polygons as I had initially suspected. I think this is because I'm drawing lots of overlapping polygons and using

glEnable(GL_BLEND);

    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Is this the blend function I should be using? How could I minimize the filling given the nature of what I'm doing? I tried enabling the GL_DEPTH_TEST and Z ordered my polygons, but since I alpha blend, this won't help. What is the most efficient way of doing this sort of thing?

Thanks

I doubt using a different blend function would help. One generally chooses the correct blend function based on desired output, not performance.

Are all the polygons you render transparent/translucent? If not, it might help to separate the rendering of those apart from the opaque polygons you have and set the proper GL states accordingly.

Also are these textured polygons? You might be able to optimize your texture handling (ex: reduce context switches, use more efficient image formats, etc).

Finally, how are you rendering these triangles? If in immediate mode or using vertex arrays, consider using VBOs.

avoid alpha blending on as many triangles as possible. It adds up and yes, it gets really expensive. There is no magic high-performance blend function.

The only solution is "use less blending and more z-buffering"

Changing blend function leads only to changes in blending coefficients, but not in equation. Anyways, modern videocards do not use hardcoded equations. You could try to write a pixel shader that satisfies your needs.

BTW, consider using VBO 's for yours "lots of triangles" if you still don't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM