0
votes

I was finding for answer, but I can't get answer for my problem.

I have FBO and I can't get alpha blending and multisample to work. FBO draws scene to texture and then it's drown to default framebuffer with two textured triangles. Drawing directly to default framebuffer is fine.

Here is difference between default framebuffer (top) and my FBO (bottom).

enter image description here

I use FBO with 2x color attachments and 1x depth attachments. (Only GL_COLOR_ATTACHMENT0 is used, second is for other function)

Depth test: Disabled

Blending: Enabled

Multisample: Enabled

Blending function: GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA

Any ideas? What am I doing wrong? I can't blend any transparent objects, there is no alpha. If you require more code, I can edit post.

EDIT:

This code is deeper in code structure, I hope, I extracted it properly.

Setup FBO:

glGenFramebuffers(1, &_framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color0_texture_id, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, color1_texture_id, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth_texture_id, 0);

Setup color texture:

glGenTextures(1, &texture_id);
glBindTexture(GL_TEXTURE_2D, texture_id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

Depth texture is the same except one line:

// This is probably wrong
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);

EDIT:

Blending is working now, but still no multisample. How to do it?

1
How is the fbo and the texture you render into setup? - dari
Multisampling isn't actually enabled, as the textures attached to the FBO are not multisample textures. - peppe
So what is the solution? How can I get multisample to work? Can you help me? - eSeverus

1 Answers

3
votes

To use multisampling when rendering to an FBO you need to allocate a multisample texture using glTexImage2DMultisample and attach that to the FBO using GL_TEXTURE_2D_MULTISAMPLE instead of GL_TEXTURE_2D.

Source: https://www.opengl.org/wiki/Multisampling#Allocating_a_Multisample_Render_Target