How do I do 2D graphics in OpenGL?

like i can draw stuff in 3d but what if i want to draw like a life bar on the screen? how do i do that?

ommit the z values in your vertices and you end up in the 2D plane

glVertex2f(x,y) is short for glVertex3f(x,y,0.0f)

a lifebar is some sort of rectangle or circle …

Also use from the gluOrtho2D() rather than the glOrtho(), gluPerspective() or glFrustum().Although you can get a correct result with the functions glOrtho(), gluPerspective() or glFrustum(), but gluOrtho2D() is specific for 2D drawing.
Use from the glVertex2*()rather than the glVertex3*(). As an example, glVertex2f(x,y) is short for glVertex3f(x,y,0.0f).