纹理与透明背景通过使用alpha混合opengl [英] textures with transparent background by using alpha blending opengl

查看:443
本文介绍了纹理与透明背景通过使用alpha混合opengl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有疤痕纹理,我想通过使用alpha混合去掉背景肤色。但是,我有改变特定纹理的单个像素的不透明度的问题。有透明背景纹理的最简单的方法是什么?我使用的是C ++和openGL。

I have scar textures and I want to get rid of the background skin colour by using alpha blending. However, I have problems with changing the opacity of individual pixels of specific textures. What is the easiest way to have textures with transparent background? I am using C++ and openGL.

我使用的是BMP图片格式,我试图将疤痕纹理映射到脸上,但是疤痕纹理的背景颜色看起来很丑面部,所以我想删除那部分,只有疤痕纹理映射到脸上。我还需要通过使用alpha混合来做到这一点。我知道我需要使用混合函数:

I am using a BMP picture format and I am trying to map that scar texture onto the face but background colour of scar texture seems ugly on the face, so I want to remove that part and have only scar texture mapped onto the face. I also need to do this by using alpha blending. I know that I need to use blend function:

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

如何更改每个纹理的透明度?

How I can change transparency for each texture?

推荐答案

这听起来像是想从sprites中删除背景。如果是这样的情况下,然后使用一个程序称为gimp,然后模糊选择背景和删除,然后导出和关闭它,但是当它要求在导出期间保存说否。 Google Gimp和背景编辑,您将看到所需的信息和工具。

It sounds like you want to remove backgrounds from sprites. If that's the case then use a program called gimp and then fuzzy select the background and delete then export it and close it but when it asks to save during export say no. Google gimp and background edit and you'll see the info and tools needed.

glBlendFunc (GL_ONE, GL_ONE); 

您可能想使用混合函数中纹理映射产生的alpha值。如果是这样,(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)始终是一个很好的开始函数。

You might want to use the alpha values that result from texture mapping in the blend function. If so, (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) is always a good function to start with.

然而,如果你想混合发生时基元是纹理映射想要纹理贴图的部分允许基本的底层颜色显示通过),那么不要使用OpenGL混合。相反,您可以使用glTexEnv(),并将纹理环境模式设置为GL_BLEND。在这种情况下,您希望将纹理环境颜色保留为默认值(0,0,0,0)。

However, if you want blending to occur when the primitive is texture mapped (i.e., you want parts of the texture map to allow the underlying color of the primitive to show through), then don't use OpenGL blending. Instead, you'd use glTexEnv(), and set the texture environment mode to GL_BLEND. In this case, you'd want to leave the texture environment color to its default value of (0,0,0,0).

这将更容易设置颜色设置为(1,1,1,1)并使用默认的GL_MODULATE。此外,您只能在glBegin()和glEnd之间使用某些命令,因此只能使用glTexCoord glColor glVertex和其他类似的命令。所以使用一个glBegin()/ glEnd()组合作为背景,然后更改设置,然后使用另一个glBegin()/ glEnd()来绘制精灵。

It would be easier to set the Color to (1,1,1,1) and use the default GL_MODULATE. Also You are only allowed to use certain commands between glBegin() and glEnd, so use only glTexCoord glColor glVertex and other similar commands. So use one glBegin()/glEnd() combo for the background, then change the settings and then use another glBegin()/glEnd() to draw the sprite.

这篇关于纹理与透明背景通过使用alpha混合opengl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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