为什么Alpha混合在正交中不起作用? [英] Why doesn't alpha blending work in ortho?

查看:120
本文介绍了为什么Alpha混合在正交中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是绘制3D对象后打开正交投影的方式:

This is how I turn on ortho projection after drawing 3D objects:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,Screen_Width,Screen_Height,0,0,1);

这是我在绘制3D对象后打开混合并在正交中绘制纹理的方式:

And this is how I turn on blending and draw textures in ortho after drawing 3D objects:

glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 
glColor4f(1,1,1,1);

glBindTexture(GL_TEXTURE_2D,Texture1);
glBegin(GL_QUADS);
//draw 1st quad
glEnd();

glBindTexture(GL_TEXTURE_2D,Texture2);
glBegin(GL_QUADS);
//draw 2nd quad
glEnd();

glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);

Quad1比Quad2大一点,并且涵盖了Quad2的某些部分。

Quad1 is a bit larger than Quad2 and covers some parts of Quad2. Both textures have alpha channel as RGBA.

问题是Quad1& Quad2正确地将3D对象与alpha重叠,但是Quad1的alpha在Quad2顶部时不起作用。

The problem is, Quad1 & Quad2 overlay the 3D objects with alpha correctly, but the alpha of Quad1 doesn't work when being on top of Quad2. It draws on top of Quad2 like RGB only.

如何解决此问题?

推荐答案

是否启用深度缓冲?如果是这样,则可能导致片段被丢弃(未通过Z测试),而不是与已经存在的片段进行alpha混合。

Is depth buffering enabled? If it is, that could cause fragments to be discarded (failing the Z test) instead of alpha-blended with what's already there.

如果您使用深度缓冲区,您需要以从后到前的顺序绘制透明对象。

If you're using a depth buffer, you need to draw transparent objects in back-to-front order.

对于纯2D场景,您可能甚至不需要深度缓冲区,只需打开

For a purely 2D scene, you might not even need a depth buffer, and you can just turn it off:

glDisable(GL_DEPTH_TEST);

这篇关于为什么Alpha混合在正交中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆