用于在全屏游戏上画东西,写字。
( d) Z3 C! x9 _# W G6 N$ z8 I# ]
) f0 [; o8 n" G8 m7 D; o% z/ R原文$ t# X- L: C8 V
http://www.gamedev.net/community/forums/topic.asp?topic_id=359319
- @; i' ~, _3 J/ ?
# K7 a9 K' t% T! ^+ VA 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.
& Z: g6 i) E, h
5 S+ {3 A; L0 [The 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.
8 @3 [+ ^6 ~5 T I. C6 g' G3 p: W7 R4 K
Back to the sample. The files of interest are: w- U+ p' l- W0 J+ o0 N# [7 E# B2 K
Overlay.cpp: Window creation (auto-generated, nothing interesting) and the main loop (important).
( S2 U; Q$ n6 w. w4 u, H; o1 j* \overlay_renderer.h, overlay_renderer.cpp: The core of the sample. The code is fairly self-explanatory, though.
+ U# T( W: b, \) o& f% g2 @4 O9 s+ y: V+ g0 W2 v+ B
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:
3 ]: @1 t3 Q; Z4 _. f5 C% o/ hdwAlignBoundarySrc
; U9 L9 L7 o3 p$ N4 xdwAlignSizeSrc. _) t- W! |- i6 d% X1 X. |
dwAlignBoundaryDest) U) y4 {; K1 R/ g- a/ q3 R( Z, l
dwAlignSizeDest
5 D* P! e; W, m0 D2 F# hdwAlignStrideAlign 5 v, n( r+ E; H) A' ?
dwMinOverlayStretch 2 ]/ i. \5 F/ z( h- T7 G4 l p( M9 i' C
dwMaxOverlayStretch7 C& L, i! R& U1 Y
; l# n4 ~# g4 n
The 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.
4 E |5 O% |/ ~& h, F* y. H% | C/ n6 @- C+ @# K
The limitations (and overlays in general) are documented under “DirectDraw->DirectDraw Essentials->Surfaces->Overlay Surfaces” in the DX7 documentation. It’s available at icarusIndie.& v- O4 G& U) T5 @# b0 ?
) P( V; L& V: E) V% i1 l
I might write a managed port, if someone’s interested. All feedback’s welcome. |