用于在全屏游戏上画东西,写字。: C& I& `% C- P( I6 }
5 c( c2 t- ?* P
原文
+ d) }3 P/ {8 w X8 Ghttp://www.gamedev.net/community/forums/topic.asp?topic_id=359319; t! U( N: e: y7 k. @
% S1 ]1 {& V. O) YA lot of people seem interested in knowing how to render content over full-screen applications, like XFire and Co, judging by the number of posts about it. Here’s an unmanaged overlaying sample. Visual Studio 2003 and 2005 solutions are included.
1 c. l8 C* h2 O* E, F
5 T" u) m9 A: l8 C) jThe sample uses DirectDraw overlays to render a black 256x64 box to the top-left of the screen, with some text in it. I would’ve shown you a screenshot, but I can’t, due to the way overlays work. Overlays are displayed as the device is painting the monitor from the primary surface. If it’s painting a location where an overlay exists, it paints the monitor with its color instead of the primary surface. Consequently, you can’t capture that in an image.
0 X _) y/ ~, I8 ^1 \ |4 t1 O1 L' L7 t
Back to the sample. The files of interest are:
2 w/ k p/ Q' h1 P; B2 u5 F. A5 ^) p, bOverlay.cpp: Window creation (auto-generated, nothing interesting) and the main loop (important).$ G' x) M- | R$ K) t6 {
overlay_renderer.h, overlay_renderer.cpp: The core of the sample. The code is fairly self-explanatory, though.
- w8 ^& @6 q/ m% ~# w9 o
& n/ q' X. @- L; N# y0 M+ {One important thing to keep in mind is that overlay support comes with a set of limitations. The following limitations are not checked or accounted for in the sample:
0 }! E1 o& {) v8 p1 {. Q( Y5 }! \dwAlignBoundarySrc
$ ?# U, p- Q* _. d1 Y- [3 W0 ?+ qdwAlignSizeSrc
, ^/ h$ d% y* gdwAlignBoundaryDest7 C6 w _# T; ~0 m7 t
dwAlignSizeDest
) a- q: R g7 wdwAlignStrideAlign * D4 P. S7 ?/ \4 h
dwMinOverlayStretch 9 `3 x! V* s: l- f
dwMaxOverlayStretch
& n) Q$ t: ~7 ]$ n" o& E( S8 h+ t
4 ~; E8 r" s5 o! h$ gThe limitations are hardware-dependent. For example, my X300 doesn’t impose any alignment restrictions for the source or destination overlay rectangles. In a product, however, you’d want to make sure you check for these and abide by them. Use CapsViewer to find out the limitations of your hardware quickly. I don’t know if the October SDK caps database includes DirectDraw caps or not, but consider checking it out.
- e3 n }, ~8 v: v3 ^2 m/ `8 p$ P. p1 ~( d& M' C8 ^
The limitations (and overlays in general) are documented under “DirectDraw->DirectDraw Essentials->Surfaces->Overlay Surfaces” in the DX7 documentation. It’s available at icarusIndie.6 a$ i" R/ X4 c7 x1 e# r
% v) g, D1 q+ B8 |) E: x
I might write a managed port, if someone’s interested. All feedback’s welcome. |