title: OpenGL Rendering 2D in a 3D space
body: <p>Am currently working on a project as part of my coursework and realised I needed to have a HUD to display information to the user, stumbled upon glOrtho and have been trying to use it however am having some issues with it as it's rendering the 2D point at the moment but not the all the 3D objects in the background.
  Have made different functions for drawing 2D and 3D so the main draw function is less cluttered.</p>
  
  <pre><code>void draw3D
  {
     glEnable(GL_DEPTH_TEST);
  
    GLfloat ambientLight[] = {0.3f, 0.3f, 0.3f, 1.0f};
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);
  
    GLfloat lightColor[] = {0.7f, 0.7f, 0.7f, 1.0f};
    GLfloat lightPos[] = {-2 * floorSize, floorSize, 4 * floorSize, 1.0f};
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
    glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
  
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0, (float)resizeWindowW/(float)resizeWindowH, 1.0, 50000000000.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity(); 
    glTranslatef(0.0f, 0.0f, -9.0f);      
  
    Cam.setView();
  
    glColor3f(1.0f, 1.0f, 1.0f);
  
    oldRocket();
    drawEarth();
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>void draw2D()
  {
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    glDisable(GL_TEXTURE_2D);
    //glDisable(GL_LIGHTING);
  
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-windowW/2, windowW/2, -windowH/2, windowH/2, -1000.0, 1000.0);
  
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
  
    drawCrosshair();
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>void drawScene() 
  {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
    draw3D();
    draw2D(); 
  
    //glDisable(GL_CULL_FACE);
    glDisable(GL_TEXTURE_2D); 
    glutSwapBuffers();
  }
  </code></pre>
  
  <p>All it's drawing at the moment is the point in the middle of the screen with a black background, and have been trying to get it to draw properly for some time now with no result.
  Have followed this approach as it worked on rendering the point where as before I just had the black screen.</p>
  
  <ul>
  <li>clean the screen</li>
  <li>3D:
  <ul>
  <li>enable lighting, z-test, etc</li>
  <li>set active matrix mode to projection</li>
  <li>load identity and establish a perspective projection</li>
  <li>set active matrix mode back to modelview</li>
  <li>draw everything 3D</li>
  </ul></li>
  <li>2D:
  <ul>
  <li>disable lighting, z-test, etc</li>
  <li>set active matrix mode to projection</li>
  <li>load identity and establish an ortogonal projection</li>
  <li>set active matrix mode back to modelview</li>
  <li>draw everything 2D</li>
  </ul></li>
  <li>swap buffers</li>
  </ul>
  
  <p>Updated code with the perspective matrix, and it now displays properly.</p>