Original Post
I'm trying to create a framebuffer with multisampling but if I attach a texture I get the error GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE from glCheckFramebufferStatus.
multisample framebuffer initialization code:
The code above works fine until the part where I bind a texture to the frame buffer. This is how I set my pixel format on my window:
multisample framebuffer initialization code:
// Framebuffer
glGenFramebuffers(1, &rendertarget->frameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, rendertarget->frameBuffer);
// Multi sample colorbuffer
glGenRenderbuffers(1, &rendertarget->colorBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, rendertarget->colorBuffer);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_RGBA8, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rendertarget->colorBuffer);
// Multi sample depth buffer
glGenRenderbuffers(1, &rendertarget->depthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER_EXT, rendertarget->depthBuffer);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rendertarget->depthBuffer);
// Create and bind texture
glGenTextures(1, &rendertarget->BaseTexture);
glBindTexture(GL_TEXTURE_2D, rendertarget->BaseTexture);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
// This is where the problem happens:
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rendertarget->BaseTexture, 0);The code above works fine until the part where I bind a texture to the frame buffer. This is how I set my pixel format on my window:
int pixelFormat;
UINT numFormats;
float fAttributes[] = {0,0};
int iAttributes[] = { WGL_DRAW_TO_WINDOW_ARB,GL_TRUE,
WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
WGL_COLOR_BITS_ARB, 24,
WGL_ALPHA_BITS_ARB,8,
WGL_DEPTH_BITS_ARB,16,
WGL_STENCIL_BITS_ARB,0,
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,
WGL_SAMPLES_ARB, 4,
0, 0};
wglChoosePixelFormatARB( rendertarget->hDC, iAttributes, fAttributes,1, &pixelFormat, &numFormats);
SetPixelFormat( rendertarget->hDC, pixelFormat, NULL );