I have been trying to get this work but either get black screen or reporting error when using XCode to analyze the GL code like below. Any help appreciated. I am using Swift here if that making a difference. Any help appreciated.

enter image description here

The code I used to attach a stencil buffer is like below:

var depthRenderbuffer: GLuint = 0
glGenRenderbuffers(1, &depthRenderbuffer)
glBindRenderbuffer(GLenum(GL_RENDERBUFFER), depthRenderbuffer)
glRenderbufferStorage(GLenum(GL_RENDERBUFFER), GLenum(GL_DEPTH24_STENCIL8), 2208, 1242)
glFramebufferRenderbuffer(GLenum(GL_FRAMEBUFFER), GLenum(GL_STENCIL_ATTACHMENT), GLenum(GL_RENDERBUFFER), depthRenderbuffer)

1 Answer 1


I figured it after found some sample code. Basically, after I bind the render buffer, the current render buffer is bound to the depthRenderBuffer, However, the bound rendering buffer while presenting must be a color render buffer. after I added another line of code at the end, it works. Hope this helps somebody in the future.

// Make the Color Render Buffer the current buffer for display
// This is important. colorRenderBuffer needs to be the one 
// binding to render buffer at the time of presenting
glBindRenderbuffer(GLenum(GL_RENDERBUFFER), self.colorRenderBuffer)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .