开发者

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);

I开发者_如何学Gos 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜