I need stencil buffer on 3GS to render planar shadow, and polygon offset won\'t work prefect, still has z-fighting problem. So I use stencil buffer to make the shadow correc
In OpenGL ES 2.0 on iOS, you have to create a combined depth and stencil renderbuffer using GL_DEPTH24_STENCIL8_OES, and then attach it to the bound framebuffer as both GL_DEPTH_ATTACHMENT and GL_STENCIL_ATTACHMENT.
glGenRenderbuffers(1, &depthStencilRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthStencilRenderbuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthStencilRenderbuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencilRenderbuffer);
Just a note, if you are using GLKView, it is as simple as
view.drawableStencilFormat = GLKViewDrawableStencilFormat8;
where view is: GLKView*