用于在全屏游戏上画东西,写字。1 B$ k: G7 Y5 I( l% Z7 c% y
+ ]/ Y0 I( J- T- `/ J" v1 j原文2 {6 V# o. ]4 c p ^' d+ s' X
http://www.gamedev.net/community/forums/topic.asp?topic_id=3593196 L" ~- n/ T+ `" f
6 X+ Y! b- c3 F- f/ a( k) ^8 c! \
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./ [, O2 h& a& S' g
3 [& N d, A5 Y j* ZThe 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.5 ]& k0 O8 p1 Q" N* L$ F/ Y
2 B' X9 `9 I5 f0 V
Back to the sample. The files of interest are:
& s; x) a6 q- \" gOverlay.cpp: Window creation (auto-generated, nothing interesting) and the main loop (important).
4 H/ O0 P8 l* S6 {2 A: woverlay_renderer.h, overlay_renderer.cpp: The core of the sample. The code is fairly self-explanatory, though.
$ W2 y+ i6 h* g0 t0 n
8 R3 O; p0 O: w( HOne 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:
. Q5 F9 j; v, c5 d! |: A; J kdwAlignBoundarySrc. l8 W9 L9 q t0 o$ Q; C
dwAlignSizeSrc2 \) h4 _2 {: ?; T7 b2 C
dwAlignBoundaryDest" z2 s4 ]4 s& Y/ b4 p5 E
dwAlignSizeDest
- Q/ X' S) ]& XdwAlignStrideAlign
. s. ~/ U7 m/ T, z3 \( t' A5 JdwMinOverlayStretch
' a$ t! q/ @ u( t5 jdwMaxOverlayStretch& C1 X! M9 n5 z; \8 ^+ {& Y
3 B; {) X% Y: o! w0 j/ k
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.$ Y: \5 N& ]2 C5 d3 e, i
; Q; [ g1 `: M: J4 _( H: x# xThe limitations (and overlays in general) are documented under “DirectDraw->DirectDraw Essentials->Surfaces->Overlay Surfaces” in the DX7 documentation. It’s available at icarusIndie.
5 X3 `2 t; J! z$ L c
& T5 ]* K/ ]/ X4 g' _0 DI might write a managed port, if someone’s interested. All feedback’s welcome. |