FBO and stencil: problem

Hi,

Why do I have an error GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT ?

//color
glGenTextures(1, &texID);
glBindTexture (GL_TEXTURE_2D, texID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,  512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture (GL_TEXTURE_2D, 0);
	
//stencil
GLuint stencilID;
glGenRenderbuffersEXT(1, &stencilID);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, stencilID);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX8_EXT, 512, 512);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
	
//attach color and stencil buffers to the fbo
glGenFramebuffersEXT(1, &fbo);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texID, 0);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, stencilID);
 
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if(status==GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT)
	std::cout<<"error"<<std::endl;
	
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

Thank you
(Sorry for my english)

zenux:
[b]Why do I have an error GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT ?

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,  512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
...
...
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX8_EXT, 512, 512);

[/b]
Try GL_RGBA8 for the color texture internal format.

Try GL_DEPTH24_STENCIL8_EXT for your stencil renderbuffer, if you have EXT_packed_depth_stencil. May need to point depth attachment to it as well.

I’ve never tried to attach a stencil buffer without a depth buffer.

What’s your hardware and driver version?

With GL_RGBA8 and GL_DEPTH24_STENCIL8_EXT, I have an error GL_FRAMEBUFFER_UNSUPPORTED_EXT !

However, with Glew, it is OK :
if(!GLEW_EXT_framebuffer_object)
throw (…)
if(!GLEW_EXT_packed_depth_stencil)
throw (…)

I have a GeForce Go 7600 with the last driver on Linux and driver 6.14.10.9424 on Windows.
And the “OpenGL Extention Viewer” software says to me that I have the extention GL_EXT_FRAMEBUFFER_OBJECT and GL_EXT_PACKED_DEPTH_STECIL !

(Sorry for my english)

You need to support the EXT_packed_depth_stencil. Use GL_DEPTH_STENCIL_EXT when making your render buffer, and attach the render buffer to both the depth and stencil attachments of your FBO.

zenux:
With GL_RGBA8 and GL_DEPTH24_STENCIL8_EXT, I have an error GL_FRAMEBUFFER_UNSUPPORTED_EXT !
Odd. Works fine for me. NVidia GeForce 6800 Ultra on Linux, 1.0-100.14.09 drivers.

It’s works with a depth buffer : “glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, stencilID);”.

But I would like that the FBO reads (I don’t need to write) in the back depth buffer (GL_BACK) and not in its depth buffer ! Is it possible ?

(Sorry for my english)

Jesus, zenux, your English is really beginning to annoy me.

Btw, I don’t think you can read and write to back buffer at the same time, not unless you really don’t know what you are not undoing.

Here’s an example that comes with the spec.
You probably did not bind the depth buffer or didn’t bind the stencil buffer.
The same depth_stencil needs to be bound as depth and then as stencil render buffer.

glGenFramebuffersEXT(1, &fb);
        glGenTextures(1, &tex_color);
        glGenTextures(1, &tex_depthstencil);

        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

        // Setup color texture (mipmap)
        glBindTexture(GL_TEXTURE_2D, tex_color);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8,
                     512, 512, 0, GL_RGBA, GL_INT, NULL);
        glGenerateMipmapEXT(GL_TEXTURE_2D);
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
                                  GL_COLOR_ATTACHMENT0_EXT,
                                  GL_TEXTURE_2D, tex_color, 0);

        // Setup depth_stencil texture (not mipmap)
        glBindTexture(GL_TEXTURE_2D, tex_depthstencil);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8_EXT,
                     512, 512, 0, GL_RGBA, GL_INT, NULL);
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
                                  GL_DEPTH_ATTACHMENT_EXT,
                                  GL_TEXTURE_2D, tex_depthstencil, 0);
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
                                  GL_STENCIL_ATTACHMENT_EXT,
                                  GL_TEXTURE_2D, tex_depthstencil, 0);

But I would like that the FBO reads (I don’t need to write) in the back depth buffer (GL_BACK) and not in its depth buffer ! Is it possible ?
No. FBO’s cannot use parts of the regular default framebuffer, and vice-versa. Once you bind an FBO, it turns off all parts of the standard framebuffer.

Thank you

Originally posted by modus:
Jesus, zenux, your English is really beginning to annoy me.
Why ? I do many mistakes ?
Sorry, I am Belgian :frowning:

Zenux: He just meant, you should stop apologizing. It is OK to apologize once, that your english is not that good, but writing it in every post is really not necessary.

And, by the way, your english is not that bad. Many people, who post on these boards, have much worse english skills.

Jan.