title: Window background visible through textures
body: <p>What can I try to solve this problem? In this example (see a screenshot below) I am using OpenGL 1.1 with deprecated functions like: glEnableClientState, glMatrixMode, glTexCoordPointer, and so on. Thanks in advance.</p>
  <p>You can see the whole example code in this thread: <a href="https://community.khronos.org/t/window-background-visible-through-textures/109061" rel="nofollow noreferrer">https://community.khronos.org/t/window-background-visible-through-textures/109061</a></p>
  <p>I draw with <code>DEPTH_TEST</code>:</p>
  <pre class="lang-cpp prettyprint-override"><code>glEnable(GL_DEPTH_TEST);
  
  /* ... */
  
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
  // Player
  glBindTexture(GL_TEXTURE_2D, spriteTexture);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glTranslatef(playerBody-&gt;GetPosition().x * WORLD_SCALE,
                  playerBody-&gt;GetPosition().y * WORLD_SCALE, 10.f);
  glScalef(16.f, 16.f, 1.f);
  glDrawArrays(GL_TRIANGLE_STRIP, drawingIndex, 4);
  
  // Coin
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glTranslatef(178.f, 120.f, 10.f);
  glScalef(16.f, 16.f, 1.f);
  glDrawArrays(GL_TRIANGLE_STRIP, 24, 4);
  
  // Enemy
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glTranslatef(194.f, 184.f, 10.f);
  glScalef(16.f, 16.f, 1.f);
  glDrawArrays(GL_TRIANGLE_STRIP, 20, 4);
  
  // Background
  glBindTexture(GL_TEXTURE_2D, backgroundTexture);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glTranslatef(0.f, 0.f, 0.f);
  glScalef(256.f, 216.f, 1.f);
  glDrawArrays(GL_TRIANGLE_STRIP, 16, 4);
  
  glfwSwapBuffers(window);
  </code></pre>
  <p>Texture:</p>
  <p><a href="https://i.stack.imgur.com/lZi9q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lZi9q.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/k6n3Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k6n3Z.png" alt="enter image description here" /></a></p>
  <p>Various window background values to show that I have an alpha channel:</p>
  <p>For <code>glClearColor(1.f, 0.f, 0.f, 1.f);</code></p>
  <p><a href="https://i.stack.imgur.com/Fy3R6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fy3R6.png" alt="enter image description here" /></a></p>
  <p>For <code>glClearColor(0.2f, 0.5f, 0.3f, 1.f);</code></p>
  <p><a href="https://i.stack.imgur.com/PNgnN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PNgnN.png" alt="enter image description here" /></a></p>
  <p>My Settings:</p>
  <pre class="lang-cpp prettyprint-override"><code>    glEnable(GL_DEPTH_TEST);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glEnable(GL_TEXTURE_2D);
  </code></pre>
  <pre class="lang-cpp prettyprint-override"><code>GLuint createTexture(char *path)
  {
      int h_image, w_image, cnt;
  
      unsigned char *data = stbi_load(path, &amp;w_image, &amp;h_image, &amp;cnt, 0);
  
      if (data == NULL)
      {
          cout &lt;&lt; &quot;Failed to load an image&quot; &lt;&lt; endl;
          glfwTerminate();
          exit(-1);
      }
  
      GLuint texture;
      glGenTextures(1, &amp;texture);
      glBindTexture(GL_TEXTURE_2D, texture);
      {
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
          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_RGBA, w_image, h_image, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
      }
      glBindTexture(GL_TEXTURE_2D, 0);
  
      stbi_image_free(data);
  
      return texture;
  }
  </code></pre>