1

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?

eSeverus
  • 552
  • 1
  • 6
  • 18

1 Answers1

3

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

user3256930
  • 1,123
  • 7
  • 12
  • I was afraid, you say this. I don't have functions glTexImage2DMultisample with GL_TEXTURE_2D_MULTISAMPLE . They just miss in my libraries. I don't understand why, because I have OpenGL version 3.3 and in documentation is requires 3.2 and greater. Thanks for help, I hope this is answer, and I try solve it. – eSeverus Jan 31 '15 at 01:36