PF_RGB -> PF_A8 -> GL_ALPHA
BlitzMax Forums/BlitzMax Programming/PF_RGB -> PF_A8 -> GL_ALPHA
| ||
I want to load a pixmap in any format, convert the pixels to an PF_A8 alpha map, based on pixel brightness, and then create a GL_ALPHA texture from that. Can someone explain how this works? Thank you. PF_RGBA8888 -> PF_A8 -> GL_ALPHA does work, BTW, so it seems the faulty step is in converting RGB888 and I8 to A8. |
| ||
Here's what you have to do. Just watch out for the following conversions that contain no alpha:If pixmap.format=PF_RGB888 Or pixmap.format=PF_BGR888 Or pixmap.format=PF_I8 alphamap:TPixmap=CreatePixmap(pixmap.width,pixmap.height,PF_A8) For x=0 To pixmap.width-1 For y=0 To pixmap.width-1 color=ReadPixel(pixmap,x,y) r=(ReadPixel(pixmap,x,y) & %11111111) WritePixel alphamap,x,y,(r Shl 24) Next Next pixmap=alphamap EndIf |
| ||
I usually take one of the channels and use it as the alpha channel. Otherwise you probably should properly do a grayscale conversion from color to grayscale and then use that as alpha. |