PDA

View Full Version : 2D. Rendering to a Masked Texture


Zwilnik
2003.03.23, 05:56 PM
This is more for a cool feature rather than a gameplay critical effect, but I was wondering if there's a fast way in basic OpenGL to draw to a texture but keep that texture's original alpha channel (I'm using 32 bit RGBA textures). I can see ways of doing it off-card by doing the effect with the CPU (ie re-copying the alpha bytes over the result), but I was wondering if OpenGL has any built in methods.
Preferably, any effect would have to be 'clear' OpenGL rather than via the extensions, as I've found that otherwise cool extensions (like the multipass textures) only work on NVidia cards (it passes if it works on my iBook 500 ;) )

inio
2003.03.23, 06:27 PM
Um, I've never done render-to-texture, but would glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE) work?

OneSadCookie
2003.03.23, 06:36 PM
So, get a context with 8-bit destination alpha, render your texture to it, ColorMask like inio says, render the color channels, ColorMask back to normal, then CopyTexSubImage2D. Seems like it should work :)

AFAICT, ColorMask doesn't affect the behavior of CopyTexSubImage2D, so just ColorMasking before you do that probably won't work.

Zwilnik
2003.03.23, 07:07 PM
neat, that sounds like a good solution (was playing about with CopyTexSubImage2D, but hadn't spotted the glColorMask). I'll give it a try.