[英]Drawing with transparent texture, then opaque color
I initialize OpenGL like so to make transparent textures transparent: 我像这样初始化OpenGL,以使透明纹理透明:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
I draw my texture like this: 我这样画我的纹理:
glPushMatrix();
//translate
//neutralize colors
//bind texture
//vertex points
glPopMatrix();
But when I try to draw a quad immediately afterwards, it won't show up: 但是当我尝试之后立即绘制四边形时,它不会显示:
glPushMatrix();
{
glTranslatef(x, y, 0);
glColor3f(1f, 0f, 0f);
glBegin(GL_QUADS);
{
glVertex2f(0, 0);
glVertex2f(10, 0);
glVertex2f(10, 10);
glVertex2f(0, 10);
}
glEnd();
}
glPopMatrix();
If I remove the initialization above, the quad appears, but then my texture is no longer transparent. 如果删除上面的初始化,将显示四边形,但是纹理不再透明。
What am I doing wrong here? 我在这里做错了什么?
Edit: Should I call glDisable(GL_BLEND);
编辑:我应该调用glDisable(GL_BLEND);
whenever I want to draw something that is not a texture? 每当我想绘制不是纹理的东西时?
You need to disable blending before drawing your quad. 您需要在绘制四边形之前禁用混合。
EDIT: Can you post more code? 编辑:您可以发布更多代码吗? The problem may be somewhere else, for example if you have not disabled the texture before drawing the quads. 问题可能出在其他地方,例如,如果您在绘制四边形之前尚未禁用纹理。
There's no need to disable blending when drawing. 有没有必要禁用绘制时混合。
I call glBlendFunc(GL_SRC_ALPHA, GL_ONE)
when I need to draw transparent cubes (with texture). 当我需要绘制透明的立方体(带有纹理)时glBlendFunc(GL_SRC_ALPHA, GL_ONE)
我调用glBlendFunc(GL_SRC_ALPHA, GL_ONE)
)。
I usually disable DEPTH test upon drawing with blend mode enabled: 我通常在启用混合模式的绘图上禁用DEPTH测试:
glEnable(GL_BLEND); // Turn Blending On
glDisable(GL_DEPTH_TEST); // Turn Depth Testing Off
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.