用于在全屏游戏上画东西,写字。
2 f: D6 N! u5 W4 b/ | Q# S. @& z: X; E
0 u" e/ C" r' P( S1 P' x. l" d原文
( V" k; L( }) T1 I+ yhttp://www.gamedev.net/community/forums/topic.asp?topic_id=359319
) L, `7 k* q6 F. _5 E% X- b( H7 Y5 ~! f( a7 ~2 J+ Q$ v' O
A 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.
! I- G2 m& Q p l6 O% g
! t8 O6 d8 z+ E' D7 A; @, W: ~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.
a1 h+ Z8 M7 t, g( r5 [' b& E' O
Back to the sample. The files of interest are:4 O; c, J, E" N+ J5 y
Overlay.cpp: Window creation (auto-generated, nothing interesting) and the main loop (important).: M$ ?" o5 ^) Z* |
overlay_renderer.h, overlay_renderer.cpp: The core of the sample. The code is fairly self-explanatory, though.; Z) q, M, [2 l7 o" p
# e9 P/ p0 @( {# S& _4 POne 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:
9 t! u2 e! _2 |, v6 tdwAlignBoundarySrc* J# Y6 V% P' V5 M G6 O, j
dwAlignSizeSrc4 }. E" p c9 ^; S, n
dwAlignBoundaryDest
: C4 I% u4 t+ edwAlignSizeDest: Y2 ~' M8 p/ U" P+ C
dwAlignStrideAlign
: {' c/ q: E; r) k# NdwMinOverlayStretch
B) E( U _! i, u: NdwMaxOverlayStretch2 {. {6 ]3 b; ?7 v9 T3 [$ O" B% s
V+ p7 g. R8 _/ K J: EThe 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.
, A- T- E* m4 i( S$ [# }
+ W; g& `5 ~) o( S) I$ zThe limitations (and overlays in general) are documented under “DirectDraw->DirectDraw Essentials->Surfaces->Overlay Surfaces” in the DX7 documentation. It’s available at icarusIndie.( V& i/ s0 ^8 i
* J# {$ t% x- F: T& d' nI might write a managed port, if someone’s interested. All feedback’s welcome. |