Kelptos render to texture code

BlitzMax Forums/OpenGL Module/Kelptos render to texture code

Pete Rigz(Posted 2008) [#1]
Hello, thanks for this code. I'm not sure if this is correct behavior or not but when rendering to a texture with alpha it doesn't seem to add the alpha up properly. I've been trying to save pngs with alpha and having the same problem, heres example code:



Basically it draws 10 overlapping rectangles all with alpha set to .1 so that a gradient is created from .1 to 1 alpha. This is done on the back buffer with cls alpha 0 and it's also rendered to the image with cls alpha set to 0, but the image dosen't seem to be rendered properly. If anyone could figure out how to make the image look the same as how it's rendered to the screen it'd be much appreciated. :)


The Caffeine Kid(Posted 2008) [#2]
You have a...

SetAlpha .1

where you need a...

SetAlpha c

I think. :)


Pete Rigz(Posted 2008) [#3]
The code is just demonstrating that alpha isn't adding up. All the rects drawn overlap each other until the are 10 overlapping, so 10 rects overlapping with .1 alpha should mean that the image has an alpha value of 1 at that point. It behaves as you'd expect on the backbuffer but not on the image buffer.


Dreamora(Posted 2008) [#4]
Perhaps a driver issue. Perhaps an ATI.
Or it is because what you have behind the FBO when you draw it, so it seems different than it is on the backbuffer.


Jake L.(Posted 2008) [#5]
When rendering to your texture, try using

glEnable GL_BLEND
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
glDisable GL_ALPHA_TEST


instead of Setblend(ALPHABLEND).

Edit: Another problem is that you can't save the image. If you just use SavePixMapPNG(LockImage(img,1,0)) you'll get a pixmap with the approp size, but it's empty.