title: OpenGL: 2D Overlay is white over of 3D Scene
body: <p>I'm trying to make a copy of MineCraft in Java using OpenGL (LWJGL). The problem I'm facing is that everything of my 2D overlay (aiming cross in the middle, menus, etc...) are all white. The 3D part of the game works great: every cube has a texture on each side.</p>
  
  <p>But when I try to draw the overlay, as I said, every texture is white, but I can see the shape of it (because it has transparent areas). I'll add a picture of it.</p>
  
  <p><img src="https://i.stack.imgur.com/7v9WA.png" alt="enter image description here">
  <sup>(This is supposed to be the inventory)</sup></p>
  
  <p>As you can see, the overlay is completely white. And it should look like this:</p>
  
  <p><img src="https://i.stack.imgur.com/iQYU7.png" alt="enter image description here"></p>
  
  <p>I'm already searching the web for hours. Can't seem to find a solution.<br>
  This drives my crazy... I already searched for instructions of how to create a 2D overlay on a 3D scene, but they don't help either. So I though, I'll give StackOverflow a try.</p>
  
  <p>Hopefully someone can help me?
  Thanks for reading my question and for the (hopefully coming) answers!</p>
  
  <p>Martijn</p>
  
  <p>Here is the code:</p>
  
  <p><strong>Initialising OpenGL</strong></p>
  
  <pre><code>public void initOpenGL() throws IOException
  {
      // init OpenGL
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(0, 800, 600, 0, 1, 300);
      glMatrixMode(GL_MODELVIEW);
  
      float color = 0.9f;
  
      glClearColor(color, color, color, color);
      glEnable(GL_TEXTURE_2D);
      glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  
      glShadeModel(GL_FLAT);
      glEnable(GL_DEPTH_TEST);
      glDepthFunc(GL_LEQUAL);
  
      glEnable(GL_LINE_SMOOTH);
      glEnable(GL_CULL_FACE);
  
  
      glEnable(GL_FOG);
      glFog(GL_FOG_COLOR, MineCraft.wrapDirect(color, color, color, 1.0f));
      glFogi(GL_FOG_MODE, GL_LINEAR);
      glFogf(GL_FOG_START, _configuration.getViewingDistance() * 0.8f);
      glFogf(GL_FOG_END, _configuration.getViewingDistance());
      glFogi(NVFogDistance.GL_FOG_DISTANCE_MODE_NV, NVFogDistance.GL_EYE_RADIAL_NV);
      glHint(GL_FOG_HINT, GL_NICEST);
  
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  }
  </code></pre>
  
  <p><strong>Configuring the matrixes for drawing the overlay</strong> (Out of inspiration, I literally copied all the OpenGL calls for this method from BlockMania (another open-source MineCraft copy), which works great)</p>
  
  <pre><code>public void renderOverlay()
  {
      glMatrixMode(GL_PROJECTION);
      glPushMatrix();
      glLoadIdentity();
      GLU.gluOrtho2D(0, conf.getWidth(), conf.getHeight(), 0);
      glMatrixMode(GL_MODELVIEW);
      glEnable(GL_COLOR_MATERIAL);
      glPushMatrix();
      glLoadIdentity();
  
      glDisable(GL_CULL_FACE);
      glDisable(GL_DEPTH_TEST);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  
      /** RENDER **/
      if (_activatedInventory != null)
      {
          _activatedInventory.renderInventory();
      }
  
      glDisable(GL_BLEND);
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_CULL_FACE);
  
      glPopMatrix();
      glMatrixMode(GL_PROJECTION);
      glPopMatrix();
      glMatrixMode(GL_MODELVIEW);
  }
  </code></pre>
  
  <p><strong>Drawing the texture itself:</strong></p>
  
  <pre><code>public void renderInventory()
  {
      Configuration conf = Game.getInstance().getConfiguration();
  
      glTranslatef(conf.getWidth() / 2.0f, conf.getHeight() / 2.0f, 0.0f);
  
      glEnable(GL_TEXTURE_2D);
      Texture tex = TextureStorage.getTexture("gui.inventory");
      tex.bind(); // newdawn.slick (same library for my whole program, so this works)
  
      float hw = 170; // half width
      float hh = 163; // half height
  
      Vector2f _texPosUpLeft = new Vector2f(3, 0);
      Vector2f _texPosDownRight = new Vector2f(_texPosUpLeft.x + hw, _texPosUpLeft.y + hh);
  
      _texPosUpLeft.x /= tex.getTextureWidth();
      _texPosUpLeft.y /= tex.getTextureHeight();
      _texPosDownRight.x /= tex.getTextureWidth();
      _texPosDownRight.y /= tex.getTextureHeight();
  
      glColor3f(1, 1, 1); // Changes this doesn't make any effect
      glBegin(GL_QUADS);
      glTexCoord2f(_texPosUpLeft.x, _texPosUpLeft.y);
      glVertex2f(-hw, -hh);
      glTexCoord2f(_texPosDownRight.x, _texPosUpLeft.y);
      glVertex2f(hw, -hh);
      glTexCoord2f(_texPosDownRight.x, _texPosDownRight.y);
      glVertex2f(hw, hh);
      glTexCoord2f(_texPosUpLeft.x, _texPosDownRight.y);
      glVertex2f(-hw, hh);
      glEnd();
  }
  </code></pre>
  
  <p>(The texture pack I'm using is CUBISM1.00)</p>