OpenGL中的透明纹理 [英] Transparent texture in OpenGL

查看:1195
本文介绍了OpenGL中的透明纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好吧

我有一个四边形纹理。但它的图片是透明的。 OpenGL显示如下:



http:// upload。 tehran98.com/img1/roc36xty7n84mavubhzj.png [ ^ ]



我该怎么办? (我使用sdl)

推荐答案

在OpenGL纹理映射中,透明度可以通过alpha混合实现。您可以使用GL_RGBA8纹理格式来创建启用Alpha的纹理。提供适当的alpha值以获得透明度。要获得不透明的图像,请提供255作为alpha值,并获得完全透明的像素,将0提供为alpha值。对于半透明像素,提供128作为alpha值。



纹理贴图启用混合以获得对绘制图像的透明效果。



In OpenGL texture mapping, Transparency can be implemented through alpha blending. You can use GL_RGBA8 texture format to create Alpha enabled texture. Provide proper alpha values to get transparency. To get get opaque image, provide 255 as alpha value and to get fully transparent pixel provide 0 as alpha value. For semi-transparent pixels provide 128 as the alpha value.

On texture mapping enable blending to get transparent effect to the drawn image.

// This function render the image with alpha blending to display only the alpha pixels.
    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
// Texture mapping code... 
// On drawing texture image, color of texel will be multiplied with the existing image.
// and it will provide transparent effect.


这篇关于OpenGL中的透明纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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