Artifacts from scaling texture in frame buffer. Why ?

Hi guys !

I have function for resize an RGB image (stored in string) in frame buffer.
All works, but the result image has artifacts (intel driver: diagonal line for left-top quarter of the image),
(nvidia: left-top quarter of the image has triangle with half drawed texture)

Please, check my code, may I have missed something, and by that I have the artifacts …

OS: linux, cards: Intel(xf86-video-intel-9999) and nvidia(nvidia-drivers-390.42)

thanks


// W and H are old sizes for image, nW and nH are new sizes
void resize_image(std::string& img, int& W, int& H, int nW, int nH) {

  std::string result;
  int D = img.size()/W/H;

  GLenum tot = (D == 4) ? GL_RGBA : GL_RGB; // type of texture

  result.resize(nW*nH*D);

  GLuint fbo = 0; // The frame buffer object,
  GLuint rbo = 0; // The depth buffer for the frame buffer object
  GLuint tex = 0; // The texture object to write our frame buffer object to


  /// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  glGenTextures(1, &tex); // Generate one texture
  glBindTexture(GL_TEXTURE_2D, tex); // Bind the texture fbo_texture

  glTexImage2D(GL_TEXTURE_2D, 0, tot, W, H, 0, tot, GL_UNSIGNED_BYTE, &img[0]); // Create a standard texture with the width and height of our window

  // Setup the basic texture parameters
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);//GL_LINEAR   GL_NEAREST
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);//GL_LINEAR    GL_NEAREST

  // Unbind the texture
  glBindTexture(GL_TEXTURE_2D, 0);
  /// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


  /// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  glGenRenderbuffers(1, &rbo); // Generate one render buffer and store the ID in fbo_depth
  glBindRenderbuffer(GL_RENDERBUFFER, rbo); // Bind the fbo_depth render buffer

  glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, nW, nH); // Set the render buffer storage to be a depth component, with a width and height of the window

  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo); // Set the render buffer of this buffer to the depth buffer

  glBindRenderbuffer(GL_RENDERBUFFER, 0); // Unbind the render buffer
  /// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


  /// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  glGenFramebuffers(1, &fbo); // Generate one frame buffer and store the ID in fbo
  glBindFramebuffer(GL_FRAMEBUFFER, fbo); // Bind our frame buffer

  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0); // Attach the texture fbo_texture to the color buffer in our frame buffer

  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo); // Attach the depth buffer fbo_depth to our frame buffer

  GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); // Check that status of our generated frame buffer

  if (status != GL_FRAMEBUFFER_COMPLETE_EXT) // If the frame buffer does not report back as complete
  {
    std::cout << "Couldn't create frame buffer" << std::endl; // Output an error to the console
    std::exit(0); // Exit the application
  }

  glBindFramebuffer(GL_FRAMEBUFFER, 0); // Unbind our frame buffer
  /// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


  glBindFramebuffer(GL_FRAMEBUFFER, fbo); // Bind our frame buffer for rendering
  glViewport(0, 0, nW, nH); // Set the size of the frame buffer view port
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0.0, nW, nH, 0.0, 0.0, 1.0);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();  // Reset the modelview matrix

  glClearColor(0.0, 1.0, 0.0, 1.0);

  /// 
ote if do adding GL_COLOR_BUFFER_BIT to bits clear - its will producing black square ...
  glClear(GL_DEPTH_BUFFER_BIT);



  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, tex);

  glBegin(GL_QUADS);

  glTexCoord2i(0, 1); glVertex2i(0,  0); // Top Left Of The Texture and Quad
  glTexCoord2i(1, 1); glVertex2i(nW, 0); // Top Right Of The Texture and Quad
  glTexCoord2i(1, 0); glVertex2i(nW, nH); // Bottom Right Of The Texture and Quad
  glTexCoord2i(0, 0); glVertex2i(0, nH); // Bottom Left Of The Texture and Quad

  glEnd();

  glFlush();
  glFinish();

  // read result into new buffer image
  glReadPixels(0, 0, nW, nH, tot, GL_UNSIGNED_BYTE, &result[0]);


  glBindFramebuffer(GL_FRAMEBUFFER, 0); // Unbind our texture
  glBindTexture(GL_TEXTURE_2D, 0);


  glDeleteFramebuffers(1,&fbo);
  glDeleteRenderbuffers(1,&rbo);
  glDeleteTextures(1, &tex);

  W = nW; H = nH;
  img = result;
}


Sorry for noise, I have found solution in this thread: Odd-artifacts-when-rendering-to-FBO

OpenGL is difficult technology, needs to know order of actions/settings before you get needed result (as most in all functional programming)