Jump to content

  • Log In with Google      Sign In   
  • Create Account

Cannot Clear/Draw to Framebuffer


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Weton   Members   -  Reputation: 255

Like
0Likes
Like

Posted 12 August 2014 - 02:43 PM

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:

Color0.png

Depth:

Depth.png

Stencil:

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!


Edited by Weton, 13 August 2014 - 03:16 AM.


Sponsor:

#2 Sponji   Members   -  Reputation: 1361

Like
0Likes
Like

Posted 12 August 2014 - 05:19 PM

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


Derp

#3 Weton   Members   -  Reputation: 255

Like
0Likes
Like

Posted 13 August 2014 - 03:17 AM

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



#4 Weton   Members   -  Reputation: 255

Like
0Likes
Like

Posted 14 August 2014 - 12:53 PM

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?

#5 BitMaster   Crossbones+   -  Reputation: 4442

Like
1Likes
Like

Posted 15 August 2014 - 12:14 AM

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?



#6 Weton   Members   -  Reputation: 255

Like
0Likes
Like

Posted 15 August 2014 - 08:27 AM

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?

#7 BitMaster   Crossbones+   -  Reputation: 4442

Like
0Likes
Like

Posted 15 August 2014 - 08:44 AM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS