Alpha channel with DXT5 compressed texture
-
21-04-2021 - |
Question
I've written a test program using OpenGL on OS X that loads a PNG, compresses it in memory to DXT5 using libsquish (http://code.google.com/p/libsquish/), and textures a plane.
When I upload an image that contains an alpha channel, but no pixels have alpha values other than fully opaque, it displays correctly: http://i.imgur.com/nElZ8.png
Given the same image but the black part is replaced with transparency, this is the output I get: http://i.imgur.com/8Ld3y.png
The code is not pretty, it is a thrown together proof of concept:
- The C++ source: http://pastebin.com/m0RqpgUS
- The vertex shader: http://pastebin.com/QyaWCaTk
- The fragment shader: http://pastebin.com/KEuFJ83C
- The test images: http://dl.dropbox.com/u/4597377/images.zip
Any thoughts?
Solution
Turns out I forgot this:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow