Threaded View

The best way to draw a 2D image directly on a hooked window

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:

Get current matrix mode

glPushAttrib(GL_ALL_ATTRIB_BITS)

glViewport(0, height - 64, 64, 64)

Disable a bunch of things

glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.5f);

Switch to projection matrix, push, loadidentity

Switch to modelview matrix, push, loadidentity, glOrtho

glRasterPos

glDrawPixels to draw the image with alpha

Restore matrices and attributes

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.