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.

  
  
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA | GLUT_STENCIL );  
  

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:
http://dropbox.sansumbrella.com/cpp/stencil-src.zip

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

http://www.opengl.org/documentation/spe-…-afunc.html

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.