ebook img

Directdraw Programming PDF

378 Pages·1996·117.72 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Directdraw Programming

® Learn how to create superfast graphics for killer games and multimedia applications ® Optimized for use with major C/C++ compilers for ~ Windows 95 or Windows NT ® Master the sprite class,tiling class, and objectclass, and TeET ER Ys ToT ® Maximize your programming “success by using the right drivers and configuration Y ah LEN i cf il ommm© —EE£wn 2 m M&T Books A Division ofMIS:Press, Inc. A Subsidiary of Henry Holt and Company, Inc. 115 West 18th Street New York, New York 10011 © 1996 by M&T Books Printedin the United States of America All rights reserved. No part ofthis book may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without prior written permission from the Publisher. Contact the Publisher for information on foreign rights. Limits ofLiability and Disclaimer ofWarranty The Author and Publisher ofthis book have used their best efforts in preparing the book and the programs contained in it. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The Author and Publisher make no warranty ofany kind, expressed or implied, with regard to these programs or the documentation contained in this book. The Author and Publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use ofthese programs. All products, names and services are trademarks or registered trademarks of their respective companies. Library ofCongress Cataloging-in-Publication Data Timmins, Bret. DirectDraw programming / by Bret Timmins. p. cm. ISBN 1-55851-460-0 1. Computer graphics. 2. Computer animation. 3. DirectDraw. 4. Computer games. 1. Title. T385.T56 1996 794.8'16765-dc20 9554175 CIP 97.96 95 94 4 3 21 Associate Publisher: Paul Farrell EditorinChief: Cary Sullivan Development Editor: Andy Neusner Copy Editor: Karen Tongish Technical Editor: David Petchey Copy Chief: Shari Chappell Chapter One: An Introduction to DirectDraw .............1 wove eeeeee Topics Covered in this Book .........coociiiiiiieoeeoee 1 PC Graphics, A Brief HIStory 2 eee ooo eeeeee, Enter Windows eeeeeeeeeeee 4 DirectDraw Features .......ocoooiiiiiiiiieeeeeeeeeeeeeeee 4 Chapter Two: How to Get the Most from this BOOK .....c.cccceeeeeeeceeeemerseennn.BeNAcereennnea? o.oo eee Installing the Game SDK eeeeee7 Finding a DirectDraw Video DEIVEr c...ooviiiiiiieeeeeeeeeeeeeeeeeeeeeeeeee 9 Louie C/C++ Compilers Supported ......ccoooovivivineiiiecceececeeeeeeeeee 10 Using ANSI C ooo eeeeeeeeeeeeeeeeeeeens 11 The WIN32 APL 11 Chapter Three: DirectDraw Concepts 13 ........cccoevreeuneeee. eee ooo eee eee The DirectDraw COM eeee ee 14 The DirectDraw Model ....oooiiiiiiiieeeee eeeeeeeeeeeeee eeee 15 eee DirectDraw Communication ..........oceeeeeeeeeeeeseeeeeeeee 15 The GDI and DirectDraw ..ooooeeeeeeeeeeee eeeeee 16 Chapter Four: The DirectDraw Objecte........e.........e. J—J The DirectDrawCreate FUNCHON o.oeeooveoeeeeioeeeoeeeevee 17 The SetCooperativeLevel function ............ccocoeevveieeeeeieeeeeeeee eee, 18 The DirectDraw GetC2aps FUNCHON esses 19 The DDCAPS Structure ...icimmisinimsm svnsssressessssrinn19 The Connect Program...aiiiissamisssms csosisiohsiinssesseesserssssessssas 20 DIRECTDRAW PROGRAMMING Contents ChapterFive: Creating Simple DirectDraw Surfaces: The Primary Surface ................. 27 .......ccocivieiiieninainsn The Surface Metaphor 27 Linear Memory ACCESS ......oovviiiiieiiinininininieiine 28 Surface Properties .....ooiivieieiininnisiiiiinc 29 The Primary Surface ......oovviviininineeiiiciis 29 SUFEACE TPRAtION. tiviisievarinssisinsssrissennsbioebransasssiasssnsssilisonessstsssiasvinassrrasanresssOU Function... The DDSURFACEDESC SErUCLUTE ..vvvovveveereeeeeeeereeeeeniesieesiesessieesinsnnesennne 31 Function... The SetDisplayMode Step...32 The RestoreDisplayMode 32 Creating a Primary Surface Step by 33 The DirectDrawSurface Object .......oviivnniiiniiie, 33 The Lock FUTCtON v.eeessresiioeeseossosserssiniasiohessidnsssnsiinadiis sassssssrssniivhensasssssoshsvie 34 The Unlock FURCHON viviinseiiessinsessassitsnssboniisenssoisssarsis ibanesrsbassteosniispisisssr Od The DirectDrawSurface Release Function ........cccecevvevieniienienneencienicnnnn30 The PRIMARY.CPP program iii yeabeis shiniessassssebevsoharessbaReesiaDD eis Chapter Six: Creating DirectDraw Surfaces: The Back Buffer and Page Flipping 45 .....cccccceveeneecen.... 45 Page FPPING .cvovvvieiiiitieei Page Flipping UnderoDirectDraw ..c.....oc.oon.vvei.iisii46 The Flip Mechanism ......coooeviniiiniiininii 47 .....i...cooviviiinin, Creating a Back Buffer 48 The GetAttachedSurface function ...........eeeeeeeeeiiiiieiiiiiii, 49 The Flip Function 50 The BACKBUFF.CPP Program aESieibithessfis aittesvsaenesssateniatsntesanesas dQ) Chapter Seven: Creating DirectDraw Surfaces: es The Off-Screen Surface ... 59 ovine Surface... Being Off Screen .......oiiiiiiieiiiinci 59 Creating an Off-Screen 60 ........ccooooviiini, The System Memory Surface 61 62 BING DIRECTDRAW PROGRAMMING Contents eee eee The BItFast function .......ocoovviieeioeiieieee oeoee o62 The OFF_SCR.CPP Program 64 ...........ccccooveveuiuieeeeieeeeeeeeeeeeeeeeeeeeeee Using Off-Screen Surfaces as Buffers eee74 ......ooooooevooe The OFFSCREEN1.CPP Program .....ccocooiiiiiiiii 74 Chapter Eight: Biting: Transparent Blting .87 ................. eee The Transparent PIXel .........ccoooovoiiiiiiiireeieeeeeeeeeeeeeeeeeeeeee e87 Using Transparency for Depth Effects ..o.ooooiiiiiiiiiiccececeeee 88 The Color Key ...c.covuiiiiiiiiiieieeeeeeeeeeeee eeeeeeeeeeee88 The DDCOLORKEY Structure 89 ..oo.eeeveeeeeeeeeoee eee The SetColorKey Function ..........c.ocoeveveioveiiiiioiesioeeeeeeeeeeee 89 The GetColorKey Function ........cccocoeveviviioiiiiiiiiiceeeeeeeeeeeeee eeeeee,90 The TB_SRC.CPP Program ..........ccccoevoviuiieeiiiieeieieeeeeeeeeeeeee 91 The TB_DEST.CPP Program ............ccccooeeioiieieeieeeeceeeeeeeeeeeeeeees ees 103 Chapter Nine: Biting: Blt Effects ...............S—— Vr eee Blt or BILFast? ..ooooiiiiiiieeeeeeeeeeeeeee eeeeeeeeeeeeeee 117 The Blt FUNCcLOcNo©otoveoviiiiiiiicceccee eeoeeeeoeeeeeen, 118 DDBLT_FX steteetecee 120 esteeveeseesssesesses sssessseeneesses aeons The Color Fill 121 The SHRINK.CPP Program ...........cccoceeioviiiieeiieieeeeeeeeeeeeeeee ee, 121 Chapter«Ten: Boiting: tDireictDtrawiCslippers............... 133 CLIPPING eeeeeeeeeeee 133 Clipping Under DirectDraw .......c.c.ooveveviieeeeeieeeeeeeeeeeeeeeeeeeeeeseeeeeees 135 eee The CreateClipper FUNCtion .......ccoovovivivivivieieiiccceceeeeeeeee 135 Creating Clip LIStS ..oooviiniiiiiiiicecccceeeeeee 136 eee The SetHWnd FUNCUON .....oovieeiieiiereceeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee eee 136 The SetClipList FUNCHON ..ovovoviieeieiieeeieeeeceeeeeeeeeeeeeeeeeee 137 Using the RGNDATA Structure .........ocooveeeeereeeeeeeeeeeeeeeeeeesesso 137 A SetClipList EXample 138 .........cccoivvrrierereverennreerenneerenicssesssssesssesessenesssssssnenns The SetClipper FUNCHON i....cumsisisimsssassesesssseserssassosssssasnsassesseneesessessasnes 139 Clipper Limitations ........vsiscicisbosesisismsessersessesmsnsnsstosbiriidiiinsarenssssssssseses 139 The CLIP.CPP Program. ....ususisissssssssssessesesencsercmensisiiotesiosssoses soossesnsmmmns 140 DIRECTDRAW PROGRAMMING Contents Chapter Eleven: DirectDraw Color ..........ccccceuuevr..... 153 Palette MORE 153 ..iviiiariiiinmeiserissesssnntansosesessssssslunsasaiasanssssssassidhansssssarssvetessmnions Palettes and DITECtIDITAW oiiveriicecersioriessnnsisisnsessssiabes forsssrnatsssessshvess s6sshutsove154 o.oosess The CreatePalette TUNCLION .uvvvvveeereiiiiieiiiieirenieneieninnereerieererrerr 155 The SetPalette FUNCHON juiyeecrrrtesrcersensessosisoississrssssssssesistssnsasasvaaifinnsonsnaisnss 156 The SetEntries and GetEntries Functions ......oocccveeeivniiniiniinnn. 157 Palette-Independent Color 158 Hicolor RGB Video Modes 158 ......cccoiivierseercemsessionisnassonnnsrssssserissssasasanessssoesesssans The GetSurfaceDesc Function ....ccccceeeiieiiiiieiiiiinininiciiiii 159 The DDPIXELFORMAT Structure 160 ..cccccecveeereeseeeeesacsineeeesisnneesissmanesssssnnnes The HICOLOR.CPP Program .......ccoovinminnneneninenescecnneinsiniisen 160 Chapter Twelve: Running Windoweed ..........s............. 175 Window... The GDI and the Primary Surface ........coovniiniinii, 175 Running in a Noormal oWoindow... 176 Writing to the Primary Surface 176 Using the GDI es178 The GetDC FuniCtion ..iveiitsiveivsssseesivsiiiisenssisarasshesssvhssonasunsinsipasessssrioerss 178 The ReleaseDC.F.u.ncctioon o.ii.vii.ieisomisiovissvoissiitosiisnisssisihrvssstvnesaivssiseiossisss es178 Finding the GDI ........oooiiie. 178 The FlipToGDISurface Function 179 Palette CONtIOl o..oiiiiiiiiviissiieiissssivsessbondsbbsnrossossessnnissanpoasnssisns sanssssssonsvrrns 179 Palette Control and DirectDraw ....coocvvvveeeieviniiminiiiiiicieninneeen 180 The WINDOW.CPP Program ........ccecooviniiiiininnnciiiiiii 180 Chapter Thirteen: Debugging sss DirectDraw Program«s ioi iivieos 201 The GDI Debugger ....cccveieeeeieieeiniiiss 201 202 A Debugger COMPrOMISe .......oooviiniiine Kernel-Level Debuggers 203 nn, The DEBUG.CPP Program ........cccocoviviiiiniiiniiniiii 204 DIRECTDRAW PROGRAMMING Contents wooo Appendix A: DirectDraw Reference ........ccccueeeeeeene-n.219 DirectDraw APIS ccc 219 DirectDrcawlreate wooveiseaeeeeeeee,219 cotteeree DirectDrawlinumerate .......c..ocooooviiiiiiiieeeeeeeeeeeee eeeeee 220 DirectDraw Member Function Reference .......oo.oouveeeeeeeoeeeeeeeeeoeeo 221 eee ADARET eee 221 COMPACT wovceeeeee 221 CreateCHPPET ...c.iiiiiieiieece eee,222 CreatePalette eeeeeeeeeeeeeeeeee,223 DCruepalteicSaUteToSauCrefac.e..o.voiiiiiiiiv.iiiicoccceeeoeeeeeieeeeeeseeeeeeeeeeeeee eeeee222254 EnumDisplayModes ....c.coooviiiiiiiiiiccceeceeeeeeeee 226 EnumSurfaces ....owooooeeiooiioioivcicceeceecceeeeee eeeeeceeeeeeeeeeeeeees228 FEPTOGDISUTTACE eee eee,230 eters GEtAPS 230 GetDisplayMode v...ooiiiiiiiiiiiii i 231 GEtFOUrCCCOES ooivviiiiiiiieieceecee eee 232 eeeeee GetGDISUITACE eeeeeeeee 232 GetMonitorFrequency .o...o.oooiiiiiiceeeecee ee233 GEtSCANTANoE .ooiviiiiiiiiciicececeeeeeeeeeeeeeeeeeeeeeee,234 GetVertical BlankStatuos .........ocooviv.iiiiiiiieeeoeeee oeee234 INTHALIZEoie eeeeeeeeeeee,235 QueryInterface .......ccceooeiiiieiiii ee236 RELEASE eeeeeeeeeeeeeeeeee 236 SetCooperative Level 237 eeeeee SetDisplayMode ......o.ooviiiiiiiiiiiicicececeee eee238 WaitForVoerticwal Boank ...e......c.eooeooiiviiiieiitriteeeeetee eeee r 240 DirectDrawClipper Membeer Function Reeference .....e.....cccocoocvvvevvv,eevveansn.. 241 AAR eeeeeeeee eee 241 oii GEtCIPLASE 241 eeea,as GetHWId eeeeeeeee 242 wove INIEATIZE 243 eects, IsClipListChanged ......c.ocooviiiiiiiiiicecceeeeeee 243 QUEryINtErface 244 .......i...ccjivmssiiiiiinimitinimeesisrssesnossanshinsebatarsoesensssrsssnns DIRECTDRAW PROGRAMMING Contents RECAB: icsiiinrensssssesiosonsstintssnsiesiersansas |i tkindnsesssnts Bosiiosnaninsbusstesvestensebisnnan245 se245 SSEtCHtPLIISE ..cvvviviirririrersrermrernrninssseeesestnseseetstsessentseinisinseesessssssssenans 246 cioviieiioniiii iasinincansansivnassnsovssbinnnetinsestiossssioinasnnnsesiorsasshassorsnbnns DirectDrawPalettie Miemiber Function Reference .......cccccoccvviiiiiiiiiinnninn. 247 AAAREE oseii idirsanssesi.uanisnivn ibeohatiesassivasanssssinge sioons sinenavossuivssibenst247 247 GEtCaPS wuvvivvririiniie 248 GEtEDATION iii veriorvissisvissitssossnonsananssranbonsinissiachansatsiastaesonnssisvbsiastastisvnsss InItalIZE iiiiviiineriiii ies anisiiriciivissvessssibaninsssugyabosassssstasbuansnnssssssssissasbanas 249 250 QueryInterface eReEtlenaBeiecsiiisiitiiiiiii ivsiiavnsssinionn assole£oss50esasxBosdea Tenmasdsonnsbibevisosnas 251 iii) 251 iiieisiviniinhansissasarsine cyaisyessvinhsnnreosvab dbivsstunsiasonas sosnbvinainos DirectDrawSurface Member Function Reference ........cccocveviviniinniiinnnnn.253 ec AddAachedSUTTHCE ©.viii miisiaieni derniersvi boirbnastucsinsvosrissivitressisiasogsses 253 AddOverlivayDiriityRieicit .a....d.cooveviiiiiiiiiininaiiineniii 253 AddRel aminaiiaasiat dli,254 Bl iii teTaeanebebehdeesedheaeaaresvebasR255 BIBALCR oven vsiissiiiiiassesnisnnninrossasssivatisnsosssoniesnsirborbuassuniossnssossitusyibusss 259 BUEASE iviisosisadivisisessvseraslibsions siorasassonsusnnanhianssissassssssdinsnate 261 262 IPSTCRECE .ovviriiiiniiriisie DeleteAttachedSUTTAces ..ovviiveiiieriiliviiinaibeinniisesnssionmssssnisissosssadssrasereras 263 EnuinAttachedSurfaces ..oiviiiiisi ietienesioibtsaiisessisecorssosiittsdaerste264 en EnumOverlayZOrders ......s...cooveivsiiininininnsniiii 265 266 FHP .oviiioniniirinnncssnsmensmsssnsssssnnssssssisssssnosissstssssasessnstsnssssssasssessnsassaes CetAtachEASUTIACE |...viiivisasfiaceresstobisvossuasobressuas dissthnn assbiossucihvanesiasins267 GetBItSTatUR iLoiiniivninriinihiesisioniccitisnBEtBsAeGtttsvibeshanty sasesns268 GEtCAPS vovevivererinirrieieeresnsstssst sasssates sashes269 269 GEtCLPPET wovvveviiiirieieieisi SR GetCoalorKey ...L.ovviaiiiiiiinnniin SE 270 EE RETR RR ee 271 272 GetFLPSLatus ..oovceeeveiiicieiiinie GetOverlayPosition ......c.ccceeieieninininnnisessissssssesssinsiiisns 273 GOtPAlRtte ....cvveivmissoiin a dodiasis isisis ssnivetboaneshsvn siavsinsasssssvanivossflakfa dmeiumsions 274 GetPIXEIFOTIAt .iviiiivsiioeiiidinossisonesevos thatsesasso ssdohisessevsupei sassssi ivasssvars 274 275 GetSUTTACEDIEEC wviiviiesiesisiasesssseressanmencbinssitssanssssanaaisfossssssidbinisenainneisosanss TNIATIZE ooeieeeeeeeoeivavisiosiassiseisseransressnsinsnsivabsenassiosasssnunnnasinnsssssinarssssane 276 276 LELLOBE oiiiriiineennonensnvsiasssnaiessinnnssninavossisanisonsnnsnrsnsnntosbonvosennsnboasto raersssnsionss 277 LOCK voviiitionieiaiunbunsivonssioittinssnint i6sevaniobiissnsnnnanassasasisinsensissnsanntessadsvrestossass QUEryInterface .........ccvuveevererisisnenietninsentnrensinnstesrsnsessnsesennsnsssssssssns 279 DIRECTDRAW PROGRAMMING Contents weieee weeee eeete REISE oii eee 280 ReleaseDoC iieee eeeeee280 vicvecee RESTOTE eeeeeeeeeeee 281 SELCHPPET 282 eee SetColorKoey ....o.iiiiiiiiiiiiee 282 SetOVerlayPOSTION w.ovoveviieisiececceeeeeeeeee eeeeeeeee,283 SEtPALEIE 284 UNLOCK 285 UpdateOverlay .....c.ococoiiiiiiiiiiiiiceceeeeeeeeeeeeeeeeeeeeeee,e 286 eee UpdateOverlayDisplay .........ocooooieviveuiuiiiiiieeeeeeeee 289 UpdateOvecrlayZOrdeer .......e..o.ooueeuiiiiiiiieieeeeeeeeeeeeeeeeeeee eee,290 DirectDraw SUrUCHUTLES oovivieieeeeeoeeeeee eeeeeie ceee292 DDCAPS eeeeeeeeeeeeeee 298 DDCOLORKEY .oociiiiiiioiieceeeeoeeeeeee3eeeee1eeee.ee30eee0ee.3)000 DDMODEDESC eee oii DDOVERLAYEFX o.oo. 0312 DDPIXELFORMAT DDSURFACEDESC 316 eee. DirectDrawClpper ......ccccooviiiniiiiiicceceeeceeeeeeeeeeeeeee 320) DirectDrawPalette «ooo ieeeeeeeeeeeeeeeeeeeeeeeeeee3eee9e32]0) DirectDrawSurface ......coooviiiiioeeeeeeeeeeeeee DirectDraw Return Values ..........ocooeveeeeevoeoioeeooeeeeeeoee 322 DirectDraw Enumeration Call Back Return Values .....oovoovovovvvvini.322 DirectDraw Error Return Values ......coo.ooeooeeeeooooooeoee.329 Appendix B: ModeX Surfaces ....333 ........cccoeeeveereereceennes ModeX ReStrICtioNS ...ooveeieeeieiieeeeeeeeeeeeeee eeeeeeeeeoee.333 The MODEX.CPP Program eee334 .......cccccoccovvveiieeeiceeeeeeeeeeeeeeeee Appendix C: Bibliography 349 ........cccccceevemvccsececrereennn. INAOX 35 cociconnsivivnsenanonsrosbibibsbibiitthe scanmonsssstiiosbisemmmmnnnnanse 1

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.