a zillion masked images

So I’m working on an app where I need to draw a whole bunch of masked images (pictures of trees!)

I could just make an alpha layer for my texture full of 0’s and 255’s and do blending, but that seems like a lot of work for the gpu for no reason (and verifiably slows things down a lot)

I’m trying to hunt for a simpler way for GL to do the texture drawing: If the alpha channel is >0 then draw the pixel, otherwise don’t.

If I need to break my textures into 2 files, I’m cool with that. Bonus points if I don’t have to.

Can any GL whiz tell me the least gpu intensive way to do this?

THANKYOU :smiley:

I’m not sure quite what you meant by creating an alpha layer and then blending. If you weren’t thinking of the stencil test when you said that, it would be my recommendation. I just put up some quick test code that uses the stencil buffer. Note that you must go into ofAppRunner.cpp and add a request for a stencil buffer to the glut setup.


You can also draw pixels to the stencil buffer, which seems promising for using a png as your stencil. I’m going to give that a go now. Hopefully this helps.

Stencil example code:

A good GL buff friend pointed out GL_ALPHA_TEST to me which I believe is what I want


glAlphaFunc(GL_GEQUAL, 0.5) thresholds drawing pixels based on the alpha channel being >= 0.5 (128 of 256)

This, I think, is working well.