BMardle
Posts: 114
Joined: Wed Feb 13, 2013 4:00 pm
Location: Isle of Wight

Working stencil buffer code?

Tue Jan 07, 2014 6:07 pm

Hiya. Can anyone give the source for a program that works on the Pi and uses a stencil buffer? (Or, at least, the relevant bits of code.)
PeterO?
I compiled the Stencil_Test example program associated 'The OpenGL ES 2.0 Programming Guide' and just got a flickery transparent rectangle... unsurprisingly.
I asked for an 8-bit alpha channel... and got a flickery green rectangle.
I gather from the source code that the result should be red, green, blue and yellow, according to stencil buffer values. (I don't know why it's flickering either.)
I tried using a 24-bit depth buffer instead of 8-bit. No difference.
(96 bits per pixel? That would have been a fevered dream when I started graphics programming!)
Bruce Mardle. "You know I yearn for a simpler time of barn dances and buggy rides before life was cheapened by heartless machines."

BMardle
Posts: 114
Joined: Wed Feb 13, 2013 4:00 pm
Location: Isle of Wight

Re: Working stencil buffer code?

Wed Jan 08, 2014 7:32 pm

Ah-ha! Fixed the sample program myself!
1st, add ES_WINDOW_ALPHA to the flags in esCreateWindow (as PeterO most usefully pointed out). Otherwise everything is transparent.
2nd, instead of passing Draw as a parameter to esRegisterDrawFunc, just call it directly, get rid of the call to esMainLoop (there's no reason to keep re-rendering it), and add, say, sleep(10) before ShutDown so you get a chance to see the result.
3rd, change the last element of the last element of colors (line124 of the original) to 1.0 instead of 0.0. If you ask OpenGL to make a rectangle 'transparent yellow' it'll make it transparent, not yellow.
Bruce Mardle. "You know I yearn for a simpler time of barn dances and buggy rides before life was cheapened by heartless machines."

User avatar
Criffer
Posts: 4
Joined: Tue Dec 22, 2015 4:37 pm

Re: Working stencil buffer code?

Wed Dec 23, 2015 11:22 am

Point 2: The sample code is incomplete, and assumes that it is starting from a default GL state. The first Draw call works correctly as it is able to write to the stencil buffer. Subsequent Draws have writing to the stencil buffer disabled.

The correct fix is to add

Code: Select all

glStencilMask(-1)
to the beginning of the Draw function.

Return to “OpenGLES”