Alpha Buffer with MaxGUI Canvas

BlitzMax Forums/BlitzMax Programming/Alpha Buffer with MaxGUI Canvas

Pete Rigz(Posted 2008) [#1]
Can't seem to get the alhpabuffer working on canvases. Here's an example of it working with normal graphics whereby it simply draws circles with alphablend then saves to a png file (with alpha):



and here's the same hing on a canvas:


Anyone any ideas why?


ImaginaryHuman(Posted 2008) [#2]
If I understand it correctly, when you create a canvas you actually are creating a graphics context ie a screen within a window, which will allocate buffers based on what the default buffers are for the driver you've selected. You can set which buffers are the default buffers for the driver, and then when you create your canvas it will be created with those buffers. You can't just say `add on an alpha buffer` after the fact, and you shouldn't need to. You can get rid of the `attach graphics` call if you set the buffers you want in the driver default.

Note that your desktop will have to be in 32-bit color mode and it must support an alpha channel in the screen in order for it to have a chance of being provided when you create your canvas. And note that just because you ask for it does not mean that your drive will give it to you, so after you create the canvas and do setgraphics canvasgraphics, or whatever it is, you may want to write a value to the alpha channel of the screen and then read off a pixel from the backbuffer with like grabpixmap and test it to see if the value you wrote is present in the pixel you read back. Note that although OpenGL for example can tell you supposedly how many bits are present in the alpha channel, it can be broken and report falsely if you requested something that was not available.

Once you do have an alpha channel as part of the display, you need a way to write alpha data to it. Drawing objects with alphablending will not achieve that, as the source alpha of the sprite is used to scale the colors in the sprite against the existing colors in the screen, but pays no attention to the screen's alpha channel at all. You have to draw into the screen's alpha channel if you hope to read values from it, and Max2D does not have any native commands to do that. You'd have to dip into DX or GL commands. Not sure if DrawPixmap works tho.


Pete Rigz(Posted 2008) [#3]
ahh I see, thanks. I never noticed the extra parameters for setgraphicsdriver.

SetGraphicsDriver GLMax2DDriver(), GRAPHICS_BACKBUFFER | GRAPHICS_ALPHABUFFER