简体   繁体   中英

How to fix alpha of stb_image library

I'm using stb_image.c for loading bytes of data to opengl. However, I'm struggling with one issue that happens to me, when I try to load png files with alpha channel 在此处输入图片说明

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

You are doing the Tom Dalling OpenGL tutorial? ^^

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. These are the parameters OpenGL seems to recommend in the documentation at least: glBlendFunc

Transparency is best implemented using blend function(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) with primitives sorted from farthest to nearest. Note that this transparency calculation does not require the presence of alpha bitplanes in the frame buffer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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