Display 2D image overtop of 3D scene


I’ve just started working with OpenGL, and I’m using Java to write a simple 3D first-person game. What I’m trying to do right now is draw a 2D image over the 3D scene, so it’s always displayed on the screen no matter where the camera is pointing. Essentially, I want something like a 2D life-meter bar or current score to be overlaid like you see in games like GTA or Duke Nukem, except I don’t need to draw text… I just want to load a small .png file and stick it on the corner of the screen. Does anyone have a piece of code or example of how to do this? (BTW, the OpenGL code in Java is almost identical to C++, so an example in C++ would be fine)


An outline :

setup projection matrix for 3D scene
draw 3D scene
setup projection matrix for 2D scene (glOrtho for example)
draw 2D scene (just a small quad textured with the .png)

I’ve been trying to do that, but haven’t been successful… but at least I know I’m on the right track.


Implementation details :


Oh, sorry if this sounds ignorant, but how do I swap buffers?