home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / vrac / agames.zip / AGAMES.ASC next >
Text File  |  1994-09-30  |  120KB  |  2,366 lines

  1.  
  2.                Microsoft Windows Multimedia                     6
  3.  
  4.  
  5.  
  6.  
  7. Writing HOT Games
  8. for Microsoftr WindowsÖ
  9.  
  10.  
  11. The Microsoft Game Developers' Handbook
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19. Microsoft WindowsÖ Multimedia
  20. 10/94
  21. Table of Contents
  22.   
  23.                
  24.                Table of Contents                                3
  25.                
  26.                Microsoft Windows Multimedia                     5
  27.                     We're serious about games                   5
  28.                     Millions of new 32-bit game machines on the
  29.                       way!                                     5
  30.                     It ain't over yet                           5
  31.                
  32.                The Windows Market                               7
  33.                
  34.                Windows 95 as a Game Platform                    9
  35.                  1 Fast, Flexible Graphics                     9
  36.                     WinG overview:                              9
  37.                     Other graphic enhancements                 10
  38.                  2 Easy to Support                            10
  39.                  3 Powerful Development Environment           10
  40.                  4 Built-in Digital Video Support             11
  41.                  5 High Quality, Flexible Sound               11
  42.                  6 Support for Multi-player Games             12
  43.                  7 Synchronization                            12
  44.                  8 Toys                                       13
  45.                  9 3D for Windows                             13
  46.                
  47.                Appendix A:  PRELIMINARY WinG Documentation     15
  48.                  Why WinG?                                    15
  49.                  Off-screen Drawing With WinG                 15
  50.                  Using GDI With WinGDCs                       16
  51.                  Halftoning With WinG                         17
  52.                  Maximizing Performance With WinG             17
  53.                     10.  Take Out Your Monochrome Debugging Card17
  54.                     9.  Store WinGBitmap Surface Pointer and
  55.                       BITMAPINFO                              17
  56.                     8.  Don't Make Redundant GDI Calls         18
  57.                     7. Special Purpose Code May Be Faster Than
  58.                       GDI                                     18
  59.                     6. Time Everything, Assume Nothing
  60.                       (Ruminations on good coding practices)  18
  61.                     5.  Don't Stretch                          18
  62.                     4.  Don't Blt                              18
  63.                     3.  Don't Clip                             18
  64.                     2.  Use an Identity Palette                19
  65.                     1.  Use the Recommended DIB Format         19
  66.                  DIB Orientation                              19
  67.                     Top-Down DIBs                              20
  68.                  Using an Identity Palette                    21
  69.                     Static Colors                              22
  70.                     Other Colors                               22
  71.                     Creating an Identity Palette               22
  72.                  Palette Animation With WinG                  24
  73.                  Accessing a Full Palette Using SYSPAL_NOSTATIC25
  74.                  WinGBitBlt                                   28
  75.                  WinGCreateBitmap                             28
  76.                  WinGCreateDC                                 31
  77.                  WinGCreateHalftoneBrush                      31
  78.                  WinGCreateHalftonePalette                    32
  79.                  WinGGetDIBColorTable                         33
  80.                  WinGGetDIBPointer                            33
  81.                  WinGRecommendDIBFormat                       34
  82.                  WinGSetDIBColorTable                         35
  83.                  WinGStretchBlt                               35
  84.                  WING_DITHER_TYPE                             36
  85.                  Debugging WinG Applications                  37
  86.                  Shipping a Product With WinG                 37
  87.                  Code Samples                                 37
  88.                  Balloon Doggie Sample                        38
  89.                  Spinning Cube Sample                         38
  90.                  WinG Timing Sample                           39
  91.                  WinG Halftoning Sample                       39
  92.                  WinG Palette Animation Sample                39
  93.                  WinG Glossary                                40
  94.                  Further Reading                              40
  95.                  
  96. Microsoft Windows Multimedia
  97.   
  98.                Microsoft is committed to making Windows a leading
  99.                force in multimedia technologies and systems.
  100.                  Our commitment takes many forms, but the most
  101.                important one for independent software vendors is
  102.                our commitment to substantial and ongoing
  103.                investment in multimedia-related R&D.  In this
  104.                handbook we explain some new innovations in
  105.                Windows that will be of particular interest to
  106.                game developers.
  107.           
  108.           We're serious about games
  109.                For the past year, the home market has been the
  110.                fastest-growing segment of the PC business.  More
  111.                and more of our customers are telling us that they
  112.                want games for Windows  and at this point, there
  113.                aren't many.  Games are already the largest
  114.                category of multimedia application, but most of
  115.                today's computer games are running on MS-DOSr.  In
  116.                fact, at the end of 1993 computer games were one
  117.                of the last remaining software categories for
  118.                which Windows product sales trailed MS-DOS product
  119.                sales.
  120.                  Not that this should come as any surprise.
  121.                Until now, game graphics under Windows made slug
  122.                racing look exciting.
  123.                  The only way for Windows to succeed as a game
  124.                platform is for developers to write great games
  125.                for it.  This Handbook is designed to help you do
  126.                that.  And the WinG library delivers graphics
  127.                performance approaching raw MS-DOS speeds.
  128.           
  129.           Millions of new 32-bit game machines on the way!
  130.                There are over 100 million MS-DOS based personal
  131.                computers in the world  and over 40 million of
  132.                those are running Windows.  The home PC market is
  133.                growing fast, and a very large portion of the
  134.                machines being sold into homes are equipped with
  135.                the kinds of devices that should make game
  136.                developers smile:  CD-ROM drives, sound
  137.                subsystems, and 4MB of RAM or more.
  138.                With the release of Windows 95, a GIANT new 32-bit
  139.                game platform will be born.
  140.                This handbook:
  141.                1 explains some of the new features and
  142.                  capabilities of Windows 95 that make it
  143.                  possible for you to write great games for the
  144.                  world's next PC operating system; and
  145.                2 introduces the WinG libraries, a development
  146.                  tool that you can use to write high-performance
  147.                  graphical games for Windows today.
  148.           
  149.           It ain't over yet
  150.                It's important to emphasize that the technologies
  151.                described in this handbook aren't the end of the
  152.                story.  Quite the contrary  we've made some very
  153.                important first steps, but there's a lot of work
  154.                to be done in the years ahead.  Please tell us how
  155.                we can make Windows a great platform for your
  156.                games!
  157.  
  158.                We've invested a lot of effort making Windows into
  159.                the leading environment for "serious"
  160.                applications.
  161.                Now comes the fun part!
  162.  
  163.                To send a suggestion to the Microsoft Windows
  164.                Multimedia team, GO WINMM in CompuServer or send
  165.                email to mmdinfo@microsoft.com.
  166.  
  167.                
  168.                
  169.                Microsoft, MS-DOS and Visual Basic are registered
  170.                trademarks and Windows is a trademark of Microsoft
  171.                Corporation.
  172.                CompuServe is a registered trademark of
  173.                CompuServe, Inc.
  174.                VoiceView is a trademark of Radish Communications,
  175.                Inc.
  176.  
  177. The Windows Market
  178.   
  179.                  
  180.                It has now been over four years since the release
  181.                of Windows 3.0, and the software market is greatly
  182.                changed.  For example:
  183.                ·  The majority of new PCs sold now come with
  184.                  Microsoft Windows pre-installed.
  185.                ·  Virtually every PC peripheral and add-in board
  186.                  on the market (including sound cards) ships
  187.                  with drivers and installation instructions for
  188.                  use with Microsoft Windows.
  189.                ·  In virtually every software category (with the
  190.                  exception of games), sales of software for
  191.                  Windows outpace sales of software for MS-DOS.
  192.                Windows is a growing, active platform, and coming
  193.                developments will help to make it more so. Windows
  194.                95 is the name for the next version of Windows.
  195.                Analysts who have reviewed Windows 95 in its
  196.                prerelease form are already concluding that this
  197.                new operating system will be the biggest news to
  198.                come from Microsoft since the release of Windows
  199.                3.0.
  200.                  Until recently, the Windows-based personal
  201.                computer hardware and software businesses focused
  202.                almost exclusively on the office desktop.  That
  203.                focus is broadening rapidly:
  204.                ·  Home PCs are the fastest-growing category of
  205.                  the PC hardware business, and home buyers are
  206.                  demanding multimedia capabilities in their PCs.
  207.                ·  Laptop and notebook computers are an
  208.                  increasingly important share of the business,
  209.                  and they are helping to establish the modem as
  210.                  a standard PC device.
  211.                ·  Non-business software categories (including
  212.                  games) are rapidly growing into the multi-
  213.                  billion dollar range.
  214.                These trends show no signs of stopping.  As PCs
  215.                become an increasingly common appliance in the
  216.                home, we can count on the following corollaries:
  217.                ·  The average level of computer knowledge among
  218.                  home users will decline.
  219.                ·  The market will favor ease of installation and
  220.                  ease of use as features of home software
  221.                  products.  Products that are obnoxious or scary
  222.                  to install won't sell well in the broad home
  223.                  market.
  224.                These forces will help support the continued
  225.                success of Windows software in the home market,
  226.                which presents an important opportunity for the
  227.                game development community.  There are millions of
  228.                PCs with Windows in homes today, and relatively
  229.                few Windows-based games.  The market forces above
  230.                make it pretty clear that there's a big market out
  231.                there, waiting for the right Windows-based game
  232.                products to come along.
  233.                Got any ideas?
  234.                  
  235. Windows 95 as a Game Platform
  236.   
  237.                  
  238.                  This chapter describes some (not all!) of the
  239.                features of Windows 95 that will make it an
  240.                important release for you as a game developer.  In
  241.                the case of our work on graphics speed, this
  242.                chapter also describes how WinG makes it possible
  243.                for games to smoothly transition to Windows 95
  244.                while maintaining compatibility with Windows 3.1
  245.                today.
  246.                  This document is an overview of our technology
  247.                and development plans as they relate to games.
  248.                Further technical articles about implementing
  249.                games on Windows can be found in the Microsoft
  250.                Developer Network.  (For a subscription, call
  251.                Microsoft at 1-800-759-5474.  Outside the US and
  252.                Canada, call 402-691-0173 for a distributor in
  253.                your country.)
  254.                  Naturally, we are interested in your input in
  255.                all of these areas, as we are very committed to
  256.                making Windows the best game operating system
  257.                possible.  The best way to reach us is through the
  258.                new CompuServe forum for game developers   GO
  259.                WINMM.  Or send email to mmdinfo@microsoft.com.
  260.                Discussed here are the following topics:
  261.                1 Fast, Flexible Graphics
  262.                2 Easy to Support
  263.                3 Powerful Development Environment
  264.                4 Built-in Digital Video Support
  265.                5 High Quality, Flexible Sound
  266.                6 Support for Multi-player Games
  267.                7 Synchronization
  268.                8 Toys
  269.                9 3D for Windows
  270.  
  271. 1    Fast, Flexible Graphics
  272.                The speed of graphics (or, more appropriately, the
  273.                lack of it) in Windows 3.1 has been the most
  274.                important obstacle keeping game developers from
  275.                choosing the Windows platform for their games.  We
  276.                have addressed this issue head-on in a way that
  277.                provides substantially improved speed while
  278.                preserving the device independence that makes
  279.                Windows appealing in the first place with a new
  280.                graphic library called WinG.
  281.                  WinG provides close to the graphic performance
  282.                of MS-DOS based games with all of the device
  283.                independence of Windows.  (For detailed
  284.                information about the WinG library, see Appendix
  285.                A)
  286.           
  287.           WinG overview:
  288.                Fast graphics.  Blts directly to the frame buffer
  289.                from Device Independent Bitmaps in memory,
  290.                allowing performance approaching raw MS-DOS speed
  291.                on any given Windows compatible computer.
  292.                Compatible with Windows 3.1 and Windows NT.  Runs
  293.                across Microsoft operating systems, including the
  294.                millions of copies of Windows 3.1 installed today,
  295.                and uses the fastest available blting mechanism on
  296.                each OS.
  297.                Color.  WinG is optimized for all color depths and
  298.                graphics resolutions under Windows 95 and Windows
  299.                NT.  For WinG on Windows 3.1, MS-DOS-class graphic
  300.                performance is optimized for 256-color source
  301.                animation.
  302.                Free.  The WinG library will be freely available
  303.                to developers and redistributable at no cost. This
  304.                library will be available on CompuServe in the
  305.                WINMM forum by the end of May, 1994.
  306.                32 bit.  WinG will be available in both 16- and 32-
  307.                bit versions, allowing you to create full Win32
  308.                games.
  309.           
  310.           Other graphic enhancements
  311.                Windows 95 games will also be able to take
  312.                advantage of the following enhancements to the
  313.                operating system:
  314.                On-the-fly control of screen resolution makes it
  315.                  possible to dynamically configure the display
  316.                  to achieve optimal speed and graphics quality
  317.                  for your game.
  318.                Offscreen buffering and other hardware-level video
  319.                  functionality not accessible in Windows 3.1
  320.                  will also be supported in Windows 95.
  321.                Device-independent color support in Windows 95
  322.                  will allow you to ensure that your graphic
  323.                  colors are consistent across all different
  324.                  types of video cards and displays.
  325.  
  326. 2    Easy to Support
  327.                Every support call might as well be a lost sale.
  328.                  Providing customer support for games  or any
  329.                software, for that matter   is very, very costly.
  330.                In fact, the margin that game developers typically
  331.                make from the sale of a game are generally low
  332.                enough that the cost of one support call for
  333.                installation or configuration can actually
  334.                eliminate the profit earned from that sale.
  335.                  Developing your game for Windows 95 and/or
  336.                Microsoft Windows 3.1 will help you decrease
  337.                support costs in four ways:
  338.                ·  Windows memory management busts the 640K
  339.                  conventional memory barrier for you, gives you
  340.                  up to gigabytes' worth of linear 32-bit
  341.                  addressable memory and eliminating the need to
  342.                  fiddle with customers' CONFIG.SYS file during
  343.                  setup.  A huge portion of all support calls
  344.                  relate to setup.
  345.                ·  Windows device independence frees you from a
  346.                  lot of card-specific coding  and support.  Use
  347.                  the standard Windows APIs and your product will
  348.                  work with all Windows-compatible devices.
  349.                ·  Not your dime.  Importantly, if you've written
  350.                  your game for Windows and your user's sound
  351.                  card doesn't go "whoooosh!" when it ought to do
  352.                  so, your game isn't the culprit.  Microsoft (or
  353.                  the sound card maker) gets the phone call, not
  354.                  you.
  355.                ·  In Windows 95, a new feature called Plug and
  356.                  Play will make it easier for users to add
  357.                  devices  such as CD-ROM drives or sound cards
  358.                  to their systems.  This will help to further
  359.                  increase the market for games, facilitate
  360.                  upgrades, and take support pressure off of game
  361.                  developers.
  362.                Windows offers device-independent support for:
  363.                ·  CD-ROM drives
  364.                ·  Sound cards
  365.                ·  Video Displays
  366.                ·  Digital video acceleration boards (including
  367.                  MPEG)
  368.                ·  Printing
  369.                ·  Networking
  370.                ·  Modem
  371.                ·  Joystick, and
  372.                ·  Pointing devices including the mouse (of
  373.                  course)
  374.  
  375. 3    Powerful Development Environment
  376.                The tools for writing Windows code have evolved
  377.                greatly over the last few years. We aren't saying
  378.                that your job is in danger  the code doesn't write
  379.                itself.  But some of the least rewarding parts
  380.                have been substantially automated, and there are
  381.                good tools now available to help you write code
  382.                that you can reuse from one project to the next.
  383.                For example:
  384.                ·  Microsoft Visual C++.  Provides a fully
  385.                  integrated graphic development environment for
  386.                  Windows applications that makes it simple to
  387.                  create a GUI application utilizing
  388.                  sophisticated functionality such as networking,
  389.                  WinG, Object Linking and Embedding, sound,
  390.                  digital video, and so forth.
  391.                ·  Object Linking and Embedding (OLE) is an object
  392.                  technology made available for all Microsoft
  393.                  operations systems and the Mac that greatly
  394.                  facilitates the exchange of information and
  395.                  functionality between unrelated applications.
  396.                  The availability of this technology creates
  397.                  game possibilities previously unimaginable in
  398.                  the MS-DOS world, such as:
  399.                ·  Drag & Drop monsters from one game space to
  400.                  another;
  401.                ·  provide standard interfaces that others can use
  402.                  to develop or extend functionality for your
  403.                  game worlds;
  404.                ·  embedding game sessions into mail messages that
  405.                  can automatically connect you over a network or
  406.                  modem, etc.
  407.  
  408. 4    Built-in Digital Video Support
  409.                For the past several years, Microsoft has been
  410.                developing a high-performance architecture for
  411.                digital video  Microsoft Video for Windows.
  412.                  In the past, Microsoft Video for Windows has
  413.                been sold separately (principally as a Software
  414.                Developers' Kit).  With the release of Windows 95,
  415.                it will be built right into the operating system.
  416.                For the first time, the ability to play digital
  417.                video will ship with every copy of Microsoft
  418.                Windows.
  419.                  If you include digital video in your game,
  420.                Windows can play it back for your customers,
  421.                regardless of the display board that the customer
  422.                may have installed.  Your customers don't need
  423.                special hardware to play your game  any VGA card
  424.                will do.
  425.                  More information on Microsoft Video for Windows
  426.                is available on MSDN and in the Microsoft Video
  427.                for Windows software developers kit.
  428.  
  429. 5    High Quality, Flexible Sound
  430.                Microsoft Windows offers device independent sound
  431.                allowing applications to call standard APIs to
  432.                drive sound boards without worrying about the
  433.                hardware-specific details.  The high-level MCI
  434.                sound APIs make it relatively straightforward to
  435.                play a given sound with minimal coding effort.
  436.                The low-level WAV APIs provide more precise
  437.                control over arbitrary digital sound.  MIDI APIs
  438.                are also provided.
  439.                  For mixing sound, Microsoft offers a library
  440.                called WAVEMIX.DLL, which can merge up to four
  441.                channels of sound into a single stream on the fly.
  442.                WAVEMIX can be found on CompuServe and on the
  443.                Microsoft Windows Multimedia Jumpstart CD.
  444.                  To make the burden of storing and playing sound
  445.                less onerous, Windows 95 includes a family of
  446.                sound compression technologies ("codecs").  These
  447.                codecs can be divided into two groups:
  448.                ·  Music-oriented codecs (such as IMADPCM) are
  449.                  included that allow close to CD-quality sound
  450.                  to be compressed to about one-quarter size.
  451.                ·  Voice-oriented codecs (such as TrueSpeech) are
  452.                  included to allow very, very efficient
  453.                  compression of voice data.
  454.                This support for compressed sound is two-way  you
  455.                can play sound from a compressed sound file, or
  456.                you can compress a sound file (using the built-in
  457.                sound recording and editing utility).  If you have
  458.                a microphone, you can turn on voice compression
  459.                when recording so that your file is compressed in
  460.                real-time.
  461.  
  462. 6    Support for Multi-player Games
  463.                The much-touted information superhighway holds
  464.                great promise in lots of areas, but one of the
  465.                least controversial is the opportunity it might
  466.                provide for cool multi-player games.  Why wait for
  467.                the information superhighway?  Windows 95 offers
  468.                two technologies that make Windows-based multi-
  469.                player games viable right away:
  470.                ·  Networks offer great promise for multi-player
  471.                  games, but network support has been added to
  472.                  relatively few MS-DOS-based games today.  This
  473.                  is principally for technical reasons  there are
  474.                  scores of different network hardware and
  475.                  software challenges, and even getting a game to
  476.                  run can be frustrating and expensive to
  477.                  support.  It's much, much simpler in Windows
  478.                  you don't have to write the networking code,
  479.                  you don't have to work around the network's
  480.                  memory space, and you don't have to take the
  481.                  network support calls.  A Windows technology
  482.                  called WinSockets makes it possible to write
  483.                  games for a broad variety of network types
  484.                  including Novell, Banyan Vines, Windows for
  485.                  Workgroups, LAN Manager, TCP/IP and others
  486.                  without worrying about which one is in use.
  487.                ·  Modems.  In addition to easy modem setup and
  488.                  configuration, Windows 95 provides support for
  489.                  a new modem technology called VoiceViewThis
  490.                  technology lends itself well to games that
  491.                  involve "taking turns,"  and will help to put
  492.                  the appeal of human interaction into modem-
  493.                  based games.
  494.                VoiceView will be shipped as a standard feature of
  495.                virtually every modem in 1995
  496.                  Until now, modem users have had no choice  they
  497.                can either talk on the phone or use their modem,
  498.                but not both.  (If you want to talk, you generally
  499.                have to disconnect the modem and call back, or
  500.                else get a second phone line.)  This makes modem-
  501.                based 2-player games pretty unappealing, because
  502.                talking to your opponent is half the fun, right?
  503.                  With VoiceView, you can play and talk to your
  504.                opponent in the same phone call.  Here's how it
  505.                works:
  506.                ·  Run one phone line from the wall to the "in"
  507.                  port of your VoiceView-capable modem, and
  508.                  another from the "out" port to your phone.
  509.                ·  Turn on your PC and call up your friend (who
  510.                  also has a VoiceView-capable modem).
  511.                ·  Talk for as long as you like.  When you feel
  512.                  like it, launch a 2-player game  we'll use
  513.                  chess as an example.
  514.                ·  When you make a move, you will hear a brief
  515.                  beep, and your modems will take over the phone
  516.                  line for a moment.  (You can't talk while the
  517.                  modems are conversing).  A simple message like
  518.                  a chess move takes less than one second to
  519.                  communicate.
  520.                ·  When you're done (or have to go eat dinner),
  521.                  hang up like you always do.
  522.  
  523. 7    Synchronization
  524.                Synchronization of sound with events is crucial
  525.                for cutting-edge games.  In Windows 95, you can
  526.                write 32-bit games that use threads to manage
  527.                processes that occur simultaneously (such as
  528.                sound, scoring and animation).  In the past, many
  529.                game developers have written their own
  530.                multitasking engines under MS-DOS to build this
  531.                sort of functionality.  The multitasking support
  532.                in Windows 95 will free you from this low-level
  533.                coding so that you can invest more of your effort
  534.                on features.
  535.                  Windows 95 has a default preemptive thread
  536.                scheduling grain of 20 ms, meaning that if there
  537.                are not a lot of other background activities, a
  538.                foreground application (or high-priority thread)
  539.                can be assured of constant and frequent attention
  540.                from the OS.  If that isn't fast enough, it's
  541.                possible to set the grain as fast as 1ms. Windows
  542.                95 provides fine event control and scheduling
  543.                objects that facilitate writing tightly
  544.                synchronized multitasking applications.
  545.                  The ability to manage sound as a separate
  546.                thread of your program allows multimedia titles
  547.                and games to have a more smooth, finished feel to
  548.                them.  For example, a game might have a thread
  549.                that plays background music continuously during
  550.                game play.  This would help smooth out the breaks
  551.                between scenes, when the game is loading new data
  552.                on another thread of the program. Threading
  553.                provides for asynchronous I/O that makes it
  554.                possible to carry on sound and animation while
  555.                hitting the network or file system at the same
  556.                time.
  557.                  Another area of synchronization that is
  558.                important to a successful action game is
  559.                synchronization of input with action.  Again,
  560.                using threading you can control the polling rate
  561.                of input devices and ensure that your game feels
  562.                crisp and responsive. In addition to a thread
  563.                scheduler, Windows 95 also provides access to a
  564.                configurable event timer that can generate clock
  565.                messages at up to 1ms.
  566.  
  567. 8    Toys
  568.                Support for game devices will be built right into
  569.                Windows 95.  Aside from the obvious support for
  570.                the mouse and the keyboard, Windows 95 will also
  571.                include built-in support for joysticks.
  572.  
  573. 9    3D for Windows
  574.                Windows NT (Daytona) will ship with the industry
  575.                standard OpenGL libraries included as a standard
  576.                part of the Windows Graphic API.  We anticipate
  577.                that this will make Windows NT a great authoring
  578.                environment for 3D software.  Microsoft will also
  579.                make the OpenGL libraries available on Windows 95,
  580.                so that the same authoring tools can run on both
  581.                Windows 95 and Windows NT.  To enable the market
  582.                for 3D accelerators, Microsoft will publish the 3D-
  583.                DDI (device driver interface), which will make it
  584.                possible for hardware vendors to accelerate 3D
  585.                graphics for MS-DOS, Windows, and Windows NT. Our
  586.                OpenGL implementation will utilize hardware
  587.                acceleration via the 3D-DDI whenever it is
  588.                available.
  589.                  The 3D DDI is an open interface, enabling other
  590.                3D rendering APIs such as HOOPS and PeX to coexist
  591.                with OpenGL on Windows.  Although general-purpose
  592.                3D libraries are not practical for most games
  593.                today, we hope that our support for OpenGL and the
  594.                3D DDI will rapidly grow the installed base of 3D
  595.                hardware accelerators.
  596.  
  597. Appendix A:  PRELIMINARY WinG Documentation
  598.   
  599.  
  600. Why WinG?
  601.                Although business applications such as word
  602.                processors and spreadsheets have moved
  603.                overwhelmingly to Windows, MS-DOS remains the
  604.                operating system of choice for games. These
  605.                applications have not made the transition to
  606.                Windows largely for performance reasons  in a
  607.                word, speed.  The performance of games under
  608.                Windows has suffered because of restrictions
  609.                placed on the programmer by GDI's device
  610.                independence, by the windowed environment, and by
  611.                the inability of general graphics libraries to
  612.                provide the necessary speed.
  613.                  Most MS-DOS game programmers use knowledge
  614.                specific to their application and their hardware
  615.                to write optimized graphics routines. Until now,
  616.                Windows programmers could not use such methods
  617.                because GDI prevents access to device-specific
  618.                surfaces; programmers can not draw directly onto
  619.                the surface of a GDI device context.
  620.                  WinG (pronounced "Win Gee") is an optimized
  621.                library designed to enable high-performance
  622.                graphics techniques under Windows 3.1, Windows 95,
  623.                and Windows NT.  WinG has been developed as a key
  624.                component of the Microsoft Windows Multimedia
  625.                Initiative.
  626.                  WinG allows the programmer to create a GDI-
  627.                compatible HBITMAP with a Device Independent
  628.                Bitmap (DIB) as the drawing surface. Programmers
  629.                can use GDI or their own code to draw onto this
  630.                bitmap, then use WinG to transfer it quickly to
  631.                the screen. WinG also provides halftoning APIs
  632.                that use the standard Microsoft halftone palette
  633.                to support simulation of true color on palette
  634.                devices.
  635.  
  636. Off-screen Drawing With WinG
  637.                WinG introduces a new type of device context, the
  638.                WinGDC, that can be used like any other device
  639.                context. Unlike other DCs, programmers can
  640.                retrieve a pointer directly to the WinGDC drawing
  641.                surface, its BITMAPINFOHEADER, and its color
  642.                table. They can also create and select new drawing
  643.                surfaces for the WinGDC or modify the color table
  644.                of an existing surface. DIBs become as easy to use
  645.                as device-specific bitmaps and compatible DCs, and
  646.                programmers can also draw into them using their
  647.                own routines.
  648.                  Most often, applications will use WinGCreateDC
  649.                to create a single WinGDC and will use
  650.                WinGCreateBitmap to create one or more WinGBitmaps
  651.                into which they compose an image. The application
  652.                will typically draw into this buffer using DIB
  653.                copy operations, GDI calls, WinG calls, and custom
  654.                drawing routines, as shown here.
  655.                                                                  
  656.                                                                  
  657.                A double-buffering architecture for WinG
  658.                Once DIB composition  for the current frame is
  659.                complete, the application will copy the WinGDC
  660.                buffer to the screen using WinGStretchBlt or
  661.                WinGBitBlt. This double-buffering architecture
  662.                minimizes flicker and provides smooth screen
  663.                updates.
  664.                  Many games and animation applications draw
  665.                their characters using sprites. On arcade
  666.                machines, sprite operations are performed in
  667.                hardware. Under DOS with a VGA, games simulate
  668.                sprite hardware using transparent blts into an off-
  669.                screen buffer. The DOGGIE sample application (in
  670.                the SAMPLES\DOGGIE directory of the WinG
  671.                development kit) uses WinG in the same way to
  672.                perform transparent blts to a WinGDC and includes
  673.                source code for an 8-bit to 8-bit
  674.                TransparentDIBits procedure.
  675.  
  676. Using GDI With WinGDCs
  677.                WinG allows drawing onto the DIB surface of a
  678.                WinGDC with GDI, but there are some anomalies to
  679.                keep in mind.
  680.                1 Most importantly, GDI does NOT regard WinGDCs
  681.                  as palette devices. WinGDCs are actually RGB
  682.                  devices with a fixed 256-color color table. You
  683.                  happen to be able to modify the device color
  684.                  table using the WinGSetDIBColorTable API, but
  685.                  the color table is considered static by GDI.
  686.                  You can't select or realize palettes in a
  687.                  WinGDC. The Palette Animation With WinG article
  688.                  describes how to match a given palette to a
  689.                  WinGDC color table.
  690.                2 Drawing with GDI on a WinGDC surface does not
  691.                  always produce a pixel-perfect duplicate of the
  692.                  image you would see using GDI on a display
  693.                  device. The images will be similar, but some
  694.                  stray pixels will remain if you XOR the two
  695.                  images together.
  696.                Brushes realized in a WinGDC will be aligned to
  697.                the upper left corner of the WinGDC whereas
  698.                brushes used in screen DCs are aligned to the
  699.                upper left corner of the screen. This means that
  700.                when you blt a WinGDC that has been filled with a
  701.                pattern into a screen DC that has been filled with
  702.                the same pattern, the patterns will not
  703.                necessarily align correctly.
  704.                  If you have this problem, you can either change
  705.                the brush origins and re-realize the brushes in
  706.                either DC (see the section "1.6.8 Brush Alignment"
  707.                in the Windows SDK Programmer's Reference Volume
  708.                1, also available on the Microsoft Developer
  709.                Network CD) or you can make off-screen brushes
  710.                align correctly with on-screen brushes by blting
  711.                the WinGDC to a brush-aligned position on the
  712.                screen. For example, an 8x8 brush pattern can be
  713.                correctly aligned to the screen by blting the
  714.                WinGDC to an x, y position when x and y are both
  715.                multiples of 8.
  716.  
  717. Halftoning With WinG
  718.                WinG allows applications to simulate true 24-bit
  719.                color on 8-bit devices through the WinG halftoning
  720.                support APIs, WinGCreateHalftonePalette and
  721.                WinGCreateHalftoneBrush.
  722.                  The halftone palette is an identity palette
  723.                containing a carefully selected ramp of colors
  724.                optimized for dithering true color images to 8-bit
  725.                devices. The WinGCreateHalftonePalette function
  726.                returns a handle to a halftone palette which
  727.                applications can select and realize into a display
  728.                device context to take advantage of the halftoning
  729.                capabilities offered by WinG.
  730.                  The brushes returned by the
  731.                WinGCreateHalftoneBrush API use patterns of colors
  732.                in the halftone palette to create areas of
  733.                simulated true color on 8-bit devices into which
  734.                the halftone palette has been selected and
  735.                realized. The CUBE sample application (in the
  736.                SAMPLES\CUBE subdirectory of the WinG development
  737.                kit) uses halftoned brushes to generate a wide
  738.                range of shaded colors on an 8-bit display.
  739.                  The halftone palette gives applications a
  740.                framework for dithering 24-bit images to 8-bit
  741.                devices. The palette itself is a slightly modified
  742.                2.6-bit-per-primary RGB cube, giving 216 halftoned
  743.                values. The 256-color halftone palette also
  744.                contains the twenty static colors and a range of
  745.                gray values.
  746.                  Given a 24-bit RGB color with 8 bits per
  747.                primitive, you can find the index of the nearest
  748.                color in the halftone palette using the following
  749.                formula:
  750.                  
  751.   HalftoneIndex = (Red / 51) + (Green / 51) * 6 + (Blue / 51) *
  752.   36;
  753.   HalftoneColorIndex = aWinGHalftoneTranslation [HalftoneIndex];
  754.                The aWinGHalftoneTranslation vector can be found
  755.                in the HALFTONE source code. The HALFTONE sample
  756.                (in the SAMPLES\HALFTONE subdirectory of the WinG
  757.                development kit) applies an ordered 8x8 dither to
  758.                a 24-bit image, converting it to an 8-bit DIB
  759.                using the WinG Halftone Palette.
  760.                  Applications should avoid depending on a
  761.                specific ordering of the halftone palette by using
  762.                PALETTERGB instead of PALETTEINDEX to refer to
  763.                entries in the palette.
  764.  
  765. Maximizing Performance With WinG
  766.                Here is the WinG Programmer's Guide to Achieving
  767.                WinG Nirvana, the Top Ten ways to maximize blt
  768.                performance under Windows using WinG.
  769.           
  770.           10.  Take Out Your Monochrome Debugging Card
  771.                Eight bit monochrome video cards can turn the 16
  772.                bit 8 MHz ISA bus into an 8 bit 4 MHz PC bus,
  773.                cutting your video bus bandwidth by up to 75%.
  774.                Monochrome cards are an invaluable aid when
  775.                debugging graphical applications, but when timing
  776.                or running final tests, remove the card for
  777.                maximum speed.
  778.           
  779.           9.  Store WinGBitmap Surface Pointer and BITMAPINFO
  780.                WinGCreateBitmap takes a BITMAPINFO, creates an
  781.                HBITMAP, and returns a pointer to the new bitmap
  782.                surface. Store the BITMAPINFO and pointer at
  783.                creation time with the HBITMAP rather than call
  784.                WinGGetDIBPointer when you need it.
  785.           
  786.           8.  Don't Make Redundant GDI Calls
  787.                GDI objects such as brushes, fonts, and pens, take
  788.                time to create, select, and destroy. Save time by
  789.                creating frequently used objects once and caching
  790.                them until they are no longer needed. Move the
  791.                creation and selection of objects as far out of
  792.                your inner loops as possible.
  793.           
  794.           7. Special Purpose Code May Be Faster Than GDI
  795.                There may be many ways to accomplish a given
  796.                graphics operation using GDI or custom graphics
  797.                code in your application. Special purpose code can
  798.                be faster than the general purpose GDI code, but
  799.                custom code often incurs associated development
  800.                and testing overhead. Determine if GDI can
  801.                accomplish the operation and if the performance is
  802.                acceptable for your problem. Weigh the
  803.                alternatives carefully and see number 6 below.
  804.           
  805.           6. Time Everything, Assume Nothing (Ruminations on good
  806.                coding practices)
  807.                Software and its interactions with hardware are
  808.                complex. Don't assume one technique is faster than
  809.                another; time both. Within GDI, some APIs do more
  810.                work than others, and there are sometimes multiple
  811.                ways to do a single operation_not all techniques
  812.                will be the same speed.
  813.                  Remember the old software development adage:
  814.                90% of your time is spent executing 10% of the
  815.                code. If you can find the 10% through profiling
  816.                and optimize it, your application will be
  817.                noticeably faster.
  818.                  Timing results may depend on the runtime
  819.                platform. An application's performance on your
  820.                development machine may be significantly different
  821.                from its performance on a different runtime
  822.                machine. For absolute maximum speed, implement a
  823.                variety of algorithms, time them at runtime or at
  824.                installation, and choose code paths accordingly.
  825.                If you choose to time at installation, remember
  826.                that changes to video drivers and hardware
  827.                configuration after your application has been
  828.                installed can have a significant effect on runtime
  829.                speed.
  830.           
  831.           5.  Don't Stretch
  832.                Stretching a WinGBitmap requires more work than
  833.                just blting it. If you must stretch, stretching by
  834.                factors of 2 will be fastest.
  835.                  On the other hand, if your application is pixel-
  836.                bound (it spends more time writing pixels to the
  837.                bitmap than it does blting), it may be faster to
  838.                stretch a small WinGBitmap to a larger window than
  839.                it is to fill and blt a WinGBitmap with the same
  840.                dimensions as the window. Your application can
  841.                respond to the WM_GETMINMAXINFO message to
  842.                restrict the size of your window if you don't want
  843.                to deal with this problem.
  844.           
  845.           4.  Don't Blt
  846.                "The fastest code is the code that isn't called."
  847.                Blt the smallest area possible as seldom as
  848.                possible. Of course, figuring out the smallest
  849.                area to blt might take longer than just blting a
  850.                larger area. For example, a dirty rectangle sprite
  851.                system could use complex algorithms to calculate
  852.                the absolute minimum rectangles to update, but it
  853.                might spend more time doing this than just blting
  854.                the union of the dirty areas. The runtime
  855.                environment can affect which method is faster.
  856.                Again, time it to make sure.
  857.           
  858.           3.  Don't Clip
  859.                Selecting GDI clip regions into the destination DC
  860.                or placing windows (like floating tool bars) over
  861.                the destination DC can slow the blt speed.
  862.                  Clip regions may seem like a good way to reduce
  863.                the number of pixels actually sent to the screen,
  864.                but someone has to do the work. As number 4 and
  865.                number 7 discuss above, you may be better off
  866.                doing the work yourself rather than using GDI.
  867.                  An easy way to test your application's
  868.                performance when clipped is to start the CLOCK.EXE
  869.                program supplied with Windows. Set it to Always On
  870.                Top and move it over your client area.
  871.           
  872.           2.  Use an Identity Palette
  873.                WinGBitmaps without identity palettes require a
  874.                color translation per pixel when blted. `Nuff
  875.                said.
  876.                  See the Using an Identity Palette article for
  877.                specific information about what identity palettes
  878.                are, how they work, and how you can use them.
  879.           
  880.           1.  Use the Recommended DIB Format
  881.                WinG adapts itself to the hardware available at
  882.                runtime to achieve optimum performance on every
  883.                platform. Every hardware and software combination
  884.                can be different, and the best way to guarantee
  885.                the best blt performance is to use the DIB
  886.                parameters returned by WinGRecommendDibFormat in
  887.                calls to WinGCreateBitmap. If you do this,
  888.                remember that your code must support both bottom-
  889.                up and top-down DIB formats. See the DIB
  890.                Orientation article for more information on
  891.                handling these formats.
  892.  
  893. DIB Orientation
  894.                The most frustrating thing about working with DIBs
  895.                is that DIBs are usually oriented with the
  896.                bottommost scanline stored first in memory, the
  897.                exact opposite of the usual device-dependent
  898.                bitmap orientation. This standard type of Windows
  899.                DIB is called a bottom-up DIB.
  900.                  WinG hides the orientation of DIBs from an
  901.                application unless the application wants to know.
  902.                Drawing into a WinGDC using GDI functions and
  903.                blting the WinGDC to the display using either of
  904.                the WinG DIB copy commands (WinGStretchBlt or
  905.                WinGBitBlt) results in an image that is almost
  906.                identical to one created using GDI to draw
  907.                directly onto a display DC. See the Using GDI With
  908.                WinGDCs article for more information.
  909.                  If you don't plan on writing custom drawing
  910.                routines and will not be using existing Windows
  911.                3.1 DIB-to-screen functions (such as StretchDIBits
  912.                or SetDIBitsToDevice), you can skip the rest of
  913.                this section.
  914.                  If you do plan on writing custom drawing
  915.                routines or just want to know how they work, this
  916.                section will begin to alleviate the confusion. The
  917.                Microsoft Technical Articles "DIBs and Their Use"
  918.                by Ron Gery and "Animation in Windows" by Herman
  919.                Rodent will flesh out the ideas presented here,
  920.                provide helpful advice, and describe DIBs in
  921.                depth. The TRIQ sample code from Microsoft's GDI
  922.                Technical Notes shows how to draw triangles and
  923.                quads into a memory DIB. These articles are listed
  924.                in the section Further Reading.
  925.                  Confusion with bottom-up DIBs inevitably stems
  926.                from the fact that the bottommost scanline is
  927.                stored first in memory, giving a coordinate space
  928.                where (0, 0) is the lower left corner of the
  929.                image. Windows uses (0, 0) as the upper left
  930.                corner of the display and of device dependent
  931.                bitmaps, meaning that the Y coordinates of bottom-
  932.                up DIBs are inverted. In the diagram below, the
  933.                smiling face casts its gaze towards the DIB
  934.                origin, but when translated to the display with
  935.                WinGStretchBlt or WinGBitBlt, it looks away from
  936.                the display origin.
  937.                                                                  
  938.                                                                  
  939.                Bottom-Up DIBs are flipped when copied to the
  940.                display
  941.                WinGStretchBlt, WinGBitBlt, StretchDIBits, and
  942.                SetDIBitsToDevice invert the bottom-up DIB as they
  943.                draw it to the screen.
  944.                  For an 8-bit bottom-up DIB, the address in
  945.                memory from which the screen pixel (X, Y) is
  946.                retrieved can be found with these equations:
  947.                  
  948.   // Calculate actual bits used per scan line
  949.   DibWidthBits = (UINT)lpBmiHeader->biWidth *
  950.   (UINT)lpBmiHeader->biBitCount);
  951.   // And align it to a 32 bit boundary
  952.   DibWidthBytes = ((DibWidthBits + 31) & (~31)) / 8;
  953.   pPixelXY = DibAddr + (DibHeight - 1 - Y) * DibWidthBytes + X
  954.                where DibAddr is the base address of the DIB,
  955.                DibHeight is the height of the DIB, lpBmiHeader is
  956.                a pointer to a BITMAPINFOHEADER describing the
  957.                DIB, and DibWidthBytes is the DWORD-aligned offset
  958.                of bytes in memory from any X in one scanline to
  959.                any X in the next scanline.
  960.           
  961.           Top-Down DIBs
  962.                Another kind of DIB, called a top-down DIB, is
  963.                stored with the same orientation as most device-
  964.                dependent bitmaps: the first scanline in memory is
  965.                the top of the image. Top-down DIBs are identified
  966.                by a negative biHeight entry in their
  967.                BITMAPINFOHEADER structures.
  968.                  Sometimes, WinG can greatly improve the speed
  969.                of a DIB-to-screen copy by using a top-down DIB
  970.                because it can avoid inverting the DIB to a device-
  971.                dependent format. When this is the case,
  972.                WinGRecommendDIBFormat will return a negative
  973.                value in the biHeight field of the passed
  974.                BITMAPINFOHEADER structure.
  975.                  If you are writing custom DIB drawing routines,
  976.                you will have to handle top-down DIBs for best
  977.                performance because there is a good chance that
  978.                WinG will recommend them with
  979.                WinGRecommendDibFormat.
  980.                  WinGStretchBlt and WinGBitBlt recognize top-
  981.                down DIBs and handle them correctly, but Windows
  982.                3.1 functions such as StretchDIBits and
  983.                SetDIBitsToDevice will not work properly with top-
  984.                down DIBs unless you intentionally mirror the
  985.                image.
  986.                                                                  
  987.                                                                  
  988.                Top-Down DIBs are copied directly to the display
  989.                For an 8-bit top-down DIB, the memory address of
  990.                the pixel (X, Y) can be found with this equation:
  991.                  
  992.   PixelAddr = DibAddr + Y * DibWidthBytes + X
  993.                where DibAddr is the base address of the DIB and
  994.                DibWidthBytes is the DWORD-aligned offset of bytes
  995.                in memory from the beginning of one scanline to
  996.                the next.
  997.                The PALANIM sample application (in the
  998.                SAMPLES\PALANIM subdirectory of the WinG
  999.                development kit) includes a routine to draw
  1000.                horizontal lines into a DIB. To do this, it
  1001.                determines the orientation of the target DIB and
  1002.                performs its calculations accordingly.
  1003.                The DOGGIE sample application (in the
  1004.                SAMPLES\DOGGIE subdirectory of the WinG
  1005.                development kit) includes a routine to copy one
  1006.                DIB into another with a transparent color. The
  1007.                assembly function that does this also behaves well
  1008.                with both DIB orientations.
  1009.  
  1010. Using an Identity Palette
  1011.                The Windows Palette Manager, described in depth in
  1012.                Ron Gery's technical article "The Palette Manager:
  1013.                How and Why" (see the Further Reading section for
  1014.                details) arbitrates conflicts between Windows
  1015.                applications vying for color entries in a single
  1016.                hardware palette (known as the system palette). It
  1017.                gives each application it's own virtual 256-color
  1018.                palette, called a logical palette, and translates
  1019.                entries in the logical palette to entries in the
  1020.                system palette as they are needed for blting
  1021.                images to the screen.
  1022.                  An identity palette is a logical palette which
  1023.                exactly matches the current system palette. An
  1024.                identity palette does not require translation of
  1025.                palette entries, so using an identity palette can
  1026.                drastically improve the speed with which you can
  1027.                blt WinGDCs to the screen.
  1028.                  The WinG Halftone Palette is an identity
  1029.                palette. This article describes how to create your
  1030.                own identity palettes for maximum WinG blt speed.
  1031.           
  1032.           Static Colors
  1033.                The Palette Manager reserves a number of colors in
  1034.                the palette, called the static colors, which it
  1035.                uses to draw system elements such as window
  1036.                captions, menus, borders, and scroll bars. An
  1037.                identity palette must include the static colors in
  1038.                the appropriate palette entries.
  1039.                  The display driver defines the actual RGB
  1040.                values of the static colors, so they must always
  1041.                be determined at run time. The
  1042.                GetSystemPaletteEntries will retrieve the colors
  1043.                currently in the system palette, and you can
  1044.                isolate the static colors using the SIZEPALETTE
  1045.                and NUMCOLORS capability indices with
  1046.                GetDeviceCaps and a little knowledge of how the
  1047.                Palette Manager works.
  1048.                  The static colors are split in half and stored
  1049.                at either end of the system palette. If there are
  1050.                nColors possible entries in the system palette and
  1051.                there are nStaticColors static colors, then the
  1052.                static colors will be found in entries 0 through
  1053.                nStaticColors/2 - 1 and entries nColors -
  1054.                nStaticColors/2 through nColors-1 in the system
  1055.                palette. Typically, there are 20 static colors,
  1056.                found in indices 0-9 and 246-255 of a 256-color
  1057.                palette. The peFlags portion of these PALETTEENTRY
  1058.                structures must be set to zero.
  1059.                  The SetSystemPaletteUse API turns use of the
  1060.                static colors on and off for the system. Using
  1061.                SYSPAL_STATIC, 20 entries will be reserved in the
  1062.                palette. SYSPAL_NOSTATIC reserves only 2 entries,
  1063.                which must be mapped to black and white. See the
  1064.                Accessing a Full Palette Using SYSPAL_NOSTATIC
  1065.                article for more information.
  1066.           
  1067.           Other Colors
  1068.                The remaining non-static colors in the logical
  1069.                palette may be defined by the application, but
  1070.                they must be marked as PC_NOCOLLAPSE (see the
  1071.                PALETTEENTRY documentation for a description) to
  1072.                ensure an identity palette.
  1073.                  A palette containing the static colors in the
  1074.                appropriate entries with the remaining entries
  1075.                marked PC_NOCOLLAPSE, selected and realized into a
  1076.                DC, becomes an identity palette. Because no
  1077.                translation to the system palette is required, the
  1078.                Palette Manager can step aside gracefully and
  1079.                leave you to achieve maximum blt bandwidth.
  1080.           
  1081.           Creating an Identity Palette
  1082.                The CreateIdentityPalette() function below shows
  1083.                how to create an identity palette from a an array
  1084.                of RGBQUAD structures. Before you realize an
  1085.                identity palette for the first time, it may be a
  1086.                good idea to clear the system palette by realizing
  1087.                a completely black palette, as the
  1088.                ClearSystemPalette() function below does This will
  1089.                ensure that palette-managed applications executed
  1090.                before your application will not affect the
  1091.                identity mapping of your carefully constructed
  1092.                palette.
  1093.                  To make sure that you have successfully created
  1094.                and are using an identity palette, you can tell
  1095.                WinG to send debugging messages to the standard
  1096.                debug output, as described in the Debugging With
  1097.                WinG article.
  1098.                  The PALANIM sample (in the SAMPLES\PALANIM
  1099.                subdirectory of the WinG development kit) uses
  1100.                these routines to create a 256-entry identity
  1101.                palette filled with a wash of color.
  1102.                  Click Here to copy the CreateIdentityPalette()
  1103.                code sample to the clipboard.
  1104.                  Click Here to copy the ClearSystemPalette()
  1105.                code sample to the clipboard.
  1106.                  
  1107.   HPALETTE CreateIdentityPalette(RGBQUADWin31_API aRGB[], int
  1108.   nColors)
  1109.   {
  1110.   int i;
  1111.   struct {
  1112.   WORD Version;
  1113.   WORD NumberOfEntries;
  1114.       PALETTEENTRY aEntries[256];
  1115.   } Palette =
  1116.     {
  1117.   0x300,
  1118.   256
  1119.     };
  1120.   
  1121.   //*** Just use the screen DC where we need it
  1122.     HDC hdc = GetDC(NULL);
  1123.   
  1124.   //*** For SYSPAL_NOSTATIC, just copy the color table into
  1125.   //*** a PALETTEENTRY array and replace the first and last
  1126.   entries
  1127.   //*** with black and white
  1128.     if (GetSystemPaletteUse(hdc) == SYSPAL_NOSTATIC)
  1129.     {
  1130.   //*** Fill in the palette with the given values, marking each
  1131.       //*** as PC_NOCOLLAPSE
  1132.   for(i = 0; i < nColors; i++)
  1133.       {
  1134.   Palette.aEntries[i].peRed = aRGB[i].rgbRed;
  1135.   Palette.aEntries[i].peGreen = aRGB[i].rgbGreen;
  1136.   Palette.aEntries[i].peBlue = aRGB[i].rgbBlue;
  1137.   Palette.aEntries[i].peFlags = PC_NOCOLLAPSE;
  1138.       }
  1139.   
  1140.   //*** Mark any unused entries PC_NOCOLLAPSE
  1141.   for (; i < 256; ++i)
  1142.       {
  1143.   Palette.aEntries[i].peFlags = PC_NOCOLLAPSE;
  1144.       }
  1145.   
  1146.   //*** Make sure the last entry is white
  1147.   //*** This may replace an entry in the array!
  1148.   Palette.aEntries[255].peRed = 255;
  1149.   Palette.aEntries[255].peGreen = 255;
  1150.   Palette.aEntries[255].peBlue = 255;
  1151.   Palette.aEntries[255].peFlags = 0;
  1152.   
  1153.   //*** And the first is black
  1154.   //*** This may replace an entry in the array!
  1155.   Palette.aEntries[0].peRed = 0;
  1156.   Palette.aEntries[0].peGreen = 0;
  1157.   Palette.aEntries[0].peBlue = 0;
  1158.   Palette.aEntries[0].peFlags = 0;
  1159.     }
  1160.   else
  1161.   //*** For SYSPAL_STATIC, get the twenty static colors into
  1162.   //*** the array, then fill in the empty spaces with the
  1163.   //*** given color table
  1164.     {
  1165.   int nStaticColors;
  1166.   int nUsableColors;
  1167.   
  1168.       //*** Get the static colors from the system palette
  1169.       nStaticColors = GetDeviceCaps(hdc, NUMCOLORS);
  1170.       GetSystemPaletteEntries(hdc, 0, 256, Palette.aEntries);
  1171.   
  1172.   //*** Set the peFlags of the lower static colors to zero
  1173.   nStaticColors = nStaticColors / 2;
  1174.   for (i=0; i<nStaticColors; i++)
  1175.   Palette.aEntries[i].peFlags = 0;
  1176.   //*** Fill in the entries from the given color table
  1177.   nUsableColors = nColors - nStaticColors;
  1178.   for (; i<nUsableColors; i++)
  1179.       {
  1180.   Palette.aEntries[i].peRed = aRGB[i].rgbRed;
  1181.   Palette.aEntries[i].peGreen = aRGB[i].rgbGreen;
  1182.   Palette.aEntries[i].peBlue = aRGB[i].rgbBlue;
  1183.   Palette.aEntries[i].peFlags = PC_NOCOLLAPSE;
  1184.       }
  1185.   
  1186.   //*** Mark any empty entries as PC_NOCOLLAPSE
  1187.   for (; i<256 - nStaticColors; i++)
  1188.   Palette.aEntries[i].peFlags = PC_NOCOLLAPSE;
  1189.   //*** Set the peFlags of the upper static colors to zero
  1190.   for (i = 256 - nStaticColors; i<256; i++)
  1191.   Palette.aEntries[i].peFlags = 0;
  1192.     }
  1193.   
  1194.   //*** Remember to release the DC!
  1195.     ReleaseDC(NULL, hdc);
  1196.   
  1197.   //*** Return the palette
  1198.     return CreatePalette((LOGPALETTE *)&Palette);
  1199.   }
  1200.   
  1201.   
  1202.   void ClearSystemPalette(void)
  1203.   {
  1204.   //*** A dummy palette setup
  1205.   struct
  1206.     {
  1207.   WORD Version;
  1208.   WORD NumberOfEntries;
  1209.       PALETTEENTRY aEntries[256];
  1210.   } Palette =
  1211.     {
  1212.   0x300,
  1213.   256
  1214.     };
  1215.   
  1216.     HPALETTE ScreenPalette = 0;
  1217.     HDC ScreenDC;
  1218.   int Counter;
  1219.   //*** Reset everything in the system palette to black
  1220.   for(Counter = 0; Counter < 256; Counter++)
  1221.     {
  1222.   Palette.aEntries[Counter].peRed = 0;
  1223.   Palette.aEntries[Counter].peGreen = 0;
  1224.   Palette.aEntries[Counter].peBlue = 0;
  1225.   Palette.aEntries[Counter].peFlags = PC_NOCOLLAPSE;
  1226.     }
  1227.   
  1228.   //*** Create, select, realize, deselect, and delete the
  1229.   palette
  1230.     ScreenDC = GetDC(NULL);
  1231.     ScreenPalette = CreatePalette((LOGPALETTE *)&Palette);
  1232.   ScreenPalette = SelectPalette(ScreenDC,ScreenPalette,FALSE);
  1233.     RealizePalette(ScreenDC);
  1234.   ScreenPalette = SelectPalette(ScreenDC,ScreenPalette,FALSE);
  1235.     DeleteObject(ScreenPalette);
  1236.     ReleaseDC(NULL, ScreenDC);
  1237.   }
  1238.  
  1239. Palette Animation With WinG
  1240.                Palette animation creates the appearance of motion
  1241.                in an image by modifying entries the system
  1242.                palette, resulting in color changes in the
  1243.                displayed image. Carefully arranged and animated
  1244.                palette entries can produce motion effects such as
  1245.                running water, flowing lava, or even motion of an
  1246.                object across the screen.
  1247.                  The AnimatePalette function in Windows replaces
  1248.                entries in a logical palette. When the modified
  1249.                palette is realized, the colors in the palette
  1250.                will be remapped, and colors on the display will
  1251.                change.
  1252.                  Because every DIB and WinGBitmap has an
  1253.                associated color table which is translated to the
  1254.                system palette when the image is copied to the
  1255.                screen, DIBs blted after the palette is animated
  1256.                will not appear animated because their colors are
  1257.                translated to the new palette.
  1258.                  The Using an Identity Palette article discusses
  1259.                the creation of an identity palette which removes
  1260.                the need for color translation when blting. If a
  1261.                palette animating application went through the
  1262.                trouble to create the identity palette, it should
  1263.                maintain the identity mapping between the palette
  1264.                and the WinGDC by matching the WinGBitmap color
  1265.                table to the animated palette before blting. To do
  1266.                this, use WinGSetDibColorTable to keep the
  1267.                WinGBitmap color table synchronized with changes
  1268.                in the system palette.
  1269.                  Remember that any entries in a palette which
  1270.                are to be animated must be marked with the
  1271.                PC_RESERVED flag. This includes the PC_NOCOLLAPSE
  1272.                flag, so these entries can be included in an
  1273.                identity palette.
  1274.                  The PALANIM sample (in the SAMPLES\PALANIM
  1275.                subdirectory of the WinG development kit) performs
  1276.                a simple palette animation with an identity
  1277.                palette, making sure to update the WinGDC color
  1278.                table to match the palette before it blts using
  1279.                the following code, which copies the current
  1280.                logical palette (hpalApp) into the color table of
  1281.                the WinGDC (hdcOffscreen). Of course, if you
  1282.                create the palette yourself from an array of
  1283.                colors, there will be no need to call
  1284.                GetPaletteEntries because you could update the
  1285.                color table from the array you already have in
  1286.                memory. Also, in a palette animation that does not
  1287.                animate the complete palette, an application would
  1288.                not need to modify the entire palette and color
  1289.                table, as this code snippet does:
  1290.   int i;
  1291.   PALETTEENTRY aPalette[256];
  1292.   RGBQUAD aPaletteRGB[256];
  1293.   
  1294.   //*** BEFORE BLTING, match the DIB color table to the
  1295.   //*** current palette to match the animated palette
  1296.   GetPaletteEntries(hpalApp, 0, 256, aPalette);
  1297.   //*** Alas, palette entries are r-g-b, rgbquads are b-g-r
  1298.   for (i=0; i<256; ++i)
  1299.   {
  1300.   aPaletteRGB[i].rgbRed = aPalette[i].peRed;
  1301.   aPaletteRGB[i].rgbGreen = aPalette[i].peGreen;
  1302.   aPaletteRGB[i].rgbBlue = aPalette[i].peBlue;
  1303.   aPaletteRGB[i].rgbReserved = 0;
  1304.   }
  1305.   WinGSetDIBColorTable(hdcOffscreen, 0, 256, aPaletteRGB);
  1306.  
  1307. Accessing a Full Palette Using SYSPAL_NOSTATIC
  1308.                The Palette Manager usually reserves twenty static
  1309.                colors in the palette for use in drawing captions,
  1310.                menus, text, scroll bars, window frames, and other
  1311.                system elements. These static colors ensure a
  1312.                common color scheme across all applications, but
  1313.                this leaves only 236 palette entries available to
  1314.                each application. A Windows graphics application
  1315.                requiring a full palette of 256 colors has two
  1316.                options, outlined here.
  1317.                  The first option is to incorporate the static
  1318.                colors into the palette at runtime, knowing that
  1319.                the RGB values of the colors may change slightly
  1320.                from display driver to display driver. This means
  1321.                that the palette will vary slightly when the
  1322.                application runs on different platforms, but it
  1323.                ensures the consistent look and feel between the
  1324.                application and coexisting applications in the
  1325.                system.
  1326.                  The static colors are defined as follows:
  1327.                  
  1328.                Inde Color               Inde  Color
  1329.                x                        x
  1330.                0    Black               246   Cream
  1331.                1    Dark Red            247   Light Gray
  1332.                2    Dark Green          248   Medium Gray
  1333.                3    Dark Yellow         249   Red
  1334.                4    Dark Blue           250   Green
  1335.                5    Dark Magenta        251   Yellow
  1336.                6    Dark Cyan           252   Blue
  1337.                7    Light Gray          253   Magenta
  1338.                8    Money Green         254   Cyan
  1339.                9    Sky Blue            255   White
  1340.                If you can accept the limitation of including
  1341.                these colors in your palette and determining their
  1342.                exact RGB values at runtime (using
  1343.                GetSystemPaletteEntries), you can skip the rest of
  1344.                this article.
  1345.                  The second option is to tell the Window Manager
  1346.                to make 18 of the twenty static colors available
  1347.                to the application, with entry 0 remaining black
  1348.                and entry 255 remaining white. However, choosing
  1349.                to control those palette entries means you'll have
  1350.                some more intimate relations with the Palette
  1351.                Manager.
  1352.                  To change the use of the static colors in the
  1353.                system palette, you use the SetSystemPaletteUse
  1354.                API, passing either SYSPAL_STATIC or
  1355.                SYSPAL_NOSTATIC. Setting the palette use to
  1356.                SYSPAL_NOSTATIC gives you access to palette
  1357.                entries 1 through 254. Your palette must map entry
  1358.                0 to RGB(0, 0, 0) and entry 255 to RGB(255, 255,
  1359.                255), but black and white are standard in most
  1360.                palettes anyway.
  1361.                  Ordinarily, Windows uses entries 0-9 and 246-
  1362.                255 to draw captions, borders, menus, and text,
  1363.                and it will continue to do so after you've changed
  1364.                the RGB values of those palette entries unless you
  1365.                tell it to do otherwise. If you do not inform the
  1366.                operating system of your changes, your application
  1367.                and all others in the system will become very
  1368.                messy and your application will be condemned by
  1369.                its peers as unfriendly.
  1370.                  You want your application to be friendly to the
  1371.                operating system and to the other active
  1372.                applications. You can handle this in two ways: you
  1373.                can make your application a full-screen window
  1374.                with no controls, thereby taking over the entire
  1375.                screen and the full palette, or you can tell the
  1376.                operating system to use different palette entries
  1377.                to draw its captions, borders, menus, and text so
  1378.                that other visible windows do not appear
  1379.                completely strange. In either case, you must
  1380.                restore the static colors when your application
  1381.                becomes inactive or exits.
  1382.                  The following procedure handles the switch
  1383.                between SYSPAL_STATIC and SYSPAL_NOSTATIC for you,
  1384.                managing the mapping and remapping of the system
  1385.                colors for you through the Windows functions
  1386.                GetSysColor and SetSysColors. It stores the
  1387.                current mapping of the system colors before
  1388.                switching to SYSPAL_NOSTATIC mode and restores
  1389.                them after switching back to SYSPAL_STATIC mode.
  1390.                  To use the AppActivate() function in an
  1391.                application, call AppActivate((BOOL)wParam) in
  1392.                response to a WM_ACTIVATEAPP message and call
  1393.                AppActivate(FALSE) before exiting to restore the
  1394.                system colors. This will set the system palette
  1395.                use and remap the system colors when your
  1396.                application is activated or deactivated.
  1397.                  The PALANIM sample (in the SAMPLES\PALANIM
  1398.                subdirectory of the WinG development kit) uses
  1399.                this function to take over the static colors at
  1400.                run time and clean up before it exits.
  1401.   
  1402.   #define NumSysColors
  1403.   (sizeof(SysPalIndex)/sizeof(SysPalIndex[1]))
  1404.   #define rgbBlack RGB(0,0,0)
  1405.   #define rgbWhite RGB(255,255,255)
  1406.   
  1407.   //*** These are the GetSysColor display element identifiers
  1408.   static int SysPalIndex[] = {
  1409.     COLOR_ACTIVEBORDER,
  1410.     COLOR_ACTIVECAPTION,
  1411.     COLOR_APPWORKSPACE,
  1412.     COLOR_BACKGROUND,
  1413.     COLOR_BTNFACE,
  1414.     COLOR_BTNSHADOW,
  1415.     COLOR_BTNTEXT,
  1416.     COLOR_CAPTIONTEXT,
  1417.     COLOR_GRAYTEXT,
  1418.     COLOR_HIGHLIGHT,
  1419.     COLOR_HIGHLIGHTTEXT,
  1420.     COLOR_INACTIVEBORDER,
  1421.     COLOR_INACTIVECAPTION,
  1422.     COLOR_MENU,
  1423.     COLOR_MENUTEXT,
  1424.     COLOR_SCROLLBAR,
  1425.     COLOR_WINDOW,
  1426.     COLOR_WINDOWFRAME,
  1427.     COLOR_WINDOWTEXT
  1428.   };
  1429.   
  1430.   //*** This array translates the display elements to black and
  1431.   white
  1432.   static COLORREF MonoColors[] = {
  1433.   rgbBlack,
  1434.   rgbWhite,
  1435.   rgbWhite,
  1436.   rgbWhite,
  1437.   rgbWhite,
  1438.   rgbBlack,
  1439.   rgbBlack,
  1440.   rgbBlack,
  1441.   rgbBlack,
  1442.   rgbBlack,
  1443.   rgbWhite,
  1444.   rgbWhite,
  1445.   rgbWhite,
  1446.   rgbWhite,
  1447.   rgbBlack,
  1448.   rgbWhite,
  1449.   rgbWhite,
  1450.   rgbBlack,
  1451.   rgbBlack
  1452.   };
  1453.   
  1454.   //*** This array holds the old color mapping so we can restore
  1455.   them
  1456.   static COLORREF OldColors[NumSysColors];
  1457.   
  1458.   //*** AppActivate sets the system palette use and
  1459.   //*** remaps the system colors accordingly.
  1460.   void AppActivate(BOOL fActive)
  1461.   {
  1462.     HDC hdc;
  1463.   int i;
  1464.   //*** Just use the screen DC
  1465.     hdc = GetDC(NULL);
  1466.   
  1467.   //*** If the app is activating, save the current color mapping
  1468.   //*** and switch to SYSPAL_NOSTATIC
  1469.     if (fActive && GetSystemPaletteUse(hdc) == SYSPAL_STATIC)
  1470.     {
  1471.   //*** Store the current mapping
  1472.   for (i=0; i<NumSysColors; i++)
  1473.   OldColors[i] = GetSysColor(SysPalIndex[i]);
  1474.   //*** Switch to SYSPAL_NOSTATIC and remap the colors
  1475.       SetSystemPaletteUse(hdc, SYSPAL_NOSTATIC);
  1476.       SetSysColors(NumSysColors, SysPalIndex, MonoColors);
  1477.     }
  1478.     else if (!fActive && GetSystemPaletteUse(hdc) ==
  1479.   SYSPAL_NOSTATIC)
  1480.     {
  1481.   //*** Switch back to SYSPAL_STATIC and the old mapping
  1482.       SetSystemPaletteUse(hdc, SYSPAL_STATIC);
  1483.       SetSysColors(NumSysColors, SysPalIndex, OldColors);
  1484.     }
  1485.   
  1486.   //*** Be sure to release the DC!
  1487.     ReleaseDC(NULL,hdc);
  1488.   }
  1489.  
  1490. WinGBitBlt
  1491.                Copies an area from a specified device context to
  1492.                a destination device context. WinGBitBlt is
  1493.                optimized for copying WinGDCs to display DCs.
  1494.                  BOOL WinGBitBlt(HDC hdcDest, int nXOriginDest,
  1495.                int nYOriginDest, int nWidthDest, int nHeightDest,
  1496.                HDC hdcSrc, int nXOriginSrc, int nYOriginSrc)
  1497.                Parameters
  1498.                
  1499.     hdcDest    Identifies the destination device context.
  1500.     nXOriginD  X coordinate of the upper-left corner of the
  1501.     est        destination rectangle in MM_TEXT client
  1502.                coordinates.
  1503.     nYOriginD  Y coordinate of the upper-left corner of the
  1504.     est        destination rectangle in MM_TEXT client
  1505.                coordinates.
  1506.     nWidthDes  Width of the source and destination
  1507.     t          rectangle..
  1508.     nHeightDe  Height of the source and destination
  1509.     st         rectangle..
  1510.     hdcSrc     Identifies the source device context.
  1511.     nXOriginS  X coordinate of the upper-left corner of the
  1512.     rc         source rectangle in MM_TEXT client
  1513.                coordinates.
  1514.     nYOriginS  Y coordinate of the upper-left corner of the
  1515.     rc         source rectangle in MM_TEXT client
  1516.                coordinates.
  1517.                Return Value
  1518.                The return value is non-zero if the function is
  1519.                successful. Otherwise, it is zero.
  1520.                Comments
  1521.                WinGBitBlt requires both DCs to use MM_TEXT
  1522.                mapping mode at the time of the call or the
  1523.                results may be unpredictable. At other times, any
  1524.                mapping mode may be used in either DC.
  1525.                Maximizing Performance
  1526.                You will get the highest performance from
  1527.                WinGBitBlt if you select a WinGBitmap created from
  1528.                header information supplied by a call to
  1529.                WinGRecommendDIBFormat.
  1530.                  WinGBitBlt is optimized for copying WinGDCs to
  1531.                the screen.
  1532.                  Clipping can slow WinGBitBlt down. In general,
  1533.                don't select clipping regions into or blt outside
  1534.                the boundaries of the source or destination DCs
  1535.                and avoid blting to an overlapped window if
  1536.                possible.
  1537.                See Also
  1538.                WinGStretchBlt WinGCreateDC WinGCreateBitmap
  1539.                WinGRecommendDIBFormat Maximizing Performance With
  1540.                WinG
  1541.  
  1542. WinGCreateBitmap
  1543.                Creates a WinGBitmap for the given WinGDC using
  1544.                the specified header information.
  1545.                  HBITMAP WinGCreateBitmap( HDC hWinGDC,
  1546.                BITMAPINFO far *pHeader, void far *far *ppBits )
  1547.                Parameters
  1548.                
  1549.     hWinGDC    Identifies the WinG device context.
  1550.     pHeader    Points to a BITMAPINFO structure specifying
  1551.                the width, height, and color table for the
  1552.                new WinGBitmap.
  1553.     ppBitsr    If not 0, points to a pointer to receive the
  1554.                address of the new WinGDC DIB surface.
  1555.                Return Value
  1556.                Returns a handle to the new WinGBitmap DIB surface
  1557.                or 0 if it is unsuccessful.
  1558.                Comments
  1559.                Under Windows 3.1, WinGCreateBitmap will only
  1560.                create 8-bit-per-pixel surfaces.
  1561.                  If ppBits is 0, the address of the newly
  1562.                created bitmap will not be returned.
  1563.                WinGGetDIBPointer will also return this
  1564.                information.
  1565.                  pHeader must point to enough memory to hold a
  1566.                BITMAPINFOHEADER and a complete color table of
  1567.                RGBQUAD entries. The biClrUsed field of the
  1568.                BITMAPINFOHEADER specifies the number of colors in
  1569.                the color table; if it is zero, the maximum number
  1570.                of colors according to biBitCount are used if
  1571.                biBitCount is less than 24. For example, if
  1572.                biBitCount is 8 and biClrUsed is 0, 256 palette
  1573.                entries are expected. See the BITMAPINFOHEADER
  1574.                description in the Windows 3.1 SDK Reference for
  1575.                more information.
  1576.                  When an application has finished using a
  1577.                WinGBitmap, it should select the bitmap out of its
  1578.                WinGDC and remove the bitmap by calling
  1579.                DeleteObject.
  1580.                  The pointer to the WinGBitmap DIB surface
  1581.                returned by WinGCreateBitmap must not be freed by
  1582.                the caller. The allocated memory will be freed by
  1583.                a call to DeleteObject.
  1584.                  WinGCreateBitmap uses pHeader and the
  1585.                subsequent color table to create the drawing
  1586.                surface. WinG ignores the biClrImportant,
  1587.                biXPelsPerMeter, biYPelsPerMeter, and biSizeImage
  1588.                fields. WinG expects biCompression to be BI_RGB.
  1589.                  If the biHeight field of the passed
  1590.                BITMAPINFOHEADER is negative, WinGCreateBitmap
  1591.                will create a top-down DIB as the bitmap surface.
  1592.                See the article on DIB Orientation for a
  1593.                discussion of top-down and bottom-up DIBs.
  1594.                  An HBITMAP can only be selected into one device
  1595.                context at a time, and a device context can only
  1596.                have a single HBITMAP selected in at a time.
  1597.                Maximizing Performance
  1598.                To create a WinGBitmap that will maximize
  1599.                WinGBitBlt performance, use WinGRecommendDIBFormat
  1600.                to fill in the entries of pHeader before calling
  1601.                WinGCreateBitmap, remembering to modify the height
  1602.                and width to suit your needs.
  1603.                  Larger WinGBitmaps take longer to blt to the
  1604.                screen. Also, if the screen DC is clipped, for
  1605.                example by an overlapping window or by a selected
  1606.                clip region, the WinGDC will take longer to blt to
  1607.                the screen.
  1608.                  Using an identity palette that exactly matches
  1609.                the WinGBitmap's color table will greatly increase
  1610.                performance.
  1611.                Example
  1612.                The following code fragment shows how an
  1613.                application could create a WinGDC with an optimal
  1614.                100x100 WinGBitmap selected for drawing, then
  1615.                delete it when it is no longer needed. Note that
  1616.                the WinGBitmap will initially have garbage in its
  1617.                color table_be sure to call WinGSetDIBColorTable
  1618.                before using the WinGDC.
  1619.                  The PALANIM sample (in the SAMPLES\PALANIM
  1620.                subdirectory of the WinG development kit) uses
  1621.                these routines, modified to create a 256x256
  1622.                WinGDC, to allocate and free its drawing buffer.
  1623.                  
  1624.      HBITMAP ghBitmapMonochrome = 0;
  1625.      
  1626.      HDC Create100x100WinGDC(void)
  1627.      {
  1628.        HDC hWinGDC;
  1629.        HBITMAP hBitmapNew;
  1630.      struct {
  1631.           BITMAPINFOHEADER InfoHeader;
  1632.           RGBQUAD ColorTable[256];
  1633.      } Info;
  1634.      void far *pSurfaceBits;
  1635.      
  1636.      // Set up an optimal bitmap
  1637.        if (WinGRecommendDibFormat((BITMAPINFO far *)&Info) ==
  1638.      FALSE)
  1639.      return 0;
  1640.      // Set the width and height of the DIB but preserve the
  1641.      // sign of biHeight in case top-down DIBs are faster
  1642.      Info.InfoHeader.biHeight *= 100;
  1643.      Info.InfoHeader.biWidth = 100;
  1644.      // Create a WinGDC and Bitmap, then select away
  1645.        hWinGDC = WinGCreateDC();
  1646.      if (hWinGDC)
  1647.        {
  1648.      hBitmapNew = WinGCreateBitmap(hWinGDC,
  1649.             (BITMAPINFO far *)&Info, &pSurfaceBits);
  1650.      if (hBitmapNew)
  1651.           {
  1652.             ghBitmapMonochrome = (HBITMAP)SelectObject(hWinGDC,
  1653.      hBitmapNew);
  1654.           }
  1655.      else
  1656.           {
  1657.             DeleteDC(hWinGDC);
  1658.      hWinGDC = 0;
  1659.           }
  1660.        }
  1661.      
  1662.      return hWinGDC;
  1663.      }
  1664.      
  1665.      void Destroy100x100WinGDC(HDC hWinGDC)
  1666.      {
  1667.        HBITMAP hBitmapOld;
  1668.      
  1669.      if (hWinGDC && ghBitmapMonochrome)
  1670.        {
  1671.      // Select the stock 1x1 monochrome bitmap back in
  1672.           hBitmapOld = (HBITMAP)SelectObject(hWinGDC,
  1673.      ghBitmapMonochrome);
  1674.           DeleteObject(hBitmapOld);
  1675.           DeleteDC(hWinGDC);
  1676.        }
  1677.      }
  1678.                See Also
  1679.                WinGCreateDC WinGRecommendDIBFormat
  1680.                CreateBitmapCreateCompatibleBitmap BITMAPINFO
  1681.                BITMAPINFOHEADER WinGGetDIBPointer
  1682.                CreateDIBSection Code Samples Off-screen Drawing
  1683.                With WinG Maximizing Performance With WinG
  1684.  
  1685. WinGCreateDC
  1686.                Creates a WinG device context with the stock 1x1
  1687.                monochrome bitmap selected.
  1688.                  HDC WinGCreateDC(void)
  1689.                Return Value
  1690.                Returns the handle to a new WinGDC if successful.
  1691.                Otherwise, WinGCreateDC returns 0.
  1692.                Comments
  1693.                Device contexts created using WinGCreateDC must be
  1694.                deleted using the DeleteDC function. All objects
  1695.                selected into the WinGDC after it was created
  1696.                should be selected out and replaced with the
  1697.                original objects before the device context is
  1698.                deleted.
  1699.                  When a WinGDC is created, WinG automatically
  1700.                selects the stock 1x1 monochrome bitmap as its
  1701.                drawing surface. To begin drawing on the WinGDC,
  1702.                select a WinGBitmap created by the
  1703.                WinGCreateBitmap function into the WinGDC.
  1704.                Maximizing Performance
  1705.                WinGCreateDC has a fairly high overhead and is
  1706.                usually used to create a single off-screen DC. In
  1707.                general, programs will call WinGCreateDC once at
  1708.                startup then select new WinGBitmaps on WM_SIZE
  1709.                messages to the double-buffered window.
  1710.                Applications can use the WM_GETMINMAXINFO message
  1711.                to restrict the size of their window if necessary.
  1712.                  Compose frames into WinGDCs, then use
  1713.                WinGStretchBlt or WinGBitBlt to copy the WinGDC to
  1714.                the screen.
  1715.                Example
  1716.                See the WinGCreateBitmap API for sample code that
  1717.                uses WinGCreateDC.
  1718.                See Also
  1719.                WinGCreateBitmap CreateDC DeleteDC WM_SIZE
  1720.                WM_GETMINMAXINFO WinGStretchBlt WinGBitBlt
  1721.                CreateDIBSection Off-screen Drawing With WinG
  1722.                Maximizing Performance With WinG Code Samples
  1723.  
  1724. WinGCreateHalftoneBrush
  1725.                Creates a dithered pattern brush based on the WinG
  1726.                halftone palette.
  1727.                  HBRUSH WinGCreateHalftoneBrush(HDC hdc,
  1728.                COLORREF Color, enum WING_DITHER_TYPE DitherType)
  1729.                Parameters
  1730.                
  1731.     hdc        Specifies the DC with which the brush should
  1732.                be compatible.
  1733.     Color      Specifies the color to be approximated by
  1734.                the brush.
  1735.     DitherTyp  Specifies the dither pattern for the brush.
  1736.     e          Can be one of:
  1737.                   WING_DISPERSED_4x4
  1738.                   WING_DISPERSED_8x8
  1739.                   WING_CLUSTERED_4x4
  1740.                Return Value
  1741.                Returns a handle to a GDI brush if successful.
  1742.                Otherwise, WinGCreateHalftoneBrush returns 0.
  1743.                Comments
  1744.                This API is intended for simulating true color on
  1745.                8-bit devices. It will create a patterned brush
  1746.                using colors from the halftone palette regardless
  1747.                of the color resolution of the target device. If
  1748.                hdc refers to a 24-bit device,
  1749.                WinGCreateHalftoneBrush will not return a solid
  1750.                brush of the given color, it will return a colored
  1751.                dither pattern using colors that appear in the
  1752.                halftone palette. On true-color devices, creating
  1753.                a solid brush that exactly matches the desired
  1754.                color is simple; WinGCreateHalftoneBrush lets you
  1755.                use the halftone patterns instead if you so
  1756.                desire.
  1757.                  A halftone brush approximates the requested
  1758.                Color using combinations of colors in the halftone
  1759.                palette. Larger dither patterns give a better
  1760.                approximation of the desired color but require
  1761.                more area to show the approximation. Quality is
  1762.                subjective, so programmers should experiment with
  1763.                different dither types to find the one that suits
  1764.                their needs.
  1765.                  If the target DC is a palette device and the
  1766.                WinG halftone palette has not been selected and
  1767.                realized into the target DC when a halftone brush
  1768.                is used, the visual results will be unpredictable.
  1769.                Use the WinGCreateHalftonePalette function to
  1770.                create a copy of the halftone palette, then select
  1771.                and realize it before using a halftone brush on a
  1772.                palette device.
  1773.                  The DISPERSED_nxn dither types create nxn
  1774.                patterns that approximate Color with a dispersed
  1775.                dot ordered dither.
  1776.                  The CLUSTERED_4x4 dither type creates a 4x4
  1777.                pattern that approximates Color with a clustered
  1778.                dot ordered dither.
  1779.                  Always free GDI objects such as brushes by
  1780.                calling DeleteObject when the object is no longer
  1781.                needed.
  1782.                Maximizing Performance
  1783.                Avoid redundant creation, selection, and deletion
  1784.                of identical brushes as much as possible. If an
  1785.                application will be using the same brush
  1786.                repeatedly, it should create the brush once and
  1787.                save it for later use, deleting it when the
  1788.                application is complete.
  1789.                Example
  1790.                The CUBE sample application (in the SAMPLES\CUBE
  1791.                directory of the WinG Development Kit) allows the
  1792.                user to select the dither type for creating shaded
  1793.                brushes and provides a good experiment in using
  1794.                the different dither types.
  1795.                See Also
  1796.                WinGCreateHalftonePalette WING_DITHER_TYPE
  1797.                CreateDIBPatternBrush CreateSolidBrush Halftoning
  1798.                With WinG Using GDI With WinGDCs Code Samples
  1799.  
  1800. WinGCreateHalftonePalette
  1801.                Creates an 8-bit palette used for halftoning
  1802.                images.
  1803.                  HPALETTE WinGCreateHalftonePalette(void)
  1804.                Return Value
  1805.                Returns the handle of a logical palettel
  1806.                containing the colors of the WinG halftone palette
  1807.                palette if successful. Otherwise,
  1808.                WinGCreateHalftonePalette returns 0.
  1809.                Comments
  1810.                The halftone palette should be selected into any
  1811.                DC into which the application will use WinG to
  1812.                halftone.
  1813.                  The WinG halftone palette is an identity
  1814.                palette: the logical palette indices and physical
  1815.                device indices are the same.
  1816.                  The halftone palette inverts correctly, so
  1817.                bitwise XORs invert colors properly.
  1818.                  See the Using an Identity Palette article for a
  1819.                discussion of identity palettes.
  1820.                Maximizing Performance
  1821.                Call WinGCreateHalftonePalette once at the
  1822.                beginning of your application. Select and realize
  1823.                the palette on WM_QUERYNEWPALETTE,
  1824.                WM_PALETTECHANGED, and WM_PAINT messages.
  1825.                Example
  1826.                The HALFTONE sample application (in the
  1827.                SAMPLES\CUBE directory of the WinG Development
  1828.                Kit) uses the halftone palette to dither 24-bit
  1829.                images to 8-bits using an 8x8 ordered dither.
  1830.                See Also
  1831.                WinGCreateHalftoneBrush WinGStretchBlt WinGBitBlt
  1832.                RealizePalette WM_QUERYNEWPALETTE
  1833.                WM_PALETTECHANGED Halftoning With WinG Using an
  1834.                Identity Palette Code Samples
  1835.  
  1836. WinGGetDIBColorTable
  1837.                Returns the color table of the WinGBitmap
  1838.                currently selected into a WinGDC.
  1839.                  UINT WinGGetDIBColorTable( HDC hWinGDC, UINT
  1840.                StartIndex, UINT NumberOfEntries, RGBQUAD far
  1841.                *pColors )
  1842.                Parameters
  1843.                
  1844.     hWinGDC      Identifies the WinG device context whose
  1845.                  color table should be retrieved.
  1846.     StartIndex   Indicates the first palette entry to be
  1847.                  retrieved.
  1848.     NumberOfEnt  Indicates the number of palette entries to
  1849.     ries         retrieve.
  1850.     pColors      Points to a buffer which receives the
  1851.                  requested color table entries.
  1852.                Return Value
  1853.                Returns the number of palette entries copied into
  1854.                the given buffer or 0 if it failed.
  1855.                Comments
  1856.                The pColors buffer must be at least large enough
  1857.                to hold NumberOfEntries RGBQUAD structures.
  1858.                  Note that StartIndex indicates an entry in a
  1859.                palette array, which is zero-based.
  1860.                NumberOfEntries indicates a count, which is one-
  1861.                based. If NumberOfEntries is zero, no color table
  1862.                entries will be retrieved.
  1863.                  WinGGetDIBColorTable will return 0 for
  1864.                WinGBitmaps with more than 8 bits per pixel.
  1865.                See Also
  1866.                WinGSetDIBColorTable WinGCreateBitmap
  1867.  
  1868. WinGGetDIBPointer
  1869.                Retrieves information about a WinGBitmap and
  1870.                returns a pointer to its surface.
  1871.                  void far *WinGGetDIBPointer(HBITMAP
  1872.                hWinGBitmap, BITMAPINFO far *pHeader)
  1873.                Parameters
  1874.                
  1875.     hWinGBit  Identifies the WinGBitmap whose surface
  1876.     map       should be retrieved.
  1877.     pHeader   If not 0, points to a buffer to receive the
  1878.               attributes and color table of the WinGDC.
  1879.                Return Value
  1880.                Returns a pointer to the bits of a WinGBitmap
  1881.                drawing surface if possible. Otherwise,
  1882.                WinGGetDIBPointer returns 0.
  1883.                Comments
  1884.                If it is supplied, pHeader must be large enough to
  1885.                hold a BITMAPINFOHEADER and enough RGBQUAD
  1886.                structures to hold the color table of the
  1887.                specified WinGBitmap.
  1888.                  If hWinGBitmap is not a WinGBitmap handle, this
  1889.                function will return 0 and *pHeader will remain
  1890.                unchanged.
  1891.                Maximizing Performance
  1892.                WinGCreateBitmap uses or returns the information
  1893.                returned by WinGGetDIBPointer as part of the
  1894.                creation process. If possible, applications should
  1895.                store the data when the WinGBitmap is created
  1896.                rather than calling WinGGetDIBPointer every time
  1897.                the information is required.
  1898.                  The address of a WinGBitmap surface will remain
  1899.                the same for the life of the WinGBitmap.
  1900.                See Also
  1901.                WinGCreateDC WinGCreateBitmap BITMAPINFO
  1902.                BITMAPINFOHEADER
  1903.  
  1904. WinGRecommendDIBFormat
  1905.                Fills in the entries of a BITMAPINFO structure
  1906.                with values that will give maximum performance for
  1907.                memory-to-screen blts using WinG.
  1908.                  BOOL WinGRecommendDIBFormat(BITMAPINFO far
  1909.                *pHeader)
  1910.                Parameters
  1911.                
  1912.     pHeader   Points to a BITMAPINFO structure to receive
  1913.               the recommended DIB format.
  1914.                Return Value
  1915.                Returns non-zero if successful. Otherwise, returns
  1916.                zero.
  1917.                Comments
  1918.                pHeader must point to enough memory to hold a
  1919.                BITMAPINFOHEADER. WinGRecommendDIBFormat will not
  1920.                return a color table.
  1921.                  For any combination of hardware and software,
  1922.                there will be one DIB format that WinG can copy
  1923.                fastest from memory to the screen.
  1924.                WinGRecommendDibFormat returns this optimal
  1925.                format, most important the recommended pixel
  1926.                format.
  1927.                  In many cases, WinG will find that it can copy
  1928.                a DIB to the screen faster if the DIB is in top-
  1929.                down format rather than the usual bottom-up
  1930.                format. WinGRecommendDibFormat will set the
  1931.                biHeight entry of the BITMAPINFOHEADER structure
  1932.                to -1 if this is the case, otherwise biHeight will
  1933.                be set to 1. See the DIB Orientation article for
  1934.                more information about these special DIBs.
  1935.                  WinGRecommendDIBFormat always recommends an 8-
  1936.                bit-per-pixel format under Windows 3.1. Other
  1937.                pixel formats are supported for Windows 95 and
  1938.                Windows NT. Code that uses this API should never
  1939.                assume that it will recommend an 8-bit format, as
  1940.                this may change depending on the run-time
  1941.                platform.
  1942.                Example
  1943.                See the WinGCreateBitmap API for sample code that
  1944.                uses WinGRecommendDibFormat.
  1945.                See Also
  1946.                WinGCreateBitmap BITMAPINFO BITMAPINFOHEADER Code
  1947.                Samples
  1948.  
  1949. WinGSetDIBColorTable
  1950.                Modifies the color table of the currently selected
  1951.                WinGBitmap in a WinGDC.
  1952.                  UINT WinGSetDIBColorTable( HDC hWinGDC, UINT
  1953.                StartIndex, UINT NumberOfEntries, RGBQUAD far
  1954.                *pColors )
  1955.                Parameters
  1956.                
  1957.     hWinGDC      Identifies the WinG device context whose
  1958.                  color table should be modified.
  1959.     StartIndex   Indicates the first palette entry to be
  1960.                  changed.
  1961.     NumberOfEnt  Indicates the number of palette entries to
  1962.     ries         change.
  1963.     pColors      Points to a buffer which contains the new
  1964.                  color table values.
  1965.                Return Value
  1966.                Returns the number of palette entries modified in
  1967.                the specified device context or 0 if it failed.
  1968.                Comments
  1969.                The pColors buffer must hold at least
  1970.                NumberOfEntries RGBQUAD structures.
  1971.                  If you want to update the display immediately
  1972.                (for example, in palette animation), use
  1973.                AnimatePalette to modify the system palette and
  1974.                then call WinGSetDIBColorTable to match it or the
  1975.                WinGDC will be remapped when it is blted. See the
  1976.                Palette Animation With WinG article for more
  1977.                information and sample code that does this.
  1978.                  Note that StartIndex indicates an entry in a
  1979.                palette array, which is zero-based.
  1980.                NumberOfEntries indicates a count, which is one-
  1981.                based. If NumberOfEntries is zero, no color table
  1982.                entries will be modified.
  1983.                Maximizing Performance
  1984.                It is not necessary to call WinGSetDIBColorTable
  1985.                every time you call AnimatePalette. Only call this
  1986.                API if you are about to blt and the destination
  1987.                palette has changed since the last call to
  1988.                WinGSetDIBColorTable.
  1989.                Example
  1990.                See the section titled Palette Animation With WinG
  1991.                for sample code and discussion of using
  1992.                WinGSetDIBColorTable to perform palette animation.
  1993.                  The PALANIM sample, in the SAMPLES\PALANIM
  1994.                subdirectory of the WinG Development Kit, performs
  1995.                simple palette animation and maintains an identity
  1996.                palette throughout.
  1997.                See Also
  1998.                WinGGetDIBColorTable WinGCreateBitmap Palette
  1999.                Animation With WinG
  2000.  
  2001. WinGStretchBlt
  2002.                Copies the source DC to the destination DC,
  2003.                resizing if necessary to fill the destination
  2004.                rectangle. Optimized for blting WinGDCs to screen
  2005.                DCs.
  2006.                  BOOL WinGStretchBlt(HDC hdcDest, int
  2007.                nXOriginDest, int nYOriginDest, int nWidthDest,
  2008.                int nHeightDest, HDC hdcSrc, int nXOriginSrc, int
  2009.                nYOriginSrc, int nWidthSrc, int nHeightSrc)
  2010.                Parameters
  2011.                
  2012.     hdcDest    Identifies the destination device context.
  2013.     nXOriginD  X coordinate of the upper-left corner of the
  2014.     est        destination rectangle in MM_TEXT client
  2015.                coordinates.
  2016.     nYOriginD  Y coordinate of the upper-left corner of the
  2017.     est        destination rectangle in MM_TEXT client
  2018.                coordinates.
  2019.     nWidthDes  Width of the destination rectangle..
  2020.     t
  2021.     nHeightDe  Height of the destination rectangle..
  2022.     st
  2023.     hdcSrc     Identifies the source device context.
  2024.     nXOriginS  X coordinate of the upper-left corner of the
  2025.     rc         source rectangle in MM_TEXT client
  2026.                coordinates.
  2027.     nYOriginS  Y coordinate of the upper-left corner of the
  2028.     rc         source rectangle in MM_TEXT client
  2029.                coordinates.
  2030.     nWidthSrc  Width of the source rectangle.
  2031.     nHeightSr  Height of the source rectangle.
  2032.     c
  2033.                Return Value
  2034.                Returns non-zero if successful, otherwise returns
  2035.                zero.
  2036.                Comments
  2037.                WinGStretchBlt requires both DCs to use MM_TEXT
  2038.                mapping mode at the time of the call or the
  2039.                results may be unpredictable. At other times, any
  2040.                mapping mode may be used in either DC.
  2041.                  WinGStretchBlt uses the STRETCH_DELETESCANS
  2042.                mode when expanding or shrinking an image, so
  2043.                stretched images may appear chunky.
  2044.                Maximizing Performance
  2045.                You will get the highest performance from
  2046.                WinGStretchBlt if you use a WinGBitmap created
  2047.                from header information supplied by a call to
  2048.                WinGRecommendDIBFormat.
  2049.                  WinGStretchBlt is optimized for copying WinGDCs
  2050.                to the screen.
  2051.                  Clipping can slow WinGStretchBlt down. In
  2052.                general, don't select clipping regions into or blt
  2053.                outside the boundaries of the source or
  2054.                destination DCs and avoid blting to an overlapped
  2055.                window if possible.
  2056.                See Also
  2057.                WinGBitBlt WinGCreateDC WinGCreateBitmap
  2058.                WinGRecommendDIBFormat Maximizing Performance With
  2059.                WinG
  2060.  
  2061. WING_DITHER_TYPE
  2062.                Dither types for halftone brushes.
  2063.                  WING_DITHER_TYPE
  2064.                Values
  2065.                
  2066.     DISPERSED_4x4
  2067.     DISPERSED_8x8
  2068.     CLUSTERED_4x4
  2069.                See Also
  2070.                WinGCreateHalftoneBrush WinGCreateHalftonePalette
  2071.                Halftoning With WinG CUBE
  2072.  
  2073. Debugging WinG Applications
  2074.                WinG will report runtime errors and helpful
  2075.                debugging messages (for example, whether or not
  2076.                WinG has recognized an identity palette) through
  2077.                standard Windows methods (the serial port or
  2078.                applications such as DBWIN.EXE) if you so desire.
  2079.                  If you want WinG to send error messages to the
  2080.                debug output, make sure the following entry
  2081.                appears in your WIN.INI file. If there is already
  2082.                a [WinG] section, just add the Debug=1 line under
  2083.                that heading.
  2084.   [WinG]
  2085.   Debug=1
  2086.                If you specifically do not want debug messages to
  2087.                appear, set this to:
  2088.   [WinG]
  2089.   Debug=0
  2090.                If neither debug level is specified in the [WinG]
  2091.                section of your WIN.INI file, debugging will be
  2092.                turned ON if you're using the Windows debug kernel
  2093.                and OFF if you're using the Windows retail kernel.
  2094.                Setting the Debug level explicitly in your WIN.INI
  2095.                will always override this default behavior.
  2096.  
  2097. Shipping a Product With WinG
  2098.                If your application uses WinG, you will have to
  2099.                copy the WinG runtime files into the \SYSTEM
  2100.                subdirectory of the Windows directory if WinG has
  2101.                not been previously installed on the target
  2102.                system. The following files should be installed on
  2103.                the user's system:
  2104.                WING.DLL
  2105.                WING32.DLL
  2106.                DIBENG.DLL
  2107.                WINGDIB.DRV
  2108.                WINGPAL.WND
  2109.                Microsoft will make the WinG libraries generally
  2110.                available to Windows developers for free
  2111.                distribution with Windows applications.
  2112.                  The Windows Software Development Kit includes
  2113.                the Setup Toolkit for Windows, which allows you to
  2114.                create and run setup scripts for installing
  2115.                Windows applications. Documentation for the
  2116.                toolkit comes with the Windows SDK and is also
  2117.                available on the Microsoft Developer Network CD.
  2118.                  The WinG Development Kit setup program installs
  2119.                the WinG runtime files using Microsoft setup
  2120.                exactly as they should be installed on a target
  2121.                user's system. Look at the SETUP.MST script on the
  2122.                WinG installation diskette to see how this is
  2123.                done.
  2124.  
  2125. Code Samples
  2126.                The WinG development kit contains a variety of
  2127.                code samples to help you develop fast applications
  2128.                quickly using WinG.
  2129.                Snippets
  2130.                The following code samples appear in this help
  2131.                file:
  2132.                ·  Setting up an off-screen buffer with WinG.
  2133.                ·  Calculating the memory address of a scanline in
  2134.                  a WinGBitmap.
  2135.                ·  Creating an Identity Palette.
  2136.                ·  Clearing the System Palette.
  2137.                ·  Maximizing palette availability using the
  2138.                  SYSPAL_NOSTATIC setting.
  2139.                ·  Copying a logical palette to a WinGBitmap color
  2140.                  table.
  2141.                ·  Matching an RGB color to a halftone palette
  2142.                  entry.
  2143.                Sample Applications
  2144.                The WinG Development Kit also contains source code
  2145.                for several sample applications, installed in the
  2146.                \SAMPLES subdirectory. The following applications
  2147.                are available:
  2148.                  DOGGIE allows the user to drag a sprite around
  2149.                the screen with the mouse, demonstrating off-
  2150.                screen composition, dirty rectangle animation, and
  2151.                custom blt routines. Includes source code for a
  2152.                sample 8-bit DIB to 8-bit DIB blt with one
  2153.                transparent color.
  2154.                  CUBE displays a halftoned rotating cube in a
  2155.                window that the user can manipulate with the
  2156.                mouse. It demonstrates off-screen composition,
  2157.                double-buffering, and using the halftone palette
  2158.                and halftone brushes with GDI to draw into a
  2159.                WinGDC.
  2160.                  TIMEWING tests and compares blt speeds of
  2161.                existing GDI functions with the WinG blt function.
  2162.                This sample will give you an idea of how WinG blts
  2163.                will compare to standard GDI functions.
  2164.                  HALFTONE converts 24-bit RGB DIBs to 8-bit DIBs
  2165.                by dithering them to the WinG Halftone Palette.
  2166.                The source code implements a standard 8x8 dither
  2167.                and color matching to the halftone palette.
  2168.                  PALANIM performs simple palette animation with
  2169.                an identity palette using WinG. This application
  2170.                uses all of the sample code appearing in this help
  2171.                file.
  2172.  
  2173. Balloon Doggie Sample
  2174.                The Balloon Doggie sample application, found in
  2175.                the SAMPLES\DOGGIE subdirectory of the WinG
  2176.                development kit, demonstrates a simple dirty
  2177.                rectangle animation system. It creates a WinGDC
  2178.                and a WinGBitmap, which it uses as an off-screen
  2179.                buffer, and uses WinGBitBlt to update the screen.
  2180.                  Balloon Doggie includes source code for
  2181.                TransparentDIBits (in TBLT.C and FAST32.ASM), a
  2182.                fast DIB-to-DIB blt with transparency.
  2183.                TransparentDIBits demonstrates the use of custom
  2184.                drawing routines with WinG to provide functions
  2185.                not present or unacceptably slow in GDI.
  2186.                  Note that DOGGIE.EXE requires MASM 5.1 to
  2187.                compile.
  2188.  
  2189. Spinning Cube Sample
  2190.                The CUBE.EXE sample application, found in the
  2191.                SAMPLES\CUBE subdirectory of the WinG development
  2192.                kit, demonstrates the use of Halftoning to create
  2193.                the appearance of more than 256 colors on an 8-bit
  2194.                palletized display device. Using
  2195.                WinGCreateHalftonePalette and
  2196.                WinGCreateHalftoneBrush, the spinning cube
  2197.                application halftones the faces of the cube to
  2198.                create lighting effects.
  2199.                  The Spinning Cube sample uses a standard double
  2200.                buffering architecture using a WinGDC and a
  2201.                WinGBitmap. It creates a WinGDC when the
  2202.                application starts, then creates and selects
  2203.                appropriate WinGBitmaps on WM_SIZE messages to
  2204.                keep the off-screen buffer the same size as the
  2205.                window's client region.
  2206.                  When appropriate, the application uses the GDI
  2207.                Polygon function to draw into the off-screen
  2208.                buffer then calls WinGBitBlt to copy the buffer to
  2209.                the screen.
  2210.                  The CUBE sample uses a simple floating-point
  2211.                vector and camera C++ class library (in DUMB3D.HPP
  2212.                and DUMB3D.CPP) that can be used as a starting
  2213.                point by those interested in generating 3D
  2214.                graphics.
  2215.  
  2216. WinG Timing Sample
  2217.                The timing sample, TIMEWING.EXE, found in the
  2218.                SAMPLES\TIMEWING subdirectory of the WinG
  2219.                development kit, times and compares the blt speeds
  2220.                of BitBlt, StretchDIBits, and WinGBitBlt. The
  2221.                application provides a summary you can use to
  2222.                compare the speeds of these techniques on various
  2223.                video configurations and a framework you can use
  2224.                for your own timing tests.
  2225.                  On most platforms, WinGBitBlt will perform
  2226.                favorably in comparison to BitBlt and will blow
  2227.                StretchDIBits away. SetDIBitsToDevice and
  2228.                StretchDIBits are essentially the same API, so
  2229.                this function is not timed.
  2230.                  Note that StretchDIBits and WinGBitBlt operate
  2231.                on device-independent bitmaps whereas BltBlt
  2232.                operates on device-specific bitmaps, which require
  2233.                no translation and can sometimes be stored in the
  2234.                local memory of the graphics card itself. For this
  2235.                reason, BitBlt usually runs at speeds approaching
  2236.                video memory bandwidth, which is the target speed
  2237.                for WinGBitBlt.
  2238.                  Also note that some drivers, such as the No
  2239.                9GXE, "cheat" on their BitBlts by keeping the last
  2240.                blted image in card memory. If the image is blted
  2241.                again, the card uses the cached image instead of
  2242.                the memory image. This can result in misleading
  2243.                performance benchmarks unless a different image is
  2244.                blted at each frame.
  2245.  
  2246. WinG Halftoning Sample
  2247.                HALFTONE.EXE, found in the SAMPLES\HALFTONE
  2248.                subdirectory of the WinG development kit, dithers
  2249.                24-bit DIBs to the WinG Halftone Palette using an
  2250.                8x8 ordered dither.
  2251.                  The main function, DibHalftoneDIB in
  2252.                HALFTONE.C, does the real work in the dithering.
  2253.                The process of calculating an ordered dither is
  2254.                too complex to describe here, but a description of
  2255.                the techniques involved can be found in "Computer
  2256.                Graphics: Principles and Practice" by Foley, van
  2257.                Dam, Feiner, and Hughes. See the Further Reading
  2258.                article for more information on this book.
  2259.                  The aWinGHalftoneTranslation array found in
  2260.                HTTABLES.C converts a 2.6-bit-per-pixel computed
  2261.                halftone index into an entry in the halftone
  2262.                palette. To calculate the nearest match of an RGB
  2263.                color to the halftone palette, HALFTONE uses the
  2264.                following formula:
  2265.                  
  2266.   HalftoneIndex = (Red / 51) + (Green / 51) * 6 + (Blue / 51) *
  2267.   36;
  2268.   HalftoneColorIndex = aWinGHalftoneTranslation [HalftoneIndex];
  2269.                See also the documentation for the
  2270.                WinGCreateHalftoneBrush  function and the
  2271.                Halftoning With WinG article.
  2272.  
  2273. WinG Palette Animation Sample
  2274.                The PALANIM.EXE application, found in the
  2275.                SAMPLES\PALANIM subdirectory of the WinG
  2276.                development kit, performs simple palette animation
  2277.                using AnimatePalette and WinGSetDIBColorTable as
  2278.                described in the Palette Animation With WinG
  2279.                article.
  2280.                  PALANIM gives the user the option of using the
  2281.                static colors in the palette to create a 254-color
  2282.                ramp or a 236-color ramp in an identity palette
  2283.                for fast blting.
  2284.                  The PALANIM sample uses the code samples found
  2285.                in this help file to perform all of its WinG
  2286.                functions.
  2287.  
  2288. WinG Glossary
  2289.                Bottom-Up DIB: A DIB in which the first scan line
  2290.                  in memory corresponds to the bottommost
  2291.                  scanline when the DIB is displayed. This is the
  2292.                  standard Windows DIB format.
  2293.                Color Table: The table of RGB color values
  2294.                  referenced by an color-indexed DIB.
  2295.                Dirty Rectangle Animation: A double-buffering
  2296.                  technique in which only the areas on the screen
  2297.                  which have changed are updated from frame to
  2298.                  frame.
  2299.                Double Buffering: An animation technique in which
  2300.                  images are composed entirely off-screen then
  2301.                  copied in whole or in part to the display.
  2302.                Halftone Palette: An identity palette carefully
  2303.                  filled with an array of colors optimized for
  2304.                  dithering images to 8 bits per pixel.
  2305.                Halftoning: A technique for simulating unavailable
  2306.                  colors using special patterns of available
  2307.                  colors. Also called dithering.
  2308.                Identity Palette: A logical palette that is a 1:1
  2309.                  match to the system palette.
  2310.                Logical Palette: A palette object created by an
  2311.                  application using the CreatePalette function.
  2312.                Palette: A table of RGB colors associated with a
  2313.                  GDI Device Context.
  2314.                Palette Animation: An animation technique in which
  2315.                  palette entries are shifted to create the
  2316.                  appearance of movement.
  2317.                Static Colors: Reserved colors in the system
  2318.                  palette that can never be changed by an
  2319.                  application. Under normal circumstances, twenty
  2320.                  colors are so reserved.
  2321.                System Colors: The colors used by Windows to draw
  2322.                  captions, menu bars, text, and other Windows
  2323.                  display elements.
  2324.                System Palette: A copy of the hardware device
  2325.                  palette maintained by the Palette Manager.
  2326.                Top-Down DIB: A DIB in which the first scan line
  2327.                  in memory corresponds to the topmost scanline
  2328.                  when the DIB is displayed.
  2329.                WinGBitmap: A special HBITMAP with a DIB as its
  2330.                  drawing surface created for use in a WinGDC.
  2331.                WinGDC: A device context with a DIB as its drawing
  2332.                  surface.
  2333.  
  2334. Further Reading
  2335.                The following collection of books, articles, and
  2336.                sample code may help clarify the use of DIBs,
  2337.                provide insight into custom drawing routines, or
  2338.                generally ease the transition from device-
  2339.                dependent bitmaps to WinGDCs. All of these are
  2340.                available on the Microsoft Developer Network CD.
  2341.                Some are included with the Windows SDK.
  2342.                Foley, vanDam, Feiner, and Hughes, Computer
  2343.                Graphics: Principles and Practice, Second Edition,
  2344.                Addison-Wesley, 1991
  2345.                Gery, Ron, "Using DIBs with Palettes," Microsoft
  2346.                Technical Article, 3 March 1992
  2347.                Gery, Ron, "DIBs and Their Use," Microsoft
  2348.                Technical Article, 20 March 1992
  2349.                Gery, Ron, "The Palette Manager: How and Why,"
  2350.                Microsoft Technical Article, 23 March 1992
  2351.                Petzold, Charles, "The Device-Independent Bitmap
  2352.                (DIB)," Programming Windows 3.1, Microsoft Press,
  2353.                1992, pp. 607-619
  2354.                Rodent, Herman, "Animation In Windows," Microsoft
  2355.                Technical Article, 28 April 1993
  2356.                "How To Use a DIB Stored as a Windows Resource,"
  2357.                Microsoft PSS Article Q67883, 26 April 1993
  2358.                "Multimedia Video Techniques," Microsoft Technical
  2359.                Article, 20 March 1992
  2360.                Windows 3.1 Software Development Kit samples:
  2361.                DIBIT, DIBVIEW, CROPDIB, WINCAP, SHOWDIB, FADE
  2362.                Microsoft Technical Samples, TRIQ, draws triangles
  2363.                or boxes directly into device-independent bitmap
  2364.                memory.
  2365.  
  2366.