3

EDIT: SOLVED

I encountered a problem while attempting to render into a texture. I create a framebuffer object like this:

glGenTextures(1, &renderFBOtex);
glBindTexture(GL_TEXTURE_2D, renderFBOtex);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, 0);

glGenRenderbuffers(1, &renderFBOrender);
glBindRenderbuffer(GL_RENDERBUFFER, renderFBOrender);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
glBindRenderbuffer(GL_RENDERBUFFER, 0);

glGenFramebuffers(1, &renderFBO);
glBindFramebuffer(GL_FRAMEBUFFER, renderFBO);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderFBOtex, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderFBOrender);

GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
glBindFramebuffer(GL_FRAMEBUFFER, 0);

But the return value of glCheckFrambufferStatus is always GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT.

The problem seems to be with the texture, as it is the same without the Renderbuffer attachment. Drawing into the Framebuffer itself shouldn't be a problem.

Could someone please point out what am I missing here?

3 Answers 3

1

Build texture mipmaps before attaching it on the color buffer.

The routine dedicated to this task is glGenerateMipmap.


Another suggestion would be to play with the texture internal format. You are not specifying a sized internal format. Since one of reason of the error is that the texture doesn't have a supported color-renderable internal format, you could give a try.

Sign up to request clarification or add additional context in comments.

2 Comments

This should be completely unneccessary when using GL_LINEAR filter mode (like he does). And by the way, don't use gluBuild2DMipmaps anyway (which isn't even OpenGL). Just use GL_GENERATE_MIPMAP or better, if you already have FBOs, use glGenerateMipmaps. They should do it in hardware.
Thanks a lot for your input. I tried it, but it doesn't seem to make any difference. I also tried probably every possible combination of parameters glTexImage2d. It is the same every time. Is it possible that my problem is caused somewhere else in the program? I mean, I really am new to OpenGL and am not sure about all the mutual dependencies between various pipeline stages...
1

Problem was in another part of the program. It was a very stupid mistake, which led to use of wrongly initialized values for width and height of the texture. They were both set to 0, hence the incomplete attachment error.

Comments

0

Try this:

glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderFBOtex, 0);
                          ^^^^

Technically they should make no difference, but some drivers may had this bug.

3 Comments

I already tried that. According to documentation, GL_DRAW_FRAMEBUFFER and GL_FRAMEBUFFER are equivalent, and it doesn't seem to change anything. Thanks anyway...
@user1076104: Yes, the equivalency was what I meant by "makes no difference". But some drivers had (have?) bugs, with that.
Sorry, I initially overlooked you wrote that (which is pretty stupid on my side while looking for advice).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.