What is the best way to draw a 2D image directly on a window which I hooked the SwapBuffers (gdi32.dll) function, without changing the existing state?

I am currently doing this:

  1. Get current matrix mode
  2. glPushAttrib(GL_ALL_ATTRIB_BITS)
  3. glViewport(0, height - 64, 64, 64)
  4. Disable a bunch of things
  5. glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.5f);
  6. Switch to projection matrix, push, loadidentity
  7. Switch to modelview matrix, push, loadidentity, glOrtho
  8. glRasterPos
  9. glDrawPixels to draw the image with alpha
  10. Restore matrices and attributes
  11. Back to original matrix mode


The reason behind this is that I am trying to draw a fps counter on the top-left corner of the window, just like Fraps or other game recording program. Although I'm not familiar with OpenGL, I believe that using texture on a quad will change the state so I can't use texture.

The drawing of the fps number happens directly before calling `SwapBuffers` in my hook.

Is there a faster/better approach than what I'm doing?