draw over opengl/D3D with GDI?
I'm wondering if it's possible to draw over an opengl/direct3D surface with GDI? and if so, how might it be done?
The reason I ask is because I'm writing a simple app to draw a few things in games. Such things would all be 2D or text such as framerate info, custom crosshair, clock, etc.
I know the best way is to hook in and use whatever the开发者_JAVA技巧 renderer/game is using natively, be it opengl or direct3d, but I'm looking at GDI as AFAIK both opengl and D3D sit on device contexts which I'm hoping can be draw to with GDI.
You can't usually do it directly.
In theory, you can intermix GDI with OpenGL or DirectX if and only if the OpenGL/DirectX drawing is done with single buffering, not double buffering. That, however, is little more than a theoretical possibility, because virtually all use of DirectX and OpenGL is with double buffering.
I'd try something else, such as drawing your data in a borderless layered window.
You can draw with GDI in a central memory buffer with CreateCompatibleDC, CreateCompatibleBitmap, SelectObject and GetDIBits. Beware: Compatible DC are slow (no 2D acceleration). Then, you must copy (slow operation) from central memory to a texture.
For text, you may copy all ASCII characters once into a texture, and then, use D3D texture functions to copy each character. It should be easy enough for monospace US-ASCII fonts.
精彩评论