Cannot Clear/Draw to Framebuffer

Started by
5 comments, last by BitMaster 9 years, 8 months ago

Hi,

I'm trying to clear/draw to a framebuffer but I don't get the expected result. Instead of the clear color/expected object the framebuffer stays black with some white pixels. After running the application multiple times the white pixel pattern changes slightly (=> due to uninitialized memory?).

glGetError returns NO_ERROR and glCheckFramebufferStatus returns FRAMEBUFFER_COMPLETE.

Does anybody know what's going wrong?

This is the content of the framebuffer taken from apitrace after the glClear

Color0:

[attachment=23132:Color0.png]

Depth:

[attachment=23133:Depth.png]

Stencil:

[attachment=23134:Stencil.png]

This are the opengl calls duped by apitrace


glGenVertexArrays(n = 1, arrays = &1)
glGenFramebuffers(n = 1, framebuffers = &1)
glGenTextures(n = 1, textures = &1)
glBindTexture(target = GL_TEXTURE_2D, texture = 1)
glTexStorage2D(target = GL_TEXTURE_2D, levels = 1, internalformat = GL_RGBA16F, width = 640, height = 480)
glTexParameteri(target = GL_TEXTURE_2D, pname = GL_TEXTURE_BASE_LEVEL, param = 0)
glTexParameteri(target = GL_TEXTURE_2D, pname = GL_TEXTURE_MAX_LEVEL, param = 1)
glGenTextures(n = 1, textures = &2)
glBindTexture(target = GL_TEXTURE_2D, texture = 2)
glTexStorage2D(target = GL_TEXTURE_2D, levels = 1, internalformat = GL_RGBA16F, width = 640, height = 480)
glTexParameteri(target = GL_TEXTURE_2D, pname = GL_TEXTURE_BASE_LEVEL, param = 0)
glTexParameteri(target = GL_TEXTURE_2D, pname = GL_TEXTURE_MAX_LEVEL, param = 1)
glGenTextures(n = 1, textures = &3)
glBindTexture(target = GL_TEXTURE_2D, texture = 3)
glTexStorage2D(target = GL_TEXTURE_2D, levels = 1, internalformat = GL_DEPTH24_STENCIL8, width = 640, height = 480)
glTexParameteri(target = GL_TEXTURE_2D, pname = GL_TEXTURE_BASE_LEVEL, param = 0)
glTexParameteri(target = GL_TEXTURE_2D, pname = GL_TEXTURE_MAX_LEVEL, param = 1)
glGenTextures(n = 1, textures = &4)
glBindTexture(target = GL_TEXTURE_2D, texture = 4)
glTexStorage2D(target = GL_TEXTURE_2D, levels = 1, internalformat = GL_DEPTH24_STENCIL8, width = 640, height = 480)
glTexParameteri(target = GL_TEXTURE_2D, pname = GL_TEXTURE_BASE_LEVEL, param = 0)
glTexParameteri(target = GL_TEXTURE_2D, pname = GL_TEXTURE_MAX_LEVEL, param = 1)
//compiling shders genBuffers... no framebuffer operations
glViewport(x = 0, y = 0, width = 640, height = 480)
glBindFramebuffer(target = GL_DRAW_FRAMEBUFFER, framebuffer = 1)
glFramebufferTexture(target = GL_DRAW_FRAMEBUFFER, attachment = GL_COLOR_ATTACHMENT0, texture = 1, level = 0)
glFramebufferTexture(target = GL_DRAW_FRAMEBUFFER, attachment = GL_COLOR_ATTACHMENT1, texture = 2, level = 0)
glFramebufferTexture(target = GL_DRAW_FRAMEBUFFER, attachment = GL_DEPTH_STENCIL_ATTACHMENT, texture = 3, level = 0)
glClearColor(red = 0.3, green = 0.3, blue = 0.3, alpha = 1)
glDepthMask(flag = GL_TRUE)
glClearDepth(depth = 1)
glClear(mask = GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT)

Thank you for your help!

Advertisement

Did you set the viewport to the size of the framebuffer object?

Derp

Yes, the viewport is set to the same width and height as the textures. (I updated the source)

After I added an object, that is using the texture it seems to work.

Is it possible, that opengl noticed that I was never reading data from the framebuffer and skipped rendering?

No, that is not an explanation. To know that OpenGL would have to look into the future.

Looking over your code I notice you did not set GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER with glTexParameteri. My last manually created framebuffer is a while ago now but I believe I remember these need to be set for a texture render target. Is it possible you added these calls when you implemented the obejct rendering code?

Thanks to both of you.

No, that is not an explanation. To know that OpenGL would have to look into the future.

Sure ;) But it could cancel the operation when I call SwapBuffers

And yes, I bound a sampler when I bound the texture.

But why is it important to know the min and mag filters when I write to a texture?

The texture is not considered complete unless those values have been set and you cannot render to an incomplete texture.

This topic is closed to new replies.

Advertisement