简体   繁体   English

如何修复stb_image库的Alpha

[英]How to fix alpha of stb_image library

I'm using stb_image.c for loading bytes of data to opengl. 我正在使用stb_image.c将数据字节加载到opengl。 However, I'm struggling with one issue that happens to me, when I try to load png files with alpha channel 但是,当我尝试通过Alpha通道加载png文件时,我正遇到一个发生的问题 在此处输入图片说明

Now the white area should be the transparent one, though it cleared only the little part of it. 现在,白色区域应该是透明区域,尽管它只清除了其中的一小部分。 Any ideas what is causing this behavior? 任何想法是什么导致这种行为?

在此处输入图片说明

The photoshop histogram Photoshop直方图

You are doing the Tom Dalling OpenGL tutorial? 您正在做Tom Dalling OpenGL教程吗? ^^ ^^

I don't know if you are still searching for a solution to this but here I go anyways: I actually had the same problem as I was working through that lesson but it worked for me by using glBlendFunc with sfactor GL_SRC_ALPHA and dfactor GL_ONE_MINUS_SRC_ALPHA. 我不知道您是否仍在寻找解决方案,但是无论如何,我还是走了:我实际上遇到了与上一课相同的问题,但是通过将glBlendFunc与sfactor GL_SRC_ALPHA和dfactor GL_ONE_MINUS_SRC_ALPHA一起使用对我来说是有效的。 These are the parameters OpenGL seems to recommend in the documentation at least: glBlendFunc 这些是OpenGL似乎至少在文档中建议的参数: glBlendFunc

Transparency is best implemented using blend function(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) with primitives sorted from farthest to nearest. 最好使用混合函数(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)以及从最远到最近排序的基元来实现透明度。 Note that this transparency calculation does not require the presence of alpha bitplanes in the frame buffer. 请注意,此透明度计算不需要在帧缓冲区中存在alpha位平面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM