title: Loading PNG with stb_image for OpenGL texture gives wrong colors
body: <p>I am using stb_image to load a 32-bit PNG file (RGBA) and I am creating an OpenGL texture with it.</p>
  
  <p>It works fine for 24-bit PNG files (with no alpha channel), but when I use a 32-bit PNG file, something goes wrong.</p>
  
  <p>This is what the texture should look like:</p>
  
  <p><img src="https://s12.postimg.cc/5859nl1ft/font.png" alt="Texture"></p>
  
  <p>And this is what it looks like when rendered with OpenGL (the black parts are meant to be transparent, and are when I enable blending):</p>
  
  <p><img src="https://s10.postimg.cc/taf44i3s9/Problem.png" alt="Wrong Texture"></p>
  
  <p>This is how I load the texture:
  </p>
  
  <pre><code>int w;
  int h;
  int comp;
  unsigned char* image = stbi_load(filename.c_str(), &amp;w, &amp;h, &amp;comp, STBI_rgb);
  
  if(image == nullptr)
      throw(std::string("Failed to load texture"));
  
  glGenTextures(1, &amp;m_texture);
  
  glBindTexture(GL_TEXTURE_2D, m_texture);
  
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  
  if(comp == 3)
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
  else if(comp == 4)
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
  
  glBindTexture(GL_TEXTURE_2D, 0);
  
  stbi_image_free(image);
  </code></pre>
  
  <p>And these are the window parameters (using SDL)
  </p>
  
  <pre><code>SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
  SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
  SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
  SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
  SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
  </code></pre>
  
  <p>What is happening?</p>