Search code examples
c++debuggingopenglgraphicsfbo

Attaching Framebuffer to Texture error


I am trying to implement shadow mapping with the tutorial here, however when I try to use this code to attach a Framebuffer to a texture it fails. My OpenGL context is 3.1 and I believe i have an Intel 3000 series graphics card. The code fails at 2 points. The first failure is at glFramebufferTexture2D, which gives error code 1282 (Not sure what enumeration that corresponds too). I believe this error is causing the assert assi later in the code to fail. I have tried code from similar questions but they do not seem to work in this case.

glGenFramebuffers(1, &MObject::fbo);
glGenTextures(1, &MObject::shadowMap);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, windowWidth, windowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glBindFramebuffer(GL_FRAMEBUFFER, MObject::fbo);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, MObject::shadowMap, 0);
GLenum  err = glGetError(); // Error code: 1282
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
assi(status == GL_FRAMEBUFFER_COMPLETE, "FBO error!"); // Expression is false, abort called.

Solution

  • Yea so I forgot glBindTexture. I hate myself. Thank you Hectigo!