Check yo' stencil bits in GLUT

Alec Jacobson

October 11, 2013

weblog/

I just wasted a lot of time wondering why I couldn't get any interesting combinations of glStenilOp and glStencilFunc to work correctly. Turns out I did not have the stencil buffer enabled in my GLUT application. I found this out by adding:

int i;
glGetIntegerv(GL_STENCIL_BITS, &i);
cout<<"GL_STENCIL_BITS: "<<i<<endl;

which displayed:

GL_STENCIL_BITS: 0

I fixed this by changing

glutInitDisplayString( "rgba depth double samples>=8");

to

glutInitDisplayString( "rgba depth double samples>=8 stencil"); 

Now things are working as expected.