我试图为FBO启用mutisampling和alpha-to-coverage。使用默认帧缓冲区,我所要做的就是拨打glEnable(GL_MULTISAMPLE)
和glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE)
。但是,我无法使用我自己的FBO达到同样的效果。如何使用OpenGL FBO多重采样
我的目标:将场景绘制到FBO的方式与使用上述属性绘制到默认帧缓冲区的方式相同。从那里我希望能够将图像用作未来穿过着色器的纹理。
这工作:代码用于制造FBO没有多重采样/α-来覆盖,1个附色,1个深度附件:
// Generate the color attachment
glGenTextures(1,&defaultColorAttachment0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,defaultColorAttachment0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,screenWidth,screenHeight,0,GL_RGBA,GL_UNSIGNED_BYTE,NULL);
// Bind the texture to the FBO
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, defaultColorAttachment0,0);
// Generate the depth attachment
glGenRenderbuffers(1,&defaultDepthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, defaultDepthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, screenWidth, screenHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, defaultDepthBuffer);
这不起作用。代码试图使多重采样FBO:
// Generate the color attachment
glGenTextures(1,&defaultColorAttachment0);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, defaultColorAttachment0);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA, screenWidth, screenHeight, GL_FALSE);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, defaultColorAttachment0,0);
// Generate the depth attachment
glGenRenderbuffers(1,&defaultDepthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, defaultDepthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, screenWidth, screenHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, defaultDepthBuffer);
我试图寻找通过这个OpenGL的维基,虽然它不完全(未完成各种标题,使它看起来不专业)。 glGetError
从不抱怨。我试过用这个来搞乱,但是我得到一个黑屏或者一个充满垃圾像素的屏幕。
主要问题:我需要考虑/更改哪些内容以及为了获得多重采样和alpha-to-coverage与FBO一起工作而在哪里(FBO创建,纹理,着色器)?
你有没有试过调用glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D_MULTISAMPLE,defaultColorAttachment0,0);而不是glFramebufferTexture(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,defaultColorAttachment0,0);? – Jherico
@Jherico是的,我仍然得到一个黑屏。 – GraphicsMuncher