Framebuffer problems

Im trying to render to a texture (shadowmap) but if I try to generate the framebuffer I always get GL_UNSUPORTED_FRAMEBUFFER_EXT.
I have a Nvidia GPU (GTX950 oc).

Texture generation :

void GenEmtyTexture(int sizeX, int sizeY, GLuint * ID, GLubyte * imagePtr, int unbind, int colorMode0, int colorMode1, GLuint dataType, GLint activeTexture, char mipmap)
{
  //imagePtr should have enougth/be NULL memory...
  printf("Generating texture...
");
  glGenTextures(1, ID);
  glActiveTexture(activeTexture);
  glBindTexture(GL_TEXTURE_2D, *ID);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  
  if(mipmap)
  {
    glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
  }
  
  glTexImage2D(GL_TEXTURE_2D, 0, colorMode0, sizeX, sizeY, 1, colorMode1, dataType, imagePtr);
  
  printf("ERROR : %s
", gluErrorString( glGetError() ) );
  if(unbind)
  {
    glBindTexture(GL_TEXTURE_2D, 0);
  }
}

I use it like this :

GenEmtyTexture(2048, 2048, &textureIDs[0], NULL, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_TEXTURE0, 1);

This is how I generate the FBO :

glGenFramebuffers(1, &frameBufferIDs[0]);
glBindFramebuffer(GL_FRAMEBUFFER, frameBufferIDs[0]);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureIDs[0], 0);

printf("FRAMEBUFFERSTATUS : %x
", glCheckFramebufferStatus(GL_FRAMEBUFFER));

printf always prints : FRAMEBUFFERSTATUS : 8cdd -->

#define GL_FRAMEBUFFER_UNSUPPORTED_EXT    0x8CDD

I read that this is Nvidia specific :

Warning: NVIDIA's OpenGL driver has a known issue with using incomplete textures. If the texture is not texture complete, the FBO itself will be considered GL_FRAMEBUFFER_UNSUPPORTED​, or will have GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT​. This is a driver bug, as the OpenGL specification does not allow implementations to return either of these values simply because a texture is not yet complete. Until this is resolved in NVIDIA's drivers, it is advised to make sure that all textures have mipmap levels, and that all glTexParameteri​ values are properly set up for the format of the texture. For example, integral textures are not complete if the mag and min filters have any LINEAR fields.

I dont know how to fix that.

glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

This is deprecated : Use glGenerateMipmap() instead, after glTexImage2d().

Still x8cdd --> GL_FRAMEBUFFER_UNSUPPORTED_EXT.

You defined a min filter that uses mipmaps, but you did not create any mipmaps.

With the “old style” glTexImage2D function you need to call it for every mipmap level.

Untested example code:

int mipmapLevelX = sizeX;
int mipmapLevelY = sizeY;
int mipmapLevel  = 0;
while (mipmapLevelX > 1 || mipmapLevelY > 1) {
    glTexImage2D(GL_TEXTURE_2D, mipmapLevel, colorMode0, mipmapLevelX, mipmapLevelY, 1, colorMode1, dataType, imagePtr);
    mipmapLevel++;
    mipmapLevelX = max(1, mipmapLevelX / 2);
    mipmapLevelY = max(1, mipmapLevelY / 2);
}

Also you have set border to 1. If I remember correctly that was already deprecated since OpenGL 3.2 core. But I don’t know what version you use. And in compatibility mode that should work fine even in OpenGL 4.5.

Yes, there is a detailed example about it in the FBO specs (Read example 5).

One more thing. If you use glGenerateMipmap or glGenerateMipmapEXT after creating the mipmap level 0 (your glTexImage2D), they create all other other mipmap levels from that. So in that case you don’t need to manually crate every single mipmap level.