renderd3d.cpp 151 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188
  1. #ifdef _d3d
  2. #include "Hunt.h"
  3. #include "stdio.h"
  4. #undef TCMAX
  5. #undef TCMIN
  6. #define TCMAX ((128<<16)-62024)
  7. #define TCMIN ((000<<16)+62024)
  8. #define _ZSCALE - 16.f
  9. #define _AZSCALE (1.f / 16.f);
  10. Vector2di ORList[2048];
  11. int ORLCount = 0;
  12. LPDIRECTDRAWSURFACE lpddPrimary = NULL;
  13. LPDIRECTDRAWSURFACE lpddBack = NULL;
  14. LPDIRECTDRAWSURFACE lpddZBuffer = NULL;
  15. LPDIRECTDRAWSURFACE lpddTexture = NULL;
  16. DDSURFACEDESC ddsd;
  17. LPDIRECT3D lpd3d = NULL;
  18. LPDIRECT3DDEVICE lpd3dDevice = NULL;
  19. LPDIRECT3DVIEWPORT lpd3dViewport = NULL;
  20. LPDIRECT3DEXECUTEBUFFER lpd3dExecuteBuffer = NULL;
  21. LPDIRECT3DEXECUTEBUFFER lpd3dExecuteBufferG = NULL;
  22. LPD3DTLVERTEX lpVertex, lpVertexG;
  23. WORD *lpwTriCount;
  24. HRESULT hRes;
  25. D3DEXECUTEBUFFERDESC d3dExeBufDesc;
  26. D3DEXECUTEBUFFERDESC d3dExeBufDescG;
  27. LPD3DINSTRUCTION lpInstruction, lpInstructionG;
  28. LPD3DPROCESSVERTICES lpProcessVertices;
  29. LPD3DTRIANGLE lpTriangle;
  30. LPD3DLINE lpLine;
  31. LPD3DSTATE lpState;
  32. BOOL fDeviceFound = FALSE;
  33. DWORD dwDeviceBitDepth = 0UL;
  34. GUID guidDevice;
  35. char szDeviceName[256];
  36. char szDeviceDesc[256];
  37. D3DDEVICEDESC d3dHWDeviceDesc;
  38. D3DTEXTUREHANDLE hTexture, hGTexture;
  39. HDC ddBackDC;
  40. BOOL D3DACTIVE;
  41. BOOL VMFORMAT565;
  42. BOOL STARTCONV555;
  43. BOOL HANDLECHANGED;
  44. #define NUM_INSTRUCTIONS 5UL
  45. #define NUM_STATES 20UL
  46. #define NUM_PROCESSVERTICES 1UL
  47. void RenderFSRect(DWORD Color);
  48. void d3dDownLoadTexture(int i, int w, int h, LPVOID tptr);
  49. BOOL d3dAllocTexture(int i, int w, int h);
  50. void d3dSetTexture(LPVOID tptr, int w, int h);
  51. void RenderShadowClip (TModel*, float, float, float, float, float, float, int, float, float);
  52. void ResetTextureMap();
  53. int WaterAlphaL = 255;
  54. int d3dTexturesMem;
  55. int d3dLastTexture;
  56. int d3dMemUsageCount;
  57. int d3dMemLoaded;
  58. int GVCnt;
  59. BOOL LINEARFILTER = TRUE;
  60. int zs;
  61. float SunLight;
  62. float TraceK,SkyTraceK,FogYGrad,FogYBase;;
  63. int SunScrX, SunScrY;
  64. int SkySumR, SkySumG, SkySumB;
  65. int LowHardMemory;
  66. int lsw;
  67. int vFogT[1024];
  68. BOOL SmallFont;
  69. typedef struct _d3dmemmap {
  70. int cpuaddr, size, lastused;
  71. LPDIRECTDRAWSURFACE lpddTexture;
  72. D3DTEXTUREHANDLE hTexture;
  73. } Td3dmemmap;
  74. #define d3dmemmapsize 128
  75. Td3dmemmap d3dMemMap[d3dmemmapsize+2];
  76. WORD conv_555(WORD c)
  77. {
  78. return (c & 31) + ( (c & 0xFFE0) >> 1 );
  79. }
  80. void conv_pic555(TPicture &pic)
  81. {
  82. if (!HARD3D) return;
  83. for (int y=0; y<pic.H; y++)
  84. for (int x=0; x<pic.W; x++)
  85. *(pic.lpImage + x + y*pic.W) = conv_555(*(pic.lpImage + x + y*pic.W));
  86. }
  87. void CalcFogLevel_Gradient(Vector3d v)
  88. {
  89. FogYBase = CalcFogLevel(v);
  90. if (FogYBase>0) {
  91. v.y+=800;
  92. FogYGrad = (CalcFogLevel(v) - FogYBase) / 800.f;
  93. } else FogYGrad=0;
  94. }
  95. void Hardware_ZBuffer(BOOL bl)
  96. {
  97. if (!bl) {
  98. DDBLTFX ddbltfx;
  99. ddbltfx.dwSize = sizeof( DDBLTFX );
  100. ddbltfx.dwFillDepth = 0x0000;
  101. lpddZBuffer->Blt( NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &ddbltfx );
  102. }
  103. }
  104. void d3dClearBuffers()
  105. {
  106. DDBLTFX ddbltfx;
  107. ddbltfx.dwSize = sizeof( DDBLTFX );
  108. if (VMFORMAT565) ddbltfx.dwFillColor = (SkyR>>3)*32*32*2 + (SkyG>>2)*32 + (SkyB>>3);
  109. else ddbltfx.dwFillColor = (SkyR>>3)*32*32 + (SkyG>>3)*32 + (SkyB>>3);
  110. lpddBack->Blt( NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx );
  111. ddbltfx.dwSize = sizeof( DDBLTFX );
  112. ddbltfx.dwFillDepth = 0x0000;
  113. lpddZBuffer->Blt( NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &ddbltfx );
  114. }
  115. void d3dStartBuffer()
  116. {
  117. ZeroMemory(&d3dExeBufDesc, sizeof(d3dExeBufDesc));
  118. d3dExeBufDesc.dwSize = sizeof(d3dExeBufDesc);
  119. hRes = lpd3dExecuteBuffer->Lock( &d3dExeBufDesc );
  120. if (FAILED(hRes)) DoHalt("Error locking execute buffer");
  121. lpVertex = (LPD3DTLVERTEX)d3dExeBufDesc.lpData;
  122. }
  123. void d3dStartBufferG()
  124. {
  125. ZeroMemory(&d3dExeBufDescG, sizeof(d3dExeBufDescG));
  126. d3dExeBufDescG.dwSize = sizeof(d3dExeBufDescG);
  127. hRes = lpd3dExecuteBufferG->Lock( &d3dExeBufDescG );
  128. if (FAILED(hRes)) DoHalt("Error locking execute buffer");
  129. GVCnt = 0;
  130. hGTexture = -1;
  131. lpVertexG = (LPD3DTLVERTEX)d3dExeBufDescG.lpData;
  132. lpInstructionG = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDescG.lpData + 400*3);
  133. lpInstructionG->bOpcode = D3DOP_PROCESSVERTICES;
  134. lpInstructionG->bSize = sizeof(D3DPROCESSVERTICES);
  135. lpInstructionG->wCount = 1U;
  136. lpInstructionG++;
  137. lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstructionG;
  138. lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
  139. lpProcessVertices->wStart = 0U;
  140. lpProcessVertices->wDest = 0U;
  141. lpProcessVertices->dwCount = 400*3;
  142. lpProcessVertices->dwReserved = 0UL;
  143. lpProcessVertices++;
  144. lpInstructionG = (LPD3DINSTRUCTION)lpProcessVertices;
  145. if (!LINEARFILTER) {
  146. lpInstructionG->bOpcode = D3DOP_STATERENDER;
  147. lpInstructionG->bSize = sizeof(D3DSTATE);
  148. lpInstructionG->wCount = 2;
  149. lpInstructionG++;
  150. lpState = (LPD3DSTATE)lpInstructionG;
  151. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
  152. lpState->dwArg[0] = D3DFILTER_LINEAR;
  153. lpState++;
  154. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
  155. lpState->dwArg[0] = D3DFILTER_LINEAR;
  156. lpState++;
  157. lpInstructionG = (LPD3DINSTRUCTION)lpState;
  158. }
  159. if (FOGENABLE) {
  160. lpInstructionG->bOpcode = D3DOP_STATERENDER;
  161. lpInstructionG->bSize = sizeof(D3DSTATE);
  162. lpInstructionG->wCount = 1;
  163. lpInstructionG++;
  164. lpState = (LPD3DSTATE)lpInstructionG;
  165. lpState->drstRenderStateType = D3DRENDERSTATE_FOGCOLOR;
  166. lpState->dwArg[0] = CurFogColor;
  167. lpState++;
  168. lpInstructionG = (LPD3DINSTRUCTION)lpState;
  169. }
  170. }
  171. void d3dStartBufferGBMP()
  172. {
  173. ZeroMemory(&d3dExeBufDescG, sizeof(d3dExeBufDescG));
  174. d3dExeBufDescG.dwSize = sizeof(d3dExeBufDescG);
  175. hRes = lpd3dExecuteBufferG->Lock( &d3dExeBufDescG );
  176. if (FAILED(hRes)) DoHalt("Error locking execute buffer");
  177. GVCnt = 0;
  178. hGTexture = -1;
  179. lpVertexG = (LPD3DTLVERTEX)d3dExeBufDescG.lpData;
  180. lpInstructionG = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDescG.lpData + 400*3);
  181. lpInstructionG->bOpcode = D3DOP_PROCESSVERTICES;
  182. lpInstructionG->bSize = sizeof(D3DPROCESSVERTICES);
  183. lpInstructionG->wCount = 1U;
  184. lpInstructionG++;
  185. lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstructionG;
  186. lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
  187. lpProcessVertices->wStart = 0U;
  188. lpProcessVertices->wDest = 0U;
  189. lpProcessVertices->dwCount = 400*3;
  190. lpProcessVertices->dwReserved = 0UL;
  191. lpProcessVertices++;
  192. lpInstructionG = (LPD3DINSTRUCTION)lpProcessVertices;
  193. lpInstructionG->bOpcode = D3DOP_STATERENDER;
  194. lpInstructionG->bSize = sizeof(D3DSTATE);
  195. if (FOGENABLE) lpInstructionG->wCount = 5;
  196. else lpInstructionG->wCount = 4;
  197. lpInstructionG++;
  198. lpState = (LPD3DSTATE)lpInstructionG;
  199. lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
  200. lpState->dwArg[0] = TRUE;
  201. lpState++;
  202. lpState->drstRenderStateType = D3DRENDERSTATE_ALPHATESTENABLE;
  203. lpState->dwArg[0] = TRUE;
  204. lpState++;
  205. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
  206. lpState->dwArg[0] = D3DFILTER_NEAREST;
  207. lpState++;
  208. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
  209. lpState->dwArg[0] = D3DFILTER_NEAREST;
  210. lpState++;
  211. if (FOGENABLE) {
  212. lpState->drstRenderStateType = D3DRENDERSTATE_FOGCOLOR;
  213. lpState->dwArg[0] = CurFogColor;
  214. /*if (UNDERWATER) lpState->dwArg[0] = 0x00004560;
  215. else lpState->dwArg[0] = 0x00606065;*/
  216. lpState++;
  217. }
  218. lpInstructionG = (LPD3DINSTRUCTION)lpState;
  219. LINEARFILTER = FALSE;
  220. }
  221. void d3dEndBufferG(BOOL ColorKey)
  222. {
  223. if (!lpVertexG) return;
  224. if (ColorKey) {
  225. lpInstructionG->bOpcode = D3DOP_STATERENDER;
  226. lpInstructionG->bSize = sizeof(D3DSTATE);
  227. lpInstructionG->wCount = 4;
  228. lpInstructionG++;
  229. lpState = (LPD3DSTATE)lpInstructionG;
  230. lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
  231. lpState->dwArg[0] = FALSE;
  232. lpState++;
  233. lpState->drstRenderStateType = D3DRENDERSTATE_ALPHATESTENABLE;
  234. lpState->dwArg[0] = FALSE;
  235. lpState++;
  236. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
  237. lpState->dwArg[0] = D3DFILTER_LINEAR;
  238. lpState++;
  239. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
  240. lpState->dwArg[0] = D3DFILTER_LINEAR;
  241. lpState++;
  242. lpInstructionG = (LPD3DINSTRUCTION)lpState;
  243. }
  244. lpInstructionG->bOpcode = D3DOP_EXIT;
  245. lpInstructionG->bSize = 0UL;
  246. lpInstructionG->wCount = 0U;
  247. lpInstructionG = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDescG.lpData + 400*3);
  248. lpInstructionG->bOpcode = D3DOP_PROCESSVERTICES;
  249. lpInstructionG->bSize = sizeof(D3DPROCESSVERTICES);
  250. lpInstructionG->wCount = 1U;
  251. lpInstructionG++;
  252. lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstructionG;
  253. lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
  254. lpProcessVertices->wStart = 0U;
  255. lpProcessVertices->wDest = 0U;
  256. lpProcessVertices->dwCount = GVCnt;
  257. lpProcessVertices->dwReserved = 0UL;
  258. lpProcessVertices++;
  259. lpd3dExecuteBufferG->Unlock( );
  260. dFacesCount+=GVCnt/3;
  261. lpInstructionG = NULL;
  262. lpVertexG = NULL;
  263. GVCnt = 0;
  264. hRes = lpd3dDevice->Execute(lpd3dExecuteBufferG, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
  265. LINEARFILTER = TRUE;
  266. }
  267. void d3dFlushBuffer(int fproc1, int fproc2)
  268. {
  269. BOOL ColorKey = (fproc2>0);
  270. lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + 1024*3);
  271. lpInstruction->bOpcode = D3DOP_STATERENDER;
  272. lpInstruction->bSize = sizeof(D3DSTATE);
  273. lpInstruction->wCount = 3;
  274. lpInstruction++;
  275. lpState = (LPD3DSTATE)lpInstruction;
  276. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
  277. lpState->dwArg[0] = hTexture;
  278. lpState++;
  279. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
  280. lpState->dwArg[0] = D3DFILTER_LINEAR;
  281. lpState++;
  282. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
  283. lpState->dwArg[0] = D3DFILTER_LINEAR;
  284. lpState++;
  285. lpInstruction = (LPD3DINSTRUCTION)lpState;
  286. lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
  287. lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
  288. lpInstruction->wCount = 1U;
  289. lpInstruction++;
  290. lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
  291. lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
  292. lpProcessVertices->wStart = 0U;
  293. lpProcessVertices->wDest = 0U;
  294. lpProcessVertices->dwCount = (fproc1+fproc2)*3;
  295. lpProcessVertices->dwReserved = 0UL;
  296. lpProcessVertices++;
  297. lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
  298. lpInstruction->bOpcode = D3DOP_TRIANGLE;
  299. lpInstruction->bSize = sizeof(D3DTRIANGLE);
  300. lpInstruction->wCount = fproc1;
  301. lpInstruction++;
  302. lpTriangle = (LPD3DTRIANGLE)lpInstruction;
  303. int ii = 0;
  304. for (int i=0; i<fproc1; i++) {
  305. lpTriangle->wV1 = ii++;
  306. lpTriangle->wV2 = ii++;
  307. lpTriangle->wV3 = ii++;
  308. lpTriangle->wFlags = 0;
  309. lpTriangle++;
  310. }
  311. lpInstruction = (LPD3DINSTRUCTION)lpTriangle;
  312. if (ColorKey) {
  313. lpInstruction->bOpcode = D3DOP_STATERENDER;
  314. lpInstruction->bSize = sizeof(D3DSTATE);
  315. lpInstruction->wCount = 4;
  316. lpInstruction++;
  317. lpState = (LPD3DSTATE)lpInstruction;
  318. lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
  319. lpState->dwArg[0] = TRUE;
  320. lpState++;
  321. lpState->drstRenderStateType = D3DRENDERSTATE_ALPHATESTENABLE;
  322. lpState->dwArg[0] = TRUE;
  323. lpState++;
  324. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
  325. lpState->dwArg[0] = D3DFILTER_NEAREST;
  326. lpState++;
  327. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
  328. lpState->dwArg[0] = D3DFILTER_NEAREST;
  329. lpState++;
  330. lpInstruction = (LPD3DINSTRUCTION)lpState;
  331. lpInstruction->bOpcode = D3DOP_TRIANGLE;
  332. lpInstruction->bSize = sizeof(D3DTRIANGLE);
  333. lpInstruction->wCount = fproc2;
  334. lpInstruction++;
  335. lpTriangle = (LPD3DTRIANGLE)lpInstruction;
  336. for (i=0; i<fproc2; i++) {
  337. lpTriangle->wV1 = ii++;
  338. lpTriangle->wV2 = ii++;
  339. lpTriangle->wV3 = ii++;
  340. lpTriangle->wFlags = 0;
  341. lpTriangle++;
  342. }
  343. lpInstruction = (LPD3DINSTRUCTION)lpTriangle;
  344. lpInstruction->bOpcode = D3DOP_STATERENDER;
  345. lpInstruction->bSize = sizeof(D3DSTATE);
  346. lpInstruction->wCount = 4;
  347. lpInstruction++;
  348. lpState = (LPD3DSTATE)lpInstruction;
  349. lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
  350. lpState->dwArg[0] = FALSE;
  351. lpState++;
  352. lpState->drstRenderStateType = D3DRENDERSTATE_ALPHATESTENABLE;
  353. lpState->dwArg[0] = FALSE;
  354. lpState++;
  355. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
  356. lpState->dwArg[0] = D3DFILTER_LINEAR;
  357. lpState++;
  358. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
  359. lpState->dwArg[0] = D3DFILTER_LINEAR;
  360. lpState++;
  361. lpInstruction = (LPD3DINSTRUCTION)lpState;
  362. }
  363. lpInstruction->bOpcode = D3DOP_EXIT;
  364. lpInstruction->bSize = 0UL;
  365. lpInstruction->wCount = 0U;
  366. lpd3dExecuteBuffer->Unlock( );
  367. LINEARFILTER = TRUE;
  368. hRes = lpd3dDevice->Execute(lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
  369. //if (FAILED(hRes)) DoHalt("Error execute buffer");
  370. dFacesCount+=fproc1+fproc2;
  371. }
  372. DWORD BitDepthToFlags( DWORD dwBitDepth )
  373. {
  374. switch( dwBitDepth ) {
  375. case 1UL: return DDBD_1;
  376. case 2UL: return DDBD_2;
  377. case 4UL: return DDBD_4;
  378. case 8UL: return DDBD_8;
  379. case 16UL: return DDBD_16;
  380. case 24UL: return DDBD_24;
  381. case 32UL: return DDBD_32;
  382. default : return 0UL;
  383. }
  384. }
  385. DWORD FlagsToBitDepth( DWORD dwFlags )
  386. {
  387. if (dwFlags & DDBD_1) return 1UL;
  388. else if (dwFlags & DDBD_2) return 2UL;
  389. else if (dwFlags & DDBD_4) return 4UL;
  390. else if (dwFlags & DDBD_8) return 8UL;
  391. else if (dwFlags & DDBD_16) return 16UL;
  392. else if (dwFlags & DDBD_24) return 24UL;
  393. else if (dwFlags & DDBD_32) return 32UL;
  394. else return 0UL;
  395. }
  396. HRESULT FillExecuteBuffer_State( LPDIRECT3DEXECUTEBUFFER lpd3dExecuteBuffer)
  397. {
  398. HRESULT hRes;
  399. D3DEXECUTEBUFFERDESC d3dExeBufDesc;
  400. LPD3DINSTRUCTION lpInstruction;
  401. LPD3DSTATE lpState;
  402. ZeroMemory(&d3dExeBufDesc, sizeof(d3dExeBufDesc));
  403. d3dExeBufDesc.dwSize = sizeof(d3dExeBufDesc);
  404. hRes = lpd3dExecuteBuffer->Lock( &d3dExeBufDesc );
  405. if (FAILED(hRes)) {
  406. PrintLog( "Error locking execute buffer");
  407. return hRes;
  408. }
  409. lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + 1024*3);
  410. lpInstruction->bOpcode = D3DOP_STATERENDER;
  411. lpInstruction->bSize = sizeof(D3DSTATE);
  412. lpInstruction->wCount = 24;
  413. lpInstruction++;
  414. lpState = (LPD3DSTATE)lpInstruction;
  415. lpState->drstRenderStateType = D3DRENDERSTATE_ZENABLE;
  416. lpState->dwArg[0] = TRUE;
  417. lpState++;
  418. lpState->drstRenderStateType = D3DRENDERSTATE_ZWRITEENABLE;
  419. lpState->dwArg[0] = TRUE;
  420. lpState++;
  421. lpState->drstRenderStateType = D3DRENDERSTATE_ZFUNC;
  422. lpState->dwArg[0] = D3DCMP_GREATEREQUAL;
  423. lpState++;
  424. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREPERSPECTIVE;
  425. lpState->dwArg[0] = TRUE;
  426. lpState++;
  427. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAPBLEND;
  428. if (OPT_ALPHA_COLORKEY) lpState->dwArg[0] = D3DTBLEND_MODULATEALPHA;
  429. else lpState->dwArg[0] = D3DTBLEND_MODULATE;
  430. lpState++;
  431. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
  432. lpState->dwArg[0] = D3DFILTER_LINEAR;
  433. lpState++;
  434. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
  435. lpState->dwArg[0] = D3DFILTER_LINEAR;
  436. lpState++;
  437. lpState->drstRenderStateType = D3DRENDERSTATE_SHADEMODE;
  438. lpState->dwArg[0] = D3DSHADE_GOURAUD;
  439. lpState++;
  440. lpState->drstRenderStateType = D3DRENDERSTATE_DITHERENABLE;
  441. lpState->dwArg[0] = TRUE;
  442. lpState++;
  443. lpState->drstRenderStateType = D3DRENDERSTATE_CULLMODE;
  444. lpState->dwArg[0] = D3DCULL_NONE;
  445. lpState++;
  446. lpState->drstRenderStateType = D3DRENDERSTATE_BLENDENABLE;
  447. lpState->dwArg[0] = TRUE;
  448. lpState++;
  449. lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
  450. lpState->dwArg[0] = FALSE;
  451. lpState++;
  452. lpState->drstRenderStateType = D3DRENDERSTATE_ALPHABLENDENABLE;
  453. lpState->dwArg[0] = TRUE;
  454. lpState++;
  455. lpState->drstRenderStateType = D3DRENDERSTATE_ALPHATESTENABLE;
  456. lpState->dwArg[0] = FALSE;
  457. lpState++;
  458. lpState->drstRenderStateType = D3DRENDERSTATE_ALPHAREF;
  459. lpState->dwArg[0] = 0;
  460. lpState++;
  461. lpState->drstRenderStateType = D3DRENDERSTATE_ALPHAFUNC;
  462. lpState->dwArg[0] = D3DCMP_GREATEREQUAL;
  463. lpState++;
  464. lpState->drstRenderStateType = D3DRENDERSTATE_SPECULARENABLE;
  465. lpState->dwArg[0] = FALSE;
  466. lpState++;
  467. lpState->drstRenderStateType = D3DRENDERSTATE_FOGENABLE;
  468. lpState->dwArg[0] = FOGENABLE;
  469. lpState++;
  470. lpState->drstRenderStateType = D3DRENDERSTATE_FOGCOLOR;
  471. lpState->dwArg[0] = 0x00606070;
  472. lpState++;
  473. lpState->drstRenderStateType = D3DRENDERSTATE_SRCBLEND;
  474. lpState->dwArg[0] = D3DBLEND_SRCALPHA;
  475. lpState++;
  476. lpState->drstRenderStateType = D3DRENDERSTATE_DESTBLEND;
  477. lpState->dwArg[0] = D3DBLEND_INVSRCALPHA;
  478. lpState++;
  479. lpState->drstRenderStateType = D3DRENDERSTATE_STIPPLEDALPHA;
  480. lpState->dwArg[0] = FALSE;
  481. lpState++;
  482. lpState->drstRenderStateType = D3DRENDERSTATE_WRAPU;
  483. lpState->dwArg[0] = FALSE;
  484. lpState++;
  485. lpState->drstRenderStateType = D3DRENDERSTATE_WRAPV;
  486. lpState->dwArg[0] = FALSE;
  487. lpState++;
  488. lpInstruction = (LPD3DINSTRUCTION)lpState;
  489. lpInstruction->bOpcode = D3DOP_EXIT;
  490. lpInstruction->bSize = 0UL;
  491. lpInstruction->wCount = 0U;
  492. lpd3dExecuteBuffer->Unlock( );
  493. //PrintLog( "Execute buffer filled successfully\n" );
  494. return DD_OK;
  495. }
  496. void SetRenderStates(BOOL ZWRITE, int DST_BLEND)
  497. {
  498. HRESULT hRes;
  499. D3DEXECUTEBUFFERDESC d3dExeBufDesc;
  500. LPD3DINSTRUCTION lpInstruction;
  501. LPD3DSTATE lpState;
  502. ZeroMemory(&d3dExeBufDesc, sizeof(d3dExeBufDesc));
  503. d3dExeBufDesc.dwSize = sizeof(d3dExeBufDesc);
  504. hRes = lpd3dExecuteBuffer->Lock( &d3dExeBufDesc );
  505. if (FAILED(hRes)) {
  506. PrintLog( "Error locking execute buffer");
  507. return;
  508. }
  509. lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + 1024*3);
  510. lpInstruction->bOpcode = D3DOP_STATERENDER;
  511. lpInstruction->bSize = sizeof(D3DSTATE);
  512. lpInstruction->wCount = 2;
  513. lpInstruction++;
  514. lpState = (LPD3DSTATE)lpInstruction;
  515. lpState->drstRenderStateType = D3DRENDERSTATE_ZWRITEENABLE;
  516. lpState->dwArg[0] = ZWRITE;
  517. lpState++;
  518. lpState->drstRenderStateType = D3DRENDERSTATE_DESTBLEND;
  519. lpState->dwArg[0] = DST_BLEND;
  520. lpState++;
  521. lpInstruction = (LPD3DINSTRUCTION)lpState;
  522. lpInstruction->bOpcode = D3DOP_EXIT;
  523. lpInstruction->bSize = 0UL;
  524. lpInstruction->wCount = 0U;
  525. lpd3dExecuteBuffer->Unlock( );
  526. lpd3dDevice->Execute( lpd3dExecuteBuffer,
  527. lpd3dViewport,
  528. D3DEXECUTE_UNCLIPPED );
  529. }
  530. HRESULT WINAPI EnumDeviceCallback(
  531. LPGUID lpGUID,
  532. LPSTR lpszDeviceDesc,
  533. LPSTR lpszDeviceName,
  534. LPD3DDEVICEDESC lpd3dHWDeviceDesc,
  535. LPD3DDEVICEDESC lpd3dSWDeviceDesc,
  536. LPVOID lpUserArg )
  537. {
  538. LPD3DDEVICEDESC lpd3dDeviceDesc;
  539. wsprintf(logt,"ENUMERATE: DDesc: %s DName: %s\n", lpszDeviceDesc, lpszDeviceName);
  540. //PrintLog(logt);
  541. if( !lpd3dHWDeviceDesc->dcmColorModel )
  542. return D3DENUMRET_OK; // we don't need SW rasterizer
  543. lpd3dDeviceDesc = lpd3dHWDeviceDesc;
  544. if( (lpd3dDeviceDesc->dwDeviceRenderBitDepth & dwDeviceBitDepth) == 0UL )
  545. return D3DENUMRET_OK;
  546. if( !(lpd3dDeviceDesc->dpcTriCaps.dwShadeCaps & D3DPSHADECAPS_COLORGOURAUDRGB) )
  547. return D3DENUMRET_OK;
  548. fDeviceFound = TRUE;
  549. CopyMemory( &guidDevice, lpGUID, sizeof(GUID) );
  550. strcpy( szDeviceDesc, lpszDeviceDesc );
  551. strcpy( szDeviceName, lpszDeviceName );
  552. CopyMemory( &d3dHWDeviceDesc, lpd3dHWDeviceDesc, sizeof(D3DDEVICEDESC) );
  553. return D3DENUMRET_CANCEL;
  554. }
  555. HRESULT CreateDirect3D( HWND hwnd )
  556. {
  557. HRESULT hRes;
  558. PrintLog("\n");
  559. PrintLog("=== Init Direct3D ===\n" );
  560. hRes = lpDD->SetCooperativeLevel( hwnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN );
  561. if (FAILED(hRes)) DoHalt("Error setting cooperative level\n");
  562. hRes = lpDD->SetDisplayMode( WinW, WinH, 16 );
  563. if (FAILED(hRes)) {
  564. PrintLog("DDraw: can't set selected video mode\n");
  565. WinW = 640;
  566. WinH = 480;
  567. OptRes = 3;
  568. hRes = lpDD->SetDisplayMode( WinW, WinH, 16 );
  569. }
  570. if (FAILED(hRes)) DoHalt("Error setting display mode\n");
  571. wsprintf(logt, "Set Display mode %dx%d, 16bpp\n", WinW, WinH);
  572. PrintLog(logt);
  573. hRes = lpDD->QueryInterface( IID_IDirect3D, (LPVOID*) &lpd3d);
  574. if (FAILED(hRes)) DoHalt("Error quering Direct3D interface\n");
  575. PrintLog("QueryInterface: Ok. (IID_IDirect3D)\n");
  576. DDSURFACEDESC ddsd;
  577. ZeroMemory(&ddsd, sizeof(ddsd));
  578. ddsd.dwSize = sizeof(ddsd);
  579. ddsd.dwFlags = DDSD_CAPS;
  580. ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
  581. hRes = lpDD->CreateSurface( &ddsd, &lpddPrimary, NULL );
  582. if (FAILED(hRes)) DoHalt( "Error creating primary surface\n");
  583. ZeroMemory(&ddsd, sizeof(ddsd) );
  584. ddsd.dwSize = sizeof(ddsd);
  585. hRes = lpddPrimary->GetSurfaceDesc( &ddsd);
  586. if (FAILED(hRes)) DoHalt("Error getting surface description\n");
  587. PrintLog("CreateSurface: Ok. (Primary)\n");
  588. dwDeviceBitDepth = BitDepthToFlags(ddsd.ddpfPixelFormat.dwRGBBitCount);
  589. fDeviceFound = FALSE;
  590. hRes = lpd3d->EnumDevices( EnumDeviceCallback, &fDeviceFound);
  591. if (FAILED(hRes) ) DoHalt("EnumDevices failed.\n");
  592. if (!fDeviceFound ) DoHalt("No devices found.\n");
  593. PrintLog("EnumDevices: Ok.\n");
  594. return DD_OK;
  595. }
  596. HRESULT CreateDevice(DWORD dwWidth, DWORD dwHeight)
  597. {
  598. DDSURFACEDESC ddsd;
  599. HRESULT hRes;
  600. DWORD dwZBufferBitDepth;
  601. ZeroMemory(&ddsd, sizeof(ddsd));
  602. ddsd.dwSize = sizeof(ddsd);
  603. ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
  604. ddsd.dwWidth = dwWidth;
  605. ddsd.dwHeight = dwHeight;
  606. ddsd.ddsCaps.dwCaps = DDSCAPS_3DDEVICE | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
  607. hRes = lpDD->CreateSurface( &ddsd, &lpddBack, NULL);
  608. if (FAILED(hRes)) DoHalt("Error creating back buffer surface\n");
  609. PrintLog("CreateSurface: Ok. (BackBuffer)\n");
  610. if( d3dHWDeviceDesc.dwDeviceZBufferBitDepth != 0UL ) {
  611. dwZBufferBitDepth = FlagsToBitDepth( d3dHWDeviceDesc.dwDeviceZBufferBitDepth );
  612. ZeroMemory(&ddsd, sizeof(ddsd));
  613. ddsd.dwSize = sizeof(ddsd);
  614. ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_ZBUFFERBITDEPTH;
  615. ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY;
  616. ddsd.dwWidth = dwWidth;
  617. ddsd.dwHeight = dwHeight;
  618. ddsd.dwZBufferBitDepth = 16;//dwZBufferBitDepth;
  619. hRes = lpDD->CreateSurface( &ddsd, &lpddZBuffer, NULL);
  620. /*
  621. if (FAILED(hRes)) {
  622. ddsd.dwZBufferBitDepth = 16;//dwZBufferBitDepth;
  623. hRes = lpDD->CreateSurface( &ddsd, &lpddZBuffer, NULL);
  624. PrintLog("Z-Buffer: 16 bit\n");
  625. } else
  626. PrintLog("Z-Buffer: 32 bit\n");
  627. */
  628. if (FAILED(hRes)) DoHalt("Error creating z-buffer\n");
  629. hRes = lpddBack->AddAttachedSurface( lpddZBuffer );
  630. if (FAILED(hRes)) DoHalt("Error attaching z-buffer\n");
  631. PrintLog("CreateSurface: Ok. (Z-buffer)\n");
  632. }
  633. hRes = lpddBack->QueryInterface( guidDevice, (LPVOID*) &lpd3dDevice);
  634. if (FAILED(hRes)) DoHalt("Error quering device interface\n");
  635. PrintLog("QueryInterface: Ok. (lpd3dDevice)\n");
  636. return DD_OK;
  637. }
  638. HRESULT CreateScene(void)
  639. {
  640. HRESULT hRes;
  641. DWORD dwVertexSize;
  642. DWORD dwInstructionSize;
  643. DWORD dwExecuteBufferSize;
  644. D3DEXECUTEBUFFERDESC d3dExecuteBufferDesc;
  645. D3DEXECUTEDATA d3dExecuteData;
  646. hRes = lpd3d->CreateViewport( &lpd3dViewport, NULL );
  647. if (FAILED(hRes)) DoHalt("Error creating viewport\n");
  648. PrintLog("CreateViewport: Ok.\n");
  649. hRes = lpd3dDevice->AddViewport( lpd3dViewport );
  650. if (FAILED(hRes)) DoHalt("Error adding viewport\n");
  651. //PrintLog("AddViewport: Ok.\n");
  652. D3DVIEWPORT d3dViewport;
  653. ZeroMemory(&d3dViewport, sizeof(d3dViewport));
  654. d3dViewport.dwSize = sizeof(d3dViewport);
  655. d3dViewport.dwX = 0UL;
  656. d3dViewport.dwY = 0UL;
  657. d3dViewport.dwWidth = (DWORD)WinW;
  658. d3dViewport.dwHeight = (DWORD)WinH;
  659. d3dViewport.dvScaleX = D3DVAL((float)d3dViewport.dwWidth / 2.0);
  660. d3dViewport.dvScaleY = D3DVAL((float)d3dViewport.dwHeight / 2.0);
  661. d3dViewport.dvMaxX = D3DVAL(1.0);
  662. d3dViewport.dvMaxY = D3DVAL(1.0);
  663. lpd3dViewport->SetViewport( &d3dViewport);
  664. //=========== CREATING EXECUTE BUFFER ======================//
  665. dwVertexSize = ((1024*3) * sizeof(D3DVERTEX));
  666. dwInstructionSize = (NUM_INSTRUCTIONS * sizeof(D3DINSTRUCTION)) +
  667. (NUM_STATES * sizeof(D3DSTATE)) +
  668. (NUM_PROCESSVERTICES * sizeof(D3DPROCESSVERTICES)) +
  669. ((1024) * sizeof(D3DTRIANGLE));
  670. dwExecuteBufferSize = dwVertexSize + dwInstructionSize;
  671. ZeroMemory(&d3dExecuteBufferDesc, sizeof(d3dExecuteBufferDesc));
  672. d3dExecuteBufferDesc.dwSize = sizeof(d3dExecuteBufferDesc);
  673. d3dExecuteBufferDesc.dwFlags = D3DDEB_BUFSIZE;
  674. d3dExecuteBufferDesc.dwBufferSize = dwExecuteBufferSize;
  675. hRes = lpd3dDevice->CreateExecuteBuffer( &d3dExecuteBufferDesc, &lpd3dExecuteBuffer, NULL);
  676. if (FAILED(hRes)) DoHalt( "Error creating execute buffer\n");
  677. PrintLog("CreateExecuteBuffer: Ok.\n");
  678. ZeroMemory(&d3dExecuteData, sizeof(d3dExecuteData));
  679. d3dExecuteData.dwSize = sizeof(d3dExecuteData);
  680. d3dExecuteData.dwVertexCount = 1024;
  681. d3dExecuteData.dwInstructionOffset = dwVertexSize;
  682. d3dExecuteData.dwInstructionLength = dwInstructionSize;
  683. hRes = lpd3dExecuteBuffer->SetExecuteData( &d3dExecuteData );
  684. if (FAILED(hRes)) DoHalt("Error setting execute data\n");
  685. //=========== CREATING EXECUTE BUFFER ======================//
  686. dwVertexSize = ((400*3) * sizeof(D3DVERTEX));
  687. dwInstructionSize = (300 * sizeof(D3DINSTRUCTION)) +
  688. (300 * sizeof(D3DSTATE)) +
  689. (10 * sizeof(D3DPROCESSVERTICES)) +
  690. ((400) * sizeof(D3DTRIANGLE));
  691. dwExecuteBufferSize = dwVertexSize + dwInstructionSize;
  692. ZeroMemory(&d3dExecuteBufferDesc, sizeof(d3dExecuteBufferDesc));
  693. d3dExecuteBufferDesc.dwSize = sizeof(d3dExecuteBufferDesc);
  694. d3dExecuteBufferDesc.dwFlags = D3DDEB_BUFSIZE;
  695. d3dExecuteBufferDesc.dwBufferSize = dwExecuteBufferSize;
  696. hRes = lpd3dDevice->CreateExecuteBuffer( &d3dExecuteBufferDesc, &lpd3dExecuteBufferG, NULL);
  697. if (FAILED(hRes)) DoHalt( "Error creating execute buffer\n");
  698. PrintLog("CreateExecuteBuffer: Ok.\n");
  699. ZeroMemory(&d3dExecuteData, sizeof(d3dExecuteData));
  700. d3dExecuteData.dwSize = sizeof(d3dExecuteData);
  701. d3dExecuteData.dwVertexCount = 400;
  702. d3dExecuteData.dwInstructionOffset = dwVertexSize;
  703. d3dExecuteData.dwInstructionLength = dwInstructionSize;
  704. hRes = lpd3dExecuteBufferG->SetExecuteData( &d3dExecuteData );
  705. if (FAILED(hRes)) DoHalt("Error setting execute data\n");
  706. FillExecuteBuffer_State(lpd3dExecuteBuffer);
  707. hRes = lpd3dDevice->Execute( lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
  708. return DD_OK;
  709. }
  710. void Init3DHardware()
  711. {
  712. HARD3D = TRUE;
  713. PrintLog("\n");
  714. PrintLog("==Init Direct Draw==\n");
  715. HRESULT hres;
  716. hres = DirectDrawCreate( NULL, &lpDD, NULL );
  717. if( hres != DD_OK ) {
  718. wsprintf(logt, "DirectDrawCreate Error: %Xh\n", hres);
  719. DoHalt(logt); }
  720. PrintLog("DirectDrawCreate: Ok\n");
  721. DirectActive = TRUE;
  722. }
  723. void d3dDetectCaps()
  724. {
  725. for (int t=0; t<d3dmemmapsize; t++) {
  726. if (!d3dAllocTexture(t, 256, 256)) break;
  727. }
  728. d3dTexturesMem = t*256*256*2;
  729. d3dDownLoadTexture(0, 256, 256, SkyPic);
  730. DWORD T;
  731. T = timeGetTime();
  732. for (t=0; t<10; t++) d3dDownLoadTexture(0, 256, 256, SkyPic);
  733. T = timeGetTime() - T;
  734. wsprintf(logt, "DETECTED: Texture memory : %dK.\n", d3dTexturesMem>>10);
  735. PrintLog(logt);
  736. ResetTextureMap();
  737. wsprintf(logt, "DETECTED: Texture transfer speed: %dK/sec.\n", 128*10000 / T);
  738. PrintLog(logt);
  739. DDSURFACEDESC ddsd;
  740. ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
  741. ddsd.dwSize = sizeof(DDSURFACEDESC);
  742. if( lpddBack->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
  743. lpddBack->Unlock(ddsd.lpSurface);
  744. if (ddsd.ddpfPixelFormat.dwGBitMask == 0x3E0) VMFORMAT565=FALSE; else VMFORMAT565=TRUE;
  745. if (VMFORMAT565)
  746. PrintLog("DETECTED: PixelFormat RGB565\n");
  747. else {
  748. PrintLog("DETECTED: PixelFormat RGB555\n");
  749. if (!STARTCONV555) {
  750. STARTCONV555 = TRUE;
  751. conv_pic555(PausePic);
  752. conv_pic555(ExitPic);
  753. conv_pic555(TrophyExit);
  754. conv_pic555(MapPic);
  755. conv_pic555(TrophyPic);
  756. for (int c=0; c<20; c++)
  757. if (DinoInfo[c].CallIcon.W)
  758. conv_pic555(DinoInfo[c].CallIcon);
  759. for (int w=0; w<TotalW; w++)
  760. if (Weapon.BulletPic[w].W)
  761. conv_pic555(Weapon.BulletPic[w]);
  762. }
  763. }
  764. }
  765. void d3dTestDrawTri(float color, float tx)
  766. {
  767. d3dStartBuffer();
  768. lpVertex->sx = 0;
  769. lpVertex->sy = 0;
  770. lpVertex->sz = _ZSCALE / 10;
  771. lpVertex->rhw = 1.f;
  772. lpVertex->color = color;
  773. lpVertex->specular = 0xFF000000;
  774. lpVertex->tu = tx;
  775. lpVertex->tv = tx;
  776. lpVertex++;
  777. lpVertex->sx = 100;
  778. lpVertex->sy = 0;
  779. lpVertex->sz = _ZSCALE / 10;
  780. lpVertex->rhw = 1.f;
  781. lpVertex->color = color;
  782. lpVertex->specular = 0xFF000000;
  783. lpVertex->tu = tx;
  784. lpVertex->tv = tx;
  785. lpVertex++;
  786. lpVertex->sx = 0;
  787. lpVertex->sy = 100;
  788. lpVertex->sz = _ZSCALE / 10;
  789. lpVertex->rhw = 1.f;
  790. lpVertex->color = color;
  791. lpVertex->specular = 0xFF000000;
  792. lpVertex->tu = tx;
  793. lpVertex->tv = tx;
  794. lpVertex++;
  795. d3dFlushBuffer(0, 1);
  796. }
  797. int d3dTestAlpha()
  798. {
  799. int RF = 0;
  800. lpd3dDevice->BeginScene( );
  801. // RenderSkyPlane();
  802. d3dSetTexture(TFX_SPECULAR.lpImage, TFX_SPECULAR.W, TFX_SPECULAR.W);
  803. DDBLTFX ddbltfx;
  804. ddbltfx.dwSize = sizeof( DDBLTFX );
  805. ddbltfx.dwFillColor = 0xFFFF;
  806. lpddBack->Blt( NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx );
  807. FillExecuteBuffer_State(lpd3dExecuteBuffer);
  808. hRes = lpd3dDevice->Execute( lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
  809. //========= test opacity ==========//
  810. //d3dSetTexture(TFX_SPECULAR.lpImage, TFX_SPECULAR.W, TFX_SPECULAR.W);
  811. SetRenderStates(FALSE, D3DBLEND_INVSRCALPHA);
  812. d3dTestDrawTri(0xFFFFFFFF, 0.0);
  813. CopyBackToDIB();
  814. if (*((WORD*)lpVideoBuf)==0) PrintLog("[OPACITY: Failed] ");
  815. else { PrintLog("[OPACITY: Ok.] "); RF+=4; }
  816. lpd3dDevice->EndScene( );
  817. lpd3dDevice->BeginScene( );
  818. /*
  819. ShowVideo();
  820. lpd3dDevice->BeginScene( );
  821. Sleep(1000);
  822. */
  823. //=========== test transparent mode =============//
  824. lpd3dDevice->BeginScene( );
  825. ddbltfx.dwSize = sizeof( DDBLTFX );
  826. ddbltfx.dwFillColor = 0x0000;
  827. lpddBack->Blt( NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx );
  828. d3dTestDrawTri(0x00FFFFFF, 0.5);
  829. CopyBackToDIB();
  830. if (*((WORD*)lpVideoBuf)!=0) PrintLog("[TRANSPARENT: Failed] ");
  831. else { PrintLog("[TRANSPARENT: Ok.] "); RF+=2; }
  832. lpd3dDevice->EndScene( );
  833. lpd3dDevice->BeginScene( );
  834. /*
  835. ShowVideo();
  836. lpd3dDevice->BeginScene( );
  837. Sleep(1000);
  838. */
  839. //=========== test env map ==================//
  840. SetRenderStates(FALSE, D3DBLEND_ONE);
  841. lpd3dDevice->BeginScene( );
  842. ddbltfx.dwSize = sizeof( DDBLTFX );
  843. ddbltfx.dwFillColor = 0x0000;
  844. lpddBack->Blt( NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx );
  845. d3dTestDrawTri(0x00FFFFFF, 0.5);
  846. CopyBackToDIB();
  847. if (*((WORD*)lpVideoBuf)!=0) PrintLog("[ENV.BLEND : Failed]\n");
  848. else { PrintLog("[ENV.BLEND : Ok.]\n"); RF+=1; }
  849. lpd3dDevice->EndScene( );
  850. lpd3dDevice->BeginScene( );
  851. /*
  852. ShowVideo();
  853. lpd3dDevice->BeginScene( );
  854. Sleep(1000);
  855. */
  856. SetRenderStates(TRUE, D3DBLEND_INVSRCALPHA);
  857. lpd3dDevice->EndScene( );
  858. return RF;
  859. }
  860. void Activate3DHardware()
  861. {
  862. SetVideoMode(WinW,WinH);
  863. HRESULT hRes = CreateDirect3D(hwndMain);
  864. if (FAILED(hRes)) DoHalt("CreateDirect3D Failed.\n");
  865. hRes = CreateDevice((DWORD)WinW, (DWORD)WinH);
  866. if (FAILED(hRes)) DoHalt("Create Device Failed.\n");
  867. d3dClearBuffers();
  868. hRes = CreateScene();
  869. if (FAILED(hRes)) DoHalt("CreateScene Failed.\n");
  870. d3dDetectCaps();
  871. OPT_ALPHA_COLORKEY=FALSE;
  872. PrintLog("TEST COLOR KEY: ");
  873. int r1 = d3dTestAlpha();
  874. OPT_ALPHA_COLORKEY=TRUE;
  875. PrintLog("TEST ALPHA KEY: ");
  876. int r2 = d3dTestAlpha();
  877. OPT_ALPHA_COLORKEY = (r2>=r1);
  878. if (OPT_ALPHA_COLORKEY) PrintLog("ALPHA KEY mode selected.\n");
  879. else PrintLog("COLOR KEY mode selected.\n");
  880. hRes = lpd3dDevice->BeginScene( );
  881. if (OptText==0) LOWRESTX = TRUE;
  882. if (OptText==1) LOWRESTX = FALSE;
  883. if (OptText==2) LOWRESTX = FALSE;
  884. d3dMemLoaded = 0;
  885. D3DACTIVE = TRUE;
  886. d3dLastTexture = d3dmemmapsize+1;
  887. PrintLog("=== Direct3D started === \n");
  888. PrintLog("\n");
  889. }
  890. void ResetTextureMap()
  891. {
  892. d3dEndBufferG(FALSE);
  893. d3dMemUsageCount = 0;
  894. //d3dMemLoaded = 0;
  895. d3dLastTexture = d3dmemmapsize+1;
  896. for (int m=0; m<d3dmemmapsize+2; m++) {
  897. d3dMemMap[m].lastused = 0;
  898. d3dMemMap[m].cpuaddr = 0;
  899. if (d3dMemMap[m].lpddTexture) {
  900. d3dMemMap[m].lpddTexture->Release();
  901. d3dMemMap[m].lpddTexture = NULL;
  902. }
  903. }
  904. }
  905. void ShutDown3DHardware()
  906. {
  907. D3DACTIVE = FALSE;
  908. if (lpd3dDevice)
  909. hRes = lpd3dDevice->EndScene();
  910. ResetTextureMap();
  911. lpInstructionG = NULL;
  912. lpVertexG = NULL;
  913. if (NULL != lpd3dExecuteBuffer) {
  914. lpd3dExecuteBuffer->Release( );
  915. lpd3dExecuteBufferG->Release( );
  916. lpd3dExecuteBuffer = NULL;
  917. }
  918. if (NULL != lpd3dViewport) {
  919. lpd3dViewport->Release( );
  920. lpd3dViewport = NULL;
  921. }
  922. if (NULL != lpd3dDevice) {
  923. lpd3dDevice->Release( );
  924. lpd3dDevice = NULL;
  925. }
  926. if (NULL != lpddZBuffer) {
  927. lpddZBuffer->Release( );
  928. lpddZBuffer = NULL;
  929. }
  930. if (NULL != lpddBack) {
  931. lpddBack->Release();
  932. lpddBack = NULL;
  933. }
  934. if (NULL != lpddPrimary) {
  935. lpddPrimary->Release( );
  936. lpddPrimary = NULL;
  937. }
  938. if (NULL != lpd3d) {
  939. lpd3d->Release( );
  940. lpd3d = NULL;
  941. }
  942. lpDD->SetCooperativeLevel( hwndMain, DDSCL_NORMAL);
  943. }
  944. void InsertFxMM(int m)
  945. {
  946. for (int mm=d3dmemmapsize-1; mm>m; mm--)
  947. d3dMemMap[m] = d3dMemMap[m-1];
  948. }
  949. BOOL d3dAllocTexture(int i, int w, int h)
  950. {
  951. DDSURFACEDESC ddsd;
  952. DDPIXELFORMAT ddpf;
  953. ZeroMemory( &ddpf, sizeof(DDPIXELFORMAT) );
  954. ddpf.dwSize = sizeof(DDPIXELFORMAT);
  955. ddpf.dwFlags = DDPF_RGB;
  956. if (OPT_ALPHA_COLORKEY) {
  957. ddpf.dwFlags |= DDPF_ALPHAPIXELS;
  958. ddpf.dwRGBAlphaBitMask = 0x8000;
  959. }
  960. ddpf.dwRGBBitCount = 16;
  961. ddpf.dwRBitMask = 0x7c00;
  962. ddpf.dwGBitMask = 0x3e0;
  963. ddpf.dwBBitMask = 0x1f;
  964. ZeroMemory(&ddsd, sizeof(ddsd));
  965. ddsd.dwSize = sizeof(ddsd);
  966. ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
  967. ddsd.dwWidth = w;
  968. ddsd.dwHeight = h;
  969. CopyMemory( &ddsd.ddpfPixelFormat, &ddpf, sizeof(DDPIXELFORMAT) );
  970. ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
  971. hRes = lpDD->CreateSurface( &ddsd, &d3dMemMap[i].lpddTexture, NULL);
  972. if (FAILED(hRes)) {
  973. d3dMemMap[i].lpddTexture = NULL;
  974. return FALSE; }
  975. DDCOLORKEY ddck;
  976. ddck.dwColorSpaceLowValue = ddck.dwColorSpaceHighValue = 0x0000;
  977. d3dMemMap[i].lpddTexture->SetColorKey(DDCKEY_SRCBLT, &ddck);
  978. return TRUE;
  979. }
  980. void d3dDownLoadTexture(int i, int w, int h, LPVOID tptr)
  981. {
  982. DDSURFACEDESC ddsd;
  983. ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
  984. ddsd.dwSize = sizeof(DDSURFACEDESC);
  985. if( d3dMemMap[i].lpddTexture->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
  986. CopyMemory( ddsd.lpSurface, tptr, w*h*2 );
  987. d3dMemMap[i].lpddTexture->Unlock( ddsd.lpSurface );
  988. IDirect3DTexture* Texture;
  989. if( d3dMemMap[i].lpddTexture->QueryInterface( IID_IDirect3DTexture, (LPVOID*)&Texture ) != S_OK ) return;
  990. if( Texture->GetHandle( lpd3dDevice, &d3dMemMap[i].hTexture ) != D3D_OK ) return;
  991. Texture->Release( );
  992. d3dMemMap[i].cpuaddr = (int) tptr;
  993. d3dMemMap[i].size = w*h*2;
  994. d3dMemLoaded+=w*h*2;
  995. //---------------------------------------------------------------------------
  996. }
  997. int DownLoadTexture(LPVOID tptr, int w, int h)
  998. {
  999. int textureSize = w*w*2;
  1000. int fxm = 0;
  1001. int m;
  1002. //========== if no memory used ==========//
  1003. if (!d3dMemMap[0].cpuaddr) {
  1004. d3dAllocTexture(0, w, h);
  1005. d3dDownLoadTexture(0, w, h, tptr);
  1006. return 0;
  1007. }
  1008. //====== search for last used block and try to alloc next ============//
  1009. for (m = 0; m < d3dmemmapsize; m++)
  1010. if (!d3dMemMap[m].cpuaddr)
  1011. if (d3dAllocTexture(m, w, h)) {
  1012. d3dDownLoadTexture(m, w, h, tptr);
  1013. return m;
  1014. } else break;
  1015. //====== search for unused texture and replace it with new ============//
  1016. int unusedtime = 2;
  1017. int rt = -1;
  1018. for (m = 0; m < d3dmemmapsize; m++) {
  1019. if (!d3dMemMap[m].cpuaddr) break;
  1020. if (d3dMemMap[m].size != w*h*2) continue;
  1021. int ut = d3dMemUsageCount - d3dMemMap[m].lastused;
  1022. if (ut >= unusedtime) {
  1023. unusedtime = ut;
  1024. rt = m; }
  1025. }
  1026. if (rt!=-1) {
  1027. d3dDownLoadTexture(rt, w, h, tptr);
  1028. return rt;
  1029. }
  1030. ResetTextureMap();
  1031. d3dAllocTexture(0, w, h);
  1032. d3dDownLoadTexture(0, w, h, tptr);
  1033. return 0;
  1034. }
  1035. void d3dSetTexture(LPVOID tptr, int w, int h)
  1036. {
  1037. if (d3dMemMap[d3dLastTexture].cpuaddr == (int)tptr) return;
  1038. int fxm = -1;
  1039. for (int m=0; m<d3dmemmapsize; m++) {
  1040. if (d3dMemMap[m].cpuaddr == (int)tptr) { fxm = m; break; }
  1041. if (!d3dMemMap[m].cpuaddr) break;
  1042. }
  1043. if (fxm==-1) fxm = DownLoadTexture(tptr, w, h);
  1044. d3dMemMap[fxm].lastused = d3dMemUsageCount;
  1045. hTexture = d3dMemMap[fxm].hTexture;
  1046. d3dLastTexture = fxm;
  1047. }
  1048. float GetTraceK(int x, int y)
  1049. {
  1050. if (x<8 || y<8 || x>WinW-8 || y>WinH-8) return 0.f;
  1051. float k = 0;
  1052. DDSURFACEDESC ddsd;
  1053. ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
  1054. ddsd.dwSize = sizeof(DDSURFACEDESC);
  1055. if( lpddZBuffer->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) {
  1056. return 0;
  1057. }
  1058. WORD CC = 200;
  1059. int bw = (ddsd.lPitch>>1);
  1060. if ( *((WORD*)ddsd.lpSurface + (y+0)*bw + x+0) < CC ) k+=1.f;
  1061. if ( *((WORD*)ddsd.lpSurface + (y+10)*bw + x+0) < CC ) k+=1.f;
  1062. if ( *((WORD*)ddsd.lpSurface + (y-10)*bw + x+0) < CC ) k+=1.f;
  1063. if ( *((WORD*)ddsd.lpSurface + (y+0)*bw + x+10) < CC ) k+=1.f;
  1064. if ( *((WORD*)ddsd.lpSurface + (y+0)*bw + x-10) < CC ) k+=1.f;
  1065. if ( *((WORD*)ddsd.lpSurface + (y+8)*bw + x+8) < CC ) k+=1.f;
  1066. if ( *((WORD*)ddsd.lpSurface + (y+8)*bw + x-8) < CC ) k+=1.f;
  1067. if ( *((WORD*)ddsd.lpSurface + (y-8)*bw + x+8) < CC ) k+=1.f;
  1068. if ( *((WORD*)ddsd.lpSurface + (y-8)*bw + x-8) < CC ) k+=1.f;
  1069. lpddZBuffer->Unlock(ddsd.lpSurface);
  1070. k/=9.f;
  1071. DeltaFunc(TraceK, k, TimeDt / 1024.f);
  1072. return TraceK;
  1073. }
  1074. void AddSkySum(WORD C)
  1075. {
  1076. int R,G,B;
  1077. if (VMFORMAT565) {
  1078. R = C>>11; G = (C>>5) & 63; B = C & 31;
  1079. } else {
  1080. R = C>>10; G = (C>>5) & 31; B = C & 31; C=C*2;
  1081. }
  1082. SkySumR += R*8;
  1083. SkySumG += G*4;
  1084. SkySumB += B*8;
  1085. }
  1086. float GetSkyK(int x, int y)
  1087. {
  1088. if (x<10 || y<10 || x>WinW-10 || y>WinH-10) return 0.5;
  1089. SkySumR = 0;
  1090. SkySumG = 0;
  1091. SkySumB = 0;
  1092. float k = 0;
  1093. DDSURFACEDESC ddsd;
  1094. ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
  1095. ddsd.dwSize = sizeof(DDSURFACEDESC);
  1096. if( lpddBack->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) {
  1097. return 0;
  1098. }
  1099. int bw = (ddsd.lPitch>>1);
  1100. AddSkySum(*((WORD*)ddsd.lpSurface + (y+0)*bw + x+0));
  1101. AddSkySum(*((WORD*)ddsd.lpSurface + (y+6)*bw + x+0));
  1102. AddSkySum(*((WORD*)ddsd.lpSurface + (y-6)*bw + x+0));
  1103. AddSkySum(*((WORD*)ddsd.lpSurface + (y+0)*bw + x+6));
  1104. AddSkySum(*((WORD*)ddsd.lpSurface + (y+0)*bw + x-6));
  1105. AddSkySum(*((WORD*)ddsd.lpSurface + (y+4)*bw + x+4));
  1106. AddSkySum(*((WORD*)ddsd.lpSurface + (y+4)*bw + x-4));
  1107. AddSkySum(*((WORD*)ddsd.lpSurface + (y-4)*bw + x+4));
  1108. AddSkySum(*((WORD*)ddsd.lpSurface + (y-4)*bw + x-4));
  1109. lpddBack->Unlock(ddsd.lpSurface);
  1110. SkySumR-=SkyTR*9;
  1111. SkySumG-=SkyTG*9;
  1112. SkySumB-=SkyTB*9;
  1113. k = (float)sqrt(SkySumR*SkySumR + SkySumG*SkySumG + SkySumB*SkySumB) / 9;
  1114. if (k>80) k = 80;
  1115. if (k< 0) k = 0;
  1116. k = 1.0f - k/80.f;
  1117. if (k<0.2) k=0.2f;
  1118. if (OptDayNight==2) k=0.3 + k/2.75;
  1119. DeltaFunc(SkyTraceK, k, (0.07f + (float)fabs(k-SkyTraceK)) * (TimeDt / 512.f) );
  1120. return SkyTraceK;
  1121. }
  1122. void TryHiResTx()
  1123. {
  1124. int UsedMem = 0;
  1125. for (int m=0; m<d3dmemmapsize; m++) {
  1126. if (!d3dMemMap[m].cpuaddr) break;
  1127. if (d3dMemMap[m].lastused+2>=d3dMemUsageCount)
  1128. UsedMem+= d3dMemMap[m].size;
  1129. }
  1130. /*
  1131. wsprintf(logt, "TOTALL: %d USED: %d", d3dTexturesMem, UsedMem);
  1132. AddMessage(logt);
  1133. */
  1134. if (UsedMem*4 < (int)d3dTexturesMem)
  1135. LOWRESTX = FALSE;
  1136. }
  1137. void ShowVideo()
  1138. {
  1139. /*
  1140. char t[128];
  1141. wsprintf(t, "T-mem loaded: %dK", d3dMemLoaded >> 10);
  1142. if (d3dMemLoaded) AddMessage(t);
  1143. */
  1144. if (d3dMemLoaded > 200*1024) LowHardMemory++;
  1145. else LowHardMemory=0;
  1146. if (LowHardMemory>2) {
  1147. LOWRESTX = TRUE;
  1148. LowHardMemory = 0; }
  1149. if (OptText==0) LOWRESTX = TRUE;
  1150. if (OptText==1) LOWRESTX = FALSE;
  1151. if (OptText==2)
  1152. if (LOWRESTX && (Takt & 63)==0) TryHiResTx();
  1153. if (UNDERWATER)
  1154. RenderFSRect(CurFogColor+0x70000000);
  1155. if (OptDayNight!=2)
  1156. if (!UNDERWATER && (SunLight>1.0f) ) {
  1157. RenderFSRect(0xFFFFC0 + ((int)SunLight<<24));
  1158. }
  1159. RenderHealthBar();
  1160. d3dMemUsageCount++;
  1161. d3dMemLoaded = 0;
  1162. hRes = lpd3dDevice->EndScene();
  1163. hRes = lpddPrimary->Blt( NULL, lpddBack, NULL, DDBLT_WAIT, NULL );
  1164. d3dClearBuffers();
  1165. hRes = lpd3dDevice->BeginScene( );
  1166. }
  1167. void CopyBackToDIB()
  1168. {
  1169. DDSURFACEDESC ddsd;
  1170. ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
  1171. ddsd.dwSize = sizeof(DDSURFACEDESC);
  1172. if( lpddBack->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
  1173. WORD *lpVMem = (WORD*) ddsd.lpSurface;
  1174. ddsd.lPitch/=2;
  1175. for (int y=0; y<=256; y++)
  1176. CopyMemory( (WORD*)lpVideoBuf + y*1024,
  1177. lpVMem + y*ddsd.lPitch,
  1178. 256*2);
  1179. lpddBack->Unlock(ddsd.lpSurface);
  1180. }
  1181. void CopyHARDToDIB()
  1182. {
  1183. DDSURFACEDESC ddsd;
  1184. ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
  1185. ddsd.dwSize = sizeof(DDSURFACEDESC);
  1186. if( lpddPrimary->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
  1187. WORD *lpVMem = (WORD*) ddsd.lpSurface;
  1188. ddsd.lPitch/=2;
  1189. for (int y=0; y<=WinH; y++)
  1190. CopyMemory( (WORD*)lpVideoBuf + y*1024,
  1191. lpVMem + y*ddsd.lPitch,
  1192. WinW*2);
  1193. lpddPrimary->Unlock(ddsd.lpSurface);
  1194. }
  1195. void FXPutBitMap(int x0, int y0, int w, int h, int smw, LPVOID lpData)
  1196. {
  1197. DDSURFACEDESC ddsd;
  1198. ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
  1199. ddsd.dwSize = sizeof(DDSURFACEDESC);
  1200. if( lpddBack->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
  1201. WORD *lpVMem = (WORD*) ddsd.lpSurface;
  1202. ddsd.lPitch/=2;
  1203. lpVMem+=x0+y0 * ddsd.lPitch;
  1204. for (int y=0; y<h; y++)
  1205. CopyMemory( lpVMem + y*ddsd.lPitch, ((WORD*)lpData)+y*smw, w*2);
  1206. lpddBack->Unlock(ddsd.lpSurface);
  1207. }
  1208. void DrawPicture(int x, int y, TPicture &pic)
  1209. {
  1210. FXPutBitMap(x, y, pic.W, pic.H, pic.W, pic.lpImage);
  1211. }
  1212. void ddTextOut(int x, int y, LPSTR t, int color)
  1213. {
  1214. lpddBack->GetDC( &ddBackDC );
  1215. SetBkMode( ddBackDC, TRANSPARENT );
  1216. HFONT oldfont;
  1217. if (SmallFont) oldfont = (HFONT)SelectObject(ddBackDC, fnt_Small);
  1218. SetTextColor(ddBackDC, 0x00101010);
  1219. TextOut(ddBackDC, x+2, y+1, t, strlen(t));
  1220. SetTextColor(ddBackDC, color);
  1221. TextOut(ddBackDC, x+1, y, t, strlen(t));
  1222. if (SmallFont) SelectObject(ddBackDC, oldfont);
  1223. lpddBack->ReleaseDC( ddBackDC );
  1224. }
  1225. void DrawTrophyText(int x0, int y0)
  1226. {
  1227. int x;
  1228. SmallFont = TRUE;
  1229. HFONT oldfont = (HFONT)SelectObject(hdcMain, fnt_Small);
  1230. int tc = TrophyBody;
  1231. int dtype = TrophyRoom.Body[tc].ctype;
  1232. int time = TrophyRoom.Body[tc].time;
  1233. int date = TrophyRoom.Body[tc].date;
  1234. int wep = TrophyRoom.Body[tc].weapon;
  1235. int score = TrophyRoom.Body[tc].score;
  1236. float scale = TrophyRoom.Body[tc].scale;
  1237. float range = TrophyRoom.Body[tc].range;
  1238. char t[32];
  1239. x0+=14; y0+=18;
  1240. x = x0;
  1241. ddTextOut(x, y0 , "Name: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Name: ");
  1242. ddTextOut(x, y0 , DinoInfo[dtype].Name, 0x0000BFBF);
  1243. x = x0;
  1244. ddTextOut(x, y0+16, "Weight: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Weight: ");
  1245. if (OptSys)
  1246. sprintf(t,"%3.2ft ", DinoInfo[dtype].Mass * scale * scale / 0.907);
  1247. else
  1248. sprintf(t,"%3.2fT ", DinoInfo[dtype].Mass * scale * scale);
  1249. ddTextOut(x, y0+16, t, 0x0000BFBF); x+=GetTextW(hdcMain,t);
  1250. ddTextOut(x, y0+16, "Length: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Length: ");
  1251. if (OptSys)
  1252. sprintf(t,"%3.2fft", DinoInfo[dtype].Length * scale / 0.3);
  1253. else
  1254. sprintf(t,"%3.2fm", DinoInfo[dtype].Length * scale);
  1255. ddTextOut(x, y0+16, t, 0x0000BFBF);
  1256. x = x0;
  1257. ddTextOut(x, y0+32, "Weapon: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Weapon: ");
  1258. wsprintf(t,"%s ", WeapInfo[wep].Name);
  1259. ddTextOut(x, y0+32, t, 0x0000BFBF); x+=GetTextW(hdcMain,t);
  1260. ddTextOut(x, y0+32, "Score: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Score: ");
  1261. wsprintf(t,"%d", score);
  1262. ddTextOut(x, y0+32, t, 0x0000BFBF);
  1263. x = x0;
  1264. ddTextOut(x, y0+48, "Range of kill: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Range of kill: ");
  1265. if (OptSys) sprintf(t,"%3.1fft", range / 0.3);
  1266. else sprintf(t,"%3.1fm", range);
  1267. ddTextOut(x, y0+48, t, 0x0000BFBF);
  1268. x = x0;
  1269. ddTextOut(x, y0+64, "Date: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Date: ");
  1270. if (OptSys)
  1271. wsprintf(t,"%d.%d.%d ", ((date>>10) & 255), (date & 255), date>>20);
  1272. else
  1273. wsprintf(t,"%d.%d.%d ", (date & 255), ((date>>10) & 255), date>>20);
  1274. ddTextOut(x, y0+64, t, 0x0000BFBF); x+=GetTextW(hdcMain,t);
  1275. ddTextOut(x, y0+64, "Time: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Time: ");
  1276. wsprintf(t,"%d:%02d", ((time>>10) & 255), (time & 255));
  1277. ddTextOut(x, y0+64, t, 0x0000BFBF);
  1278. SmallFont = FALSE;
  1279. SelectObject(hdcMain, oldfont);
  1280. }
  1281. void Render_LifeInfo(int li)
  1282. {
  1283. int x,y;
  1284. SmallFont = TRUE;
  1285. //HFONT oldfont = SelectObject(hdcMain, fnt_Small);
  1286. int ctype = Characters[li].CType;
  1287. float scale = Characters[li].scale;
  1288. char t[32];
  1289. x = VideoCX + WinW / 64;
  1290. y = VideoCY + (int)(WinH / 6.8);
  1291. ddTextOut(x, y, DinoInfo[ctype].Name, 0x0000b000);
  1292. if (OptSys) sprintf(t,"Weight: %3.2ft ", DinoInfo[ctype].Mass * scale * scale / 0.907);
  1293. else sprintf(t,"Weight: %3.2fT ", DinoInfo[ctype].Mass * scale * scale);
  1294. ddTextOut(x, y+16, t, 0x0000b000);
  1295. int R = (int)(VectorLength( SubVectors(Characters[li].pos, PlayerPos) )*3 / 64.f);
  1296. if (OptSys) sprintf(t,"Distance: %dft ", R);
  1297. else sprintf(t,"Distance: %dm ", R/3);
  1298. ddTextOut(x, y+32, t, 0x0000b000);
  1299. SmallFont = FALSE;
  1300. //SelectObject(hdcMain, oldfont);
  1301. }
  1302. void RenderFXMMap()
  1303. {
  1304. }
  1305. void ShowControlElements()
  1306. {
  1307. char buf[128];
  1308. //ddTextOut(100, 100, "!", 0x0020A0A0);
  1309. lpddBack->GetDC( &ddBackDC );
  1310. lpddBack->ReleaseDC( ddBackDC );
  1311. if (TIMER) {
  1312. wsprintf(buf,"msc: %d", TimeDt);
  1313. ddTextOut(WinEX-81, 11, buf, 0x0020A0A0);
  1314. wsprintf(buf,"polys: %d", dFacesCount);
  1315. ddTextOut(WinEX-90, 24, buf, 0x0020A0A0);
  1316. wsprintf(buf,"%d", Env);
  1317. ddTextOut(10, 24, buf, 0x0020A0A0);
  1318. }
  1319. if (MessageList.timeleft) {
  1320. if (RealTime>MessageList.timeleft) MessageList.timeleft = 0;
  1321. ddTextOut(10, 10, MessageList.mtext, 0x0020A0A0);
  1322. }
  1323. if (ExitTime) {
  1324. int y = WinH / 3;
  1325. wsprintf(buf,"Preparing for evacuation...");
  1326. ddTextOut(VideoCX - GetTextW(hdcCMain, buf)/2, y, buf, 0x0060C0D0);
  1327. wsprintf(buf,"%d seconds left.", 1 + ExitTime / 1000);
  1328. ddTextOut(VideoCX - GetTextW(hdcCMain, buf)/2, y + 18, buf, 0x0060C0D0);
  1329. }
  1330. }
  1331. void ClipVector(CLIPPLANE& C, int vn)
  1332. {
  1333. int ClipRes = 0;
  1334. float s,s1,s2;
  1335. int vleft = (vn-1); if (vleft <0) vleft=vused-1;
  1336. int vright = (vn+1); if (vright>=vused) vright=0;
  1337. MulVectorsScal(cp[vn].ev.v, C.nv, s); /*s=SGN(s-0.01f);*/
  1338. if (s>=0) return;
  1339. MulVectorsScal(cp[vleft ].ev.v, C.nv, s1); /* s1=SGN(s1+0.01f); */ //s1+=0.0001f;
  1340. MulVectorsScal(cp[vright].ev.v, C.nv, s2); /* s2=SGN(s2+0.01f); */ //s2+=0.0001f;
  1341. if (s1>0) {
  1342. ClipRes+=1;
  1343. /*
  1344. CalcHitPoint(C,cp[vn].ev.v,
  1345. cp[vleft].ev.v, hleft.ev.v);
  1346. float ll = VectorLength(SubVectors(cp[vleft].ev.v, cp[vn].ev.v));
  1347. float lc = VectorLength(SubVectors(hleft.ev.v, cp[vn].ev.v));
  1348. lc = lc / ll;
  1349. */
  1350. float lc = -s / (s1-s);
  1351. hleft.ev.v.x = cp[vn].ev.v.x + ((cp[vleft].ev.v.x - cp[vn].ev.v.x) * lc);
  1352. hleft.ev.v.y = cp[vn].ev.v.y + ((cp[vleft].ev.v.y - cp[vn].ev.v.y) * lc);
  1353. hleft.ev.v.z = cp[vn].ev.v.z + ((cp[vleft].ev.v.z - cp[vn].ev.v.z) * lc);
  1354. hleft.tx = cp[vn].tx + ((cp[vleft].tx - cp[vn].tx) * lc);
  1355. hleft.ty = cp[vn].ty + ((cp[vleft].ty - cp[vn].ty) * lc);
  1356. hleft.ev.Light = cp[vn].ev.Light + (int)((cp[vleft].ev.Light - cp[vn].ev.Light) * lc);
  1357. hleft.ev.ALPHA = cp[vn].ev.ALPHA + (int)((cp[vleft].ev.ALPHA - cp[vn].ev.ALPHA) * lc);
  1358. hleft.ev.Fog = cp[vn].ev.Fog + ((cp[vleft].ev.Fog - cp[vn].ev.Fog ) * lc);
  1359. }
  1360. if (s2>0) {
  1361. ClipRes+=2;
  1362. /*
  1363. CalcHitPoint(C,cp[vn].ev.v,
  1364. cp[vright].ev.v, hright.ev.v);
  1365. float ll = VectorLength(SubVectors(cp[vright].ev.v, cp[vn].ev.v));
  1366. float lc = VectorLength(SubVectors(hright.ev.v, cp[vn].ev.v));
  1367. lc = lc / ll;*/
  1368. float lc = -s / (s2-s);
  1369. hright.ev.v.x = cp[vn].ev.v.x + ((cp[vright].ev.v.x - cp[vn].ev.v.x) * lc);
  1370. hright.ev.v.y = cp[vn].ev.v.y + ((cp[vright].ev.v.y - cp[vn].ev.v.y) * lc);
  1371. hright.ev.v.z = cp[vn].ev.v.z + ((cp[vright].ev.v.z - cp[vn].ev.v.z) * lc);
  1372. hright.tx = cp[vn].tx + ((cp[vright].tx - cp[vn].tx) * lc);
  1373. hright.ty = cp[vn].ty + ((cp[vright].ty - cp[vn].ty) * lc);
  1374. hright.ev.Light = cp[vn].ev.Light + (int)((cp[vright].ev.Light - cp[vn].ev.Light) * lc);
  1375. hright.ev.ALPHA = cp[vn].ev.ALPHA + (int)((cp[vright].ev.ALPHA - cp[vn].ev.ALPHA) * lc);
  1376. hright.ev.Fog = cp[vn].ev.Fog + ((cp[vright].ev.Fog - cp[vn].ev.Fog ) * lc);
  1377. }
  1378. if (ClipRes == 0) {
  1379. u--; vused--;
  1380. cp[vn] = cp[vn+1];
  1381. cp[vn+1] = cp[vn+2];
  1382. cp[vn+2] = cp[vn+3];
  1383. cp[vn+3] = cp[vn+4];
  1384. cp[vn+4] = cp[vn+5];
  1385. cp[vn+5] = cp[vn+6];
  1386. //memcpy(&cp[vn], &cp[vn+1], (15-vn)*sizeof(ClipPoint));
  1387. }
  1388. if (ClipRes == 1) {cp[vn] = hleft; }
  1389. if (ClipRes == 2) {cp[vn] = hright;}
  1390. if (ClipRes == 3) {
  1391. u++; vused++;
  1392. //memcpy(&cp[vn+1], &cp[vn], (15-vn)*sizeof(ClipPoint));
  1393. cp[vn+6] = cp[vn+5];
  1394. cp[vn+5] = cp[vn+4];
  1395. cp[vn+4] = cp[vn+3];
  1396. cp[vn+3] = cp[vn+2];
  1397. cp[vn+2] = cp[vn+1];
  1398. cp[vn+1] = cp[vn];
  1399. cp[vn] = hleft;
  1400. cp[vn+1] = hright;
  1401. }
  1402. }
  1403. void DrawTPlaneClip(BOOL SECONT)
  1404. {
  1405. if (!WATERREVERSE) {
  1406. MulVectorsVect(SubVectors(ev[1].v, ev[0].v), SubVectors(ev[2].v, ev[0].v), nv);
  1407. if (nv.x*ev[0].v.x + nv.y*ev[0].v.y + nv.z*ev[0].v.z<0) return;
  1408. }
  1409. cp[0].ev = ev[0]; cp[1].ev = ev[1]; cp[2].ev = ev[2];
  1410. if (ReverseOn)
  1411. if (SECONT) {
  1412. switch (TDirection) {
  1413. case 0:
  1414. cp[0].tx = TCMIN; cp[0].ty = TCMAX;
  1415. cp[1].tx = TCMAX; cp[1].ty = TCMIN;
  1416. cp[2].tx = TCMAX; cp[2].ty = TCMAX;
  1417. break;
  1418. case 1:
  1419. cp[0].tx = TCMAX; cp[0].ty = TCMAX;
  1420. cp[1].tx = TCMIN; cp[1].ty = TCMIN;
  1421. cp[2].tx = TCMAX; cp[2].ty = TCMIN;
  1422. break;
  1423. case 2:
  1424. cp[0].tx = TCMAX; cp[0].ty = TCMIN;
  1425. cp[1].tx = TCMIN; cp[1].ty = TCMAX;
  1426. cp[2].tx = TCMIN; cp[2].ty = TCMIN;
  1427. break;
  1428. case 3:
  1429. cp[0].tx = TCMIN; cp[0].ty = TCMIN;
  1430. cp[1].tx = TCMAX; cp[1].ty = TCMAX;
  1431. cp[2].tx = TCMIN; cp[2].ty = TCMAX;
  1432. break;
  1433. }
  1434. } else {
  1435. switch (TDirection) {
  1436. case 0:
  1437. cp[0].tx = TCMIN; cp[0].ty = TCMIN;
  1438. cp[1].tx = TCMAX; cp[1].ty = TCMIN;
  1439. cp[2].tx = TCMIN; cp[2].ty = TCMAX;
  1440. break;
  1441. case 1:
  1442. cp[0].tx = TCMIN; cp[0].ty = TCMAX;
  1443. cp[1].tx = TCMIN; cp[1].ty = TCMIN;
  1444. cp[2].tx = TCMAX; cp[2].ty = TCMAX;
  1445. break;
  1446. case 2:
  1447. cp[0].tx = TCMAX; cp[0].ty = TCMAX;
  1448. cp[1].tx = TCMIN; cp[1].ty = TCMAX;
  1449. cp[2].tx = TCMAX; cp[2].ty = TCMIN;
  1450. break;
  1451. case 3:
  1452. cp[0].tx = TCMAX; cp[0].ty = TCMIN;
  1453. cp[1].tx = TCMAX; cp[1].ty = TCMAX;
  1454. cp[2].tx = TCMIN; cp[2].ty = TCMIN;
  1455. break;
  1456. }
  1457. }
  1458. else
  1459. if (SECONT) {
  1460. switch (TDirection) {
  1461. case 0:
  1462. cp[0].tx = TCMIN; cp[0].ty = TCMIN;
  1463. cp[1].tx = TCMAX; cp[1].ty = TCMAX;
  1464. cp[2].tx = TCMIN; cp[2].ty = TCMAX;
  1465. break;
  1466. case 1:
  1467. cp[0].tx = TCMIN; cp[0].ty = TCMAX;
  1468. cp[1].tx = TCMAX; cp[1].ty = TCMIN;
  1469. cp[2].tx = TCMAX; cp[2].ty = TCMAX;
  1470. break;
  1471. case 2:
  1472. cp[0].tx = TCMAX; cp[0].ty = TCMAX;
  1473. cp[1].tx = TCMIN; cp[1].ty = TCMIN;
  1474. cp[2].tx = TCMAX; cp[2].ty = TCMIN;
  1475. break;
  1476. case 3:
  1477. cp[0].tx = TCMAX; cp[0].ty = TCMIN;
  1478. cp[1].tx = TCMIN; cp[1].ty = TCMAX;
  1479. cp[2].tx = TCMIN; cp[2].ty = TCMIN;
  1480. break;
  1481. }
  1482. } else {
  1483. switch (TDirection) {
  1484. case 0:
  1485. cp[0].tx = TCMIN; cp[0].ty = TCMIN;
  1486. cp[1].tx = TCMAX; cp[1].ty = TCMIN;
  1487. cp[2].tx = TCMAX; cp[2].ty = TCMAX;
  1488. break;
  1489. case 1:
  1490. cp[0].tx = TCMIN; cp[0].ty = TCMAX;
  1491. cp[1].tx = TCMIN; cp[1].ty = TCMIN;
  1492. cp[2].tx = TCMAX; cp[2].ty = TCMIN;
  1493. break;
  1494. case 2:
  1495. cp[0].tx = TCMAX; cp[0].ty = TCMAX;
  1496. cp[1].tx = TCMIN; cp[1].ty = TCMAX;
  1497. cp[2].tx = TCMIN; cp[2].ty = TCMIN;
  1498. break;
  1499. case 3:
  1500. cp[0].tx = TCMAX; cp[0].ty = TCMIN;
  1501. cp[1].tx = TCMAX; cp[1].ty = TCMAX;
  1502. cp[2].tx = TCMIN; cp[2].ty = TCMAX;
  1503. break;
  1504. }
  1505. }
  1506. vused = 3;
  1507. for (u=0; u<vused; u++) cp[u].ev.v.z+=16.0f;
  1508. for (u=0; u<vused; u++) ClipVector(ClipZ,u);
  1509. for (u=0; u<vused; u++) cp[u].ev.v.z-=16.0f;
  1510. if (vused<3) return;
  1511. for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) return;
  1512. for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) return;
  1513. for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) return;
  1514. for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) return;
  1515. for (u=0; u<vused; u++) {
  1516. cp[u].ev.scrx = (VideoCX)*16 - (int)(16.f * cp[u].ev.v.x / cp[u].ev.v.z * CameraW);
  1517. cp[u].ev.scry = (VideoCY)*16 + (int)(16.f * cp[u].ev.v.y / cp[u].ev.v.z * CameraH);
  1518. }
  1519. if (!lpVertexG)
  1520. d3dStartBufferG();
  1521. if (GVCnt>380) {
  1522. if (lpVertexG) d3dEndBufferG(FALSE);
  1523. d3dStartBufferG();
  1524. }
  1525. if (hGTexture!=hTexture) {
  1526. hGTexture=hTexture;
  1527. lpInstructionG->bOpcode = D3DOP_STATERENDER;
  1528. lpInstructionG->bSize = sizeof(D3DSTATE);
  1529. lpInstructionG->wCount = 1;
  1530. lpInstructionG++;
  1531. lpState = (LPD3DSTATE)lpInstructionG;
  1532. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
  1533. lpState->dwArg[0] = hTexture;
  1534. lpState++;
  1535. lpInstructionG = (LPD3DINSTRUCTION)lpState;
  1536. lpwTriCount = &(lpInstructionG->wCount);
  1537. lpInstructionG->bOpcode = D3DOP_TRIANGLE;
  1538. lpInstructionG->bSize = sizeof(D3DTRIANGLE);
  1539. lpInstructionG->wCount = 0;
  1540. lpInstructionG++;
  1541. }
  1542. lpTriangle = (LPD3DTRIANGLE)lpInstructionG;
  1543. for (u=0; u<vused-2; u++) {
  1544. lpVertexG->sx = (float)cp[0].ev.scrx / 16.f;
  1545. lpVertexG->sy = (float)cp[0].ev.scry / 16.f;
  1546. lpVertexG->sz = _ZSCALE / cp[0].ev.v.z;
  1547. lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
  1548. lpVertexG->color = (int)(cp[0].ev.Light) * 0x00010101 | ((int)cp[0].ev.ALPHA<<24);
  1549. lpVertexG->specular = (255-(int)cp[0].ev.Fog)<<24;//0x7F000000;
  1550. lpVertexG->tu = (float)(cp[0].tx) / (128.f*65536.f);
  1551. lpVertexG->tv = (float)(cp[0].ty) / (128.f*65536.f);
  1552. lpVertexG++;
  1553. lpVertexG->sx = (float)cp[u+1].ev.scrx / 16.f;
  1554. lpVertexG->sy = (float)cp[u+1].ev.scry / 16.f;
  1555. lpVertexG->sz = _ZSCALE / cp[u+1].ev.v.z;
  1556. lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
  1557. lpVertexG->color = (int)(cp[u+1].ev.Light) * 0x00010101 | ((int)cp[u+1].ev.ALPHA<<24);
  1558. lpVertexG->specular = (255-(int)cp[u+1].ev.Fog)<<24;//0x7F000000;
  1559. lpVertexG->tu = (float)(cp[u+1].tx) / (128.f*65536.f);
  1560. lpVertexG->tv = (float)(cp[u+1].ty) / (128.f*65536.f);
  1561. lpVertexG++;
  1562. lpVertexG->sx = (float)cp[u+2].ev.scrx / 16.f;
  1563. lpVertexG->sy = (float)cp[u+2].ev.scry / 16.f;
  1564. lpVertexG->sz = _ZSCALE / cp[u+2].ev.v.z;
  1565. lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
  1566. lpVertexG->color = (int)(cp[u+2].ev.Light) * 0x00010101 | ((int)cp[u+2].ev.ALPHA<<24);
  1567. lpVertexG->specular = (255-(int)cp[u+2].ev.Fog)<<24;//0x7F000000;
  1568. lpVertexG->tu = (float)(cp[u+2].tx) / (128.f*65536.f);
  1569. lpVertexG->tv = (float)(cp[u+2].ty) / (128.f*65536.f);
  1570. lpVertexG++;
  1571. lpTriangle->wV1 = GVCnt;
  1572. lpTriangle->wV2 = GVCnt+1;
  1573. lpTriangle->wV3 = GVCnt+2;
  1574. lpTriangle->wFlags = 0;
  1575. lpTriangle++;
  1576. *lpwTriCount = (*lpwTriCount) + 1;
  1577. GVCnt+=3;
  1578. }
  1579. lpInstructionG = (LPD3DINSTRUCTION)lpTriangle;
  1580. }
  1581. void DrawTPlane(BOOL SECONT)
  1582. {
  1583. int n;
  1584. //if (!WATERREVERSE) {
  1585. MulVectorsVect(SubVectors(ev[1].v, ev[0].v), SubVectors(ev[2].v, ev[0].v), nv);
  1586. if (nv.x*ev[0].v.x + nv.y*ev[0].v.y + nv.z*ev[0].v.z<0) return;
  1587. //}
  1588. Mask1=0x007F;
  1589. for (n=0; n<3; n++) {
  1590. if (ev[n].DFlags & 128) return;
  1591. Mask1=Mask1 & ev[n].DFlags; }
  1592. if (Mask1>0) return;
  1593. if (ReverseOn)
  1594. if (SECONT) {
  1595. switch (TDirection) {
  1596. case 0:
  1597. scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
  1598. scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
  1599. scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
  1600. break;
  1601. case 1:
  1602. scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
  1603. scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
  1604. scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
  1605. break;
  1606. case 2:
  1607. scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
  1608. scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
  1609. scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
  1610. break;
  1611. case 3:
  1612. scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
  1613. scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
  1614. scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
  1615. break;
  1616. }
  1617. } else {
  1618. switch (TDirection) {
  1619. case 0:
  1620. scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
  1621. scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
  1622. scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
  1623. break;
  1624. case 1:
  1625. scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
  1626. scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
  1627. scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
  1628. break;
  1629. case 2:
  1630. scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
  1631. scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
  1632. scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
  1633. break;
  1634. case 3:
  1635. scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
  1636. scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
  1637. scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
  1638. break;
  1639. }
  1640. }
  1641. else
  1642. if (SECONT) {
  1643. switch (TDirection) {
  1644. case 0:
  1645. scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
  1646. scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
  1647. scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
  1648. break;
  1649. case 1:
  1650. scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
  1651. scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
  1652. scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
  1653. break;
  1654. case 2:
  1655. scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
  1656. scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
  1657. scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
  1658. break;
  1659. case 3:
  1660. scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
  1661. scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
  1662. scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
  1663. break;
  1664. }
  1665. } else {
  1666. switch (TDirection) {
  1667. case 0:
  1668. scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
  1669. scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
  1670. scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
  1671. break;
  1672. case 1:
  1673. scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
  1674. scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
  1675. scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
  1676. break;
  1677. case 2:
  1678. scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
  1679. scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
  1680. scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
  1681. break;
  1682. case 3:
  1683. scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
  1684. scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
  1685. scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
  1686. break;
  1687. }
  1688. }
  1689. int alpha1 = 255;
  1690. int alpha2 = 255;
  1691. int alpha3 = 255;
  1692. //if (!WATERREVERSE)
  1693. if (zs > (ctViewR-8)<<8) {
  1694. int zz;
  1695. zz = (int)VectorLength(ev[0].v) - 256 * (ctViewR-4);
  1696. if (zz > 0) alpha1 = max(0, 255 - zz / 3); else alpha1 = 255;
  1697. zz = (int)VectorLength(ev[1].v) - 256 * (ctViewR-4);
  1698. if (zz > 0) alpha2 = max(0, 255 - zz / 3); else alpha2 = 255;
  1699. zz = (int)VectorLength(ev[2].v) - 256 * (ctViewR-4);
  1700. if (zz > 0) alpha3 = max(0, 255 - zz / 3); else alpha3 = 255;
  1701. }
  1702. if (!lpVertexG)
  1703. d3dStartBufferG();
  1704. if (GVCnt>380) {
  1705. if (lpVertexG) d3dEndBufferG(FALSE);
  1706. d3dStartBufferG();
  1707. }
  1708. lpVertexG->sx = (float)ev[0].scrx / 16;
  1709. lpVertexG->sy = (float)ev[0].scry / 16;
  1710. lpVertexG->sz = _ZSCALE / ev[0].v.z;
  1711. lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
  1712. lpVertexG->color = (int)(ev[0].Light) * 0x00010101 | alpha1<<24;
  1713. lpVertexG->specular = (255-(int)ev[0].Fog)<<24;//0x7F000000;
  1714. lpVertexG->tu = (float)(scrp[0].tx) / (128.f*65536.f);
  1715. lpVertexG->tv = (float)(scrp[0].ty) / (128.f*65536.f);
  1716. lpVertexG++;
  1717. lpVertexG->sx = (float)ev[1].scrx / 16;
  1718. lpVertexG->sy = (float)ev[1].scry / 16;
  1719. lpVertexG->sz = _ZSCALE / ev[1].v.z;
  1720. lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
  1721. lpVertexG->color = (int)(ev[1].Light) * 0x00010101 | alpha2<<24;
  1722. lpVertexG->specular = (255-(int)ev[1].Fog)<<24;//0x7F000000;
  1723. lpVertexG->tu = (float)(scrp[1].tx) / (128.f*65536.f);
  1724. lpVertexG->tv = (float)(scrp[1].ty) / (128.f*65536.f);
  1725. lpVertexG++;
  1726. lpVertexG->sx = (float)ev[2].scrx / 16;
  1727. lpVertexG->sy = (float)ev[2].scry / 16;
  1728. lpVertexG->sz = _ZSCALE / ev[2].v.z;
  1729. lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
  1730. lpVertexG->color = (int)(ev[2].Light) * 0x00010101 | alpha3<<24;
  1731. lpVertexG->specular = (255-(int)ev[2].Fog)<<24;//0x7F000000;
  1732. lpVertexG->tu = (float)(scrp[2].tx) / (128.f*65536.f);
  1733. lpVertexG->tv = (float)(scrp[2].ty) / (128.f*65536.f);
  1734. lpVertexG++;
  1735. if (hGTexture!=hTexture) {
  1736. hGTexture=hTexture;
  1737. lpInstructionG->bOpcode = D3DOP_STATERENDER;
  1738. lpInstructionG->bSize = sizeof(D3DSTATE);
  1739. lpInstructionG->wCount = 1;
  1740. lpInstructionG++;
  1741. lpState = (LPD3DSTATE)lpInstructionG;
  1742. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
  1743. lpState->dwArg[0] = hTexture;
  1744. lpState++;
  1745. lpInstructionG = (LPD3DINSTRUCTION)lpState;
  1746. lpwTriCount = (&lpInstructionG->wCount);
  1747. lpInstructionG->bOpcode = D3DOP_TRIANGLE;
  1748. lpInstructionG->bSize = sizeof(D3DTRIANGLE);
  1749. lpInstructionG->wCount = 0;
  1750. lpInstructionG++;
  1751. }
  1752. lpTriangle = (LPD3DTRIANGLE)lpInstructionG;
  1753. lpTriangle->wV1 = GVCnt;
  1754. lpTriangle->wV2 = GVCnt+1;
  1755. lpTriangle->wV3 = GVCnt+2;
  1756. lpTriangle->wFlags = 0;
  1757. lpTriangle++;
  1758. *lpwTriCount = (*lpwTriCount) + 1;
  1759. lpInstructionG = (LPD3DINSTRUCTION)lpTriangle;
  1760. GVCnt+=3;
  1761. }
  1762. void DrawTPlaneW(BOOL SECONT)
  1763. {
  1764. int n;
  1765. Mask1=0x007F;
  1766. for (n=0; n<3; n++) {
  1767. if (ev[n].DFlags & 128) return;
  1768. Mask1=Mask1 & ev[n].DFlags; }
  1769. if (Mask1>0) return;
  1770. /*
  1771. for (n=0; n<3; n++) {
  1772. scrp[n].x = (float)(VideoCX) - (ev[n].v.x / ev[n].v.z * CameraW);
  1773. scrp[n].y = (float)(VideoCY) + (ev[n].v.y / ev[n].v.z * CameraH);
  1774. scrp[n].Light = ev[n].Light;
  1775. } */
  1776. if (ReverseOn)
  1777. if (SECONT) {
  1778. switch (TDirection) {
  1779. case 0:
  1780. scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
  1781. scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
  1782. scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
  1783. break;
  1784. case 1:
  1785. scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
  1786. scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
  1787. scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
  1788. break;
  1789. case 2:
  1790. scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
  1791. scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
  1792. scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
  1793. break;
  1794. case 3:
  1795. scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
  1796. scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
  1797. scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
  1798. break;
  1799. }
  1800. } else {
  1801. switch (TDirection) {
  1802. case 0:
  1803. scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
  1804. scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
  1805. scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
  1806. break;
  1807. case 1:
  1808. scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
  1809. scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
  1810. scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
  1811. break;
  1812. case 2:
  1813. scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
  1814. scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
  1815. scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
  1816. break;
  1817. case 3:
  1818. scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
  1819. scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
  1820. scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
  1821. break;
  1822. }
  1823. }
  1824. else
  1825. if (SECONT) {
  1826. switch (TDirection) {
  1827. case 0:
  1828. scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
  1829. scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
  1830. scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
  1831. break;
  1832. case 1:
  1833. scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
  1834. scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
  1835. scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
  1836. break;
  1837. case 2:
  1838. scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
  1839. scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
  1840. scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
  1841. break;
  1842. case 3:
  1843. scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
  1844. scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
  1845. scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
  1846. break;
  1847. }
  1848. } else {
  1849. switch (TDirection) {
  1850. case 0:
  1851. scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
  1852. scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
  1853. scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
  1854. break;
  1855. case 1:
  1856. scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
  1857. scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
  1858. scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
  1859. break;
  1860. case 2:
  1861. scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
  1862. scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
  1863. scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
  1864. break;
  1865. case 3:
  1866. scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
  1867. scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
  1868. scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
  1869. break;
  1870. }
  1871. }
  1872. if (!UNDERWATER)
  1873. if (zs > (ctViewR-8)<<8) {
  1874. float zz;
  1875. zz = VectorLength(ev[0].v) - 256 * (ctViewR-4);
  1876. if (zz > 0) ev[0].ALPHA = max(0.f,255.f - zz / 3.f);
  1877. zz = VectorLength(ev[1].v) - 256 * (ctViewR-4);
  1878. if (zz > 0) ev[1].ALPHA = max(0.f, 255.f - zz / 3.f);
  1879. zz = VectorLength(ev[2].v) - 256 * (ctViewR-4);
  1880. if (zz > 0) ev[2].ALPHA = max(0,255.f - zz / 3.f);
  1881. }
  1882. if (!lpVertexG)
  1883. d3dStartBufferG();
  1884. if (GVCnt>380) {
  1885. if (lpVertexG) d3dEndBufferG(FALSE);
  1886. d3dStartBufferG();
  1887. }
  1888. lpVertexG->sx = (float)ev[0].scrx / 16;
  1889. lpVertexG->sy = (float)ev[0].scry / 16;
  1890. lpVertexG->sz = _ZSCALE / ev[0].v.z;
  1891. lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
  1892. lpVertexG->color = (int)(ev[0].Light) * 0x00010101 | ev[0].ALPHA<<24;
  1893. lpVertexG->specular = (255-(int)ev[0].Fog)<<24;
  1894. lpVertexG->tu = (float)(scrp[0].tx) / (128.f*65536.f);
  1895. lpVertexG->tv = (float)(scrp[0].ty) / (128.f*65536.f);
  1896. lpVertexG++;
  1897. lpVertexG->sx = (float)ev[1].scrx / 16;
  1898. lpVertexG->sy = (float)ev[1].scry / 16;
  1899. lpVertexG->sz = _ZSCALE / ev[1].v.z;
  1900. lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
  1901. lpVertexG->color = (int)(ev[1].Light) * 0x00010101 | ev[1].ALPHA<<24;
  1902. lpVertexG->specular = (255-(int)ev[1].Fog)<<24;
  1903. lpVertexG->tu = (float)(scrp[1].tx) / (128.f*65536.f);
  1904. lpVertexG->tv = (float)(scrp[1].ty) / (128.f*65536.f);
  1905. lpVertexG++;
  1906. lpVertexG->sx = (float)ev[2].scrx / 16;
  1907. lpVertexG->sy = (float)ev[2].scry / 16;
  1908. lpVertexG->sz = _ZSCALE / ev[2].v.z;
  1909. lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
  1910. lpVertexG->color = (int)(ev[2].Light) * 0x00010101 | ev[2].ALPHA<<24;
  1911. lpVertexG->specular = (255-(int)ev[2].Fog)<<24;
  1912. lpVertexG->tu = (float)(scrp[2].tx) / (128.f*65536.f);
  1913. lpVertexG->tv = (float)(scrp[2].ty) / (128.f*65536.f);
  1914. lpVertexG++;
  1915. if (hGTexture!=hTexture) {
  1916. hGTexture=hTexture;
  1917. lpInstructionG->bOpcode = D3DOP_STATERENDER;
  1918. lpInstructionG->bSize = sizeof(D3DSTATE);
  1919. lpInstructionG->wCount = 1;
  1920. lpInstructionG++;
  1921. lpState = (LPD3DSTATE)lpInstructionG;
  1922. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
  1923. lpState->dwArg[0] = hTexture;
  1924. lpState++;
  1925. lpInstructionG = (LPD3DINSTRUCTION)lpState;
  1926. lpwTriCount = (&lpInstructionG->wCount);
  1927. lpInstructionG->bOpcode = D3DOP_TRIANGLE;
  1928. lpInstructionG->bSize = sizeof(D3DTRIANGLE);
  1929. lpInstructionG->wCount = 0;
  1930. lpInstructionG++;
  1931. }
  1932. lpTriangle = (LPD3DTRIANGLE)lpInstructionG;
  1933. lpTriangle->wV1 = GVCnt;
  1934. lpTriangle->wV2 = GVCnt+1;
  1935. lpTriangle->wV3 = GVCnt+2;
  1936. lpTriangle->wFlags = 0;
  1937. lpTriangle++;
  1938. *lpwTriCount = (*lpwTriCount) + 1;
  1939. lpInstructionG = (LPD3DINSTRUCTION)lpTriangle;
  1940. GVCnt+=3;
  1941. }
  1942. void _RenderObject(int x, int y)
  1943. {
  1944. int ob = OMap[y][x];
  1945. if (!MObjects[ob].model) {
  1946. //return;
  1947. wsprintf(logt,"Incorrect model at [%d][%d]!", x, y);
  1948. DoHalt(logt);
  1949. }
  1950. //int mlight = -(RandomMap[y & 31][x & 31] >> 5) + (LMap[y][x]>>1) + 96;
  1951. int FI = (FMap[y][x] >> 2) & 3;
  1952. float fi = CameraAlpha + (float)(FI * 2.f*pi / 4.f);
  1953. int mlight;
  1954. if (MObjects[ob].info.flags & ofDEFLIGHT)
  1955. mlight = MObjects[ob].info.DefLight; else
  1956. if (MObjects[ob].info.flags & ofGRNDLIGHT)
  1957. {
  1958. mlight = 128;
  1959. CalcModelGroundLight(MObjects[ob].model, x*256+128, y*256+128, FI);
  1960. FI = 0;
  1961. }
  1962. else
  1963. mlight = -(RandomMap[y & 31][x & 31] >> 5) + (LMap[y][x]>>1) + 96;
  1964. if (mlight >192) mlight =192;
  1965. if (mlight < 64) mlight = 64;
  1966. v[0].x = x*256+128 - CameraX;
  1967. v[0].z = y*256+128 - CameraZ;
  1968. v[0].y = (float)(HMapO[y][x]) * ctHScale - CameraY;
  1969. float zs = VectorLength(v[0]);
  1970. //if (v[0].y + MObjects[ob].info.YHi < (int)(HMap[y][x]+HMap[y+1][x+1]) / 2 * ctHScale - CameraY) return;
  1971. CalcFogLevel_Gradient(v[0]);
  1972. v[0] = RotateVector(v[0]);
  1973. GlassL = 0;
  1974. if (zs > 256 * (ctViewR-8))
  1975. GlassL=min(255,(int)(zs - 256 * (ctViewR-8)) / 4);
  1976. if (GlassL==255) return;
  1977. if (MObjects[ob].info.flags & ofANIMATED)
  1978. if (MObjects[ob].info.LastAniTime!=RealTime) {
  1979. MObjects[ob].info.LastAniTime=RealTime;
  1980. CreateMorphedObject(MObjects[ob].model,
  1981. MObjects[ob].vtl,
  1982. RealTime % MObjects[ob].vtl.AniTime);
  1983. }
  1984. if (MObjects[ob].info.flags & ofNOBMP) zs = 0;
  1985. /*
  1986. if (!NeedWater && zs>ctViewRM*256 && zs<(ctViewRM+1)*256) {
  1987. GlassL = 255-(int)(zs - ctViewRM*256);
  1988. RenderBMPModel(&MObjects[ob].bmpmodel, v[0].x, v[0].y, v[0].z, mlight-32);
  1989. GlassL=255-GlassL;
  1990. RenderModel(MObjects[ob].model, v[0].x, v[0].y, v[0].z, mlight, FI, fi, CameraBeta);
  1991. } else */
  1992. if (zs>ctViewRM*256)
  1993. RenderBMPModel(&MObjects[ob].bmpmodel, v[0].x, v[0].y, v[0].z, mlight-16);
  1994. else
  1995. if (v[0].z<-256*8)
  1996. RenderModel(MObjects[ob].model, v[0].x, v[0].y, v[0].z, mlight, FI, fi, CameraBeta);
  1997. else
  1998. RenderModelClip(MObjects[ob].model, v[0].x, v[0].y, v[0].z, mlight, FI, fi, CameraBeta);
  1999. }
  2000. void RenderObject(int x, int y)
  2001. {
  2002. if (OMap[y][x]==255) return;
  2003. if (!MODELS) return;
  2004. if (ORLCount>2000) return;
  2005. ORList[ORLCount].x = x;
  2006. ORList[ORLCount].y = y;
  2007. ORLCount++;
  2008. }
  2009. void RenderModelsList()
  2010. {
  2011. d3dEndBufferG(FALSE);
  2012. for (int o=0; o<ORLCount; o++)
  2013. _RenderObject(ORList[o].x, ORList[o].y);
  2014. ORLCount=0;
  2015. d3dEndBufferG(TRUE);
  2016. }
  2017. void ProcessMap(int x, int y, int r)
  2018. {
  2019. //WATERREVERSE = FALSE;
  2020. if (x>=ctMapSize-1 || y>=ctMapSize-1 ||
  2021. x<0 || y<0) return;
  2022. float BackR = BackViewR;
  2023. if (OMap[y][x]!=255) BackR+=MObjects[OMap[y][x]].info.BoundR;
  2024. ev[0] = VMap[y-CCY+128][x-CCX+128];
  2025. if (ev[0].v.z>BackR) return;
  2026. int t1 = TMap1[y][x];
  2027. ReverseOn = (FMap[y][x] & fmReverse);
  2028. TDirection = (FMap[y][x] & 3);
  2029. x = x - CCX + 128;
  2030. y = y - CCY + 128;
  2031. ev[1] = VMap[y][x+1];
  2032. if (ReverseOn) ev[2] = VMap[y+1][x];
  2033. else ev[2] = VMap[y+1][x+1];
  2034. float xx = (ev[0].v.x + VMap[y+1][x+1].v.x) / 2;
  2035. float yy = (ev[0].v.y + VMap[y+1][x+1].v.y) / 2;
  2036. float zz = (ev[0].v.z + VMap[y+1][x+1].v.z) / 2;
  2037. if ( fabs(xx*FOVK) > -zz + BackR) return;
  2038. zs = (int)sqrt( xx*xx + zz*zz + yy*yy);
  2039. if (MIPMAP && (zs > 256 * 10 && t1 || LOWRESTX)) d3dSetTexture(Textures[t1]->DataB, 64, 64);
  2040. else d3dSetTexture(Textures[t1]->DataA, 128, 128);
  2041. if (r>8) DrawTPlane(FALSE);
  2042. else DrawTPlaneClip(FALSE);
  2043. if (ReverseOn) { ev[0] = ev[2]; ev[2] = VMap[y+1][x+1]; }
  2044. else { ev[1] = ev[2]; ev[2] = VMap[y+1][x]; }
  2045. if (r>8) DrawTPlane(TRUE);
  2046. else DrawTPlaneClip(TRUE);
  2047. x = x + CCX - 128;
  2048. y = y + CCY - 128;
  2049. if (OMap[y][x]==255) return;
  2050. if (zz<BackR)
  2051. RenderObject(x, y);
  2052. }
  2053. void ProcessMap2(int x, int y, int r)
  2054. {
  2055. //WATERREVERSE = FALSE;
  2056. if (x>=ctMapSize-1 || y>=ctMapSize-1 ||
  2057. x<0 || y<0) return;
  2058. ev[0] = VMap[y-CCY+128][x-CCX+128];
  2059. if (ev[0].v.z>BackViewR) return;
  2060. int t1 = TMap2[y][x];
  2061. TDirection = ((FMap[y][x]>>8) & 3);
  2062. ReverseOn = FALSE;
  2063. x = x - CCX + 128;
  2064. y = y - CCY + 128;
  2065. ev[1] = VMap[y][x+2];
  2066. if (ReverseOn) ev[2] = VMap[y+2][x];
  2067. else ev[2] = VMap[y+2][x+2];
  2068. float xx = (ev[0].v.x + VMap[y+2][x+2].v.x) / 2;
  2069. float yy = (ev[0].v.y + VMap[y+2][x+2].v.y) / 2;
  2070. float zz = (ev[0].v.z + VMap[y+2][x+2].v.z) / 2;
  2071. if ( fabs(xx*FOVK) > -zz + BackViewR) return;
  2072. zs = (int)sqrt( xx*xx + zz*zz + yy*yy);
  2073. if (zs>ctViewR*256) return;
  2074. d3dSetTexture(Textures[t1]->DataB, 64, 64);
  2075. DrawTPlane(FALSE);
  2076. if (ReverseOn) { ev[0] = ev[2]; ev[2] = VMap[y+2][x+2]; }
  2077. else { ev[1] = ev[2]; ev[2] = VMap[y+2][x]; }
  2078. DrawTPlane(TRUE);
  2079. x = x + CCX - 128;
  2080. y = y + CCY - 128;
  2081. RenderObject(x , y);
  2082. RenderObject(x+1, y);
  2083. RenderObject(x , y+1);
  2084. RenderObject(x+1, y+1);
  2085. }
  2086. void ProcessMapW(int x, int y, int r)
  2087. {
  2088. if (!( (FMap[y ][x ] & fmWaterA) &&
  2089. (FMap[y ][x+1] & fmWaterA) &&
  2090. (FMap[y+1][x ] & fmWaterA) &&
  2091. (FMap[y+1][x+1] & fmWaterA) )) return;
  2092. WATERREVERSE = TRUE;
  2093. int t1 = WaterList[ WMap[y][x] ].tindex;
  2094. ev[0] = VMap2[y-CCY+128][x-CCX+128];
  2095. if (ev[0].v.z>BackViewR) return;
  2096. ReverseOn = FALSE;
  2097. TDirection = 0;
  2098. x = x - CCX + 128;
  2099. y = y - CCY + 128;
  2100. ev[1] = VMap2[y][x+1];
  2101. ev[2] = VMap2[y+1][x+1];
  2102. float xx = (ev[0].v.x + VMap2[y+1][x+1].v.x) / 2;
  2103. float yy = (ev[0].v.y + VMap2[y+1][x+1].v.y) / 2;
  2104. float zz = (ev[0].v.z + VMap2[y+1][x+1].v.z) / 2;
  2105. if ( fabs(xx*FOVK) > -zz + BackViewR) return;
  2106. zs = (int)sqrt( xx*xx + zz*zz + yy*yy);
  2107. if (zs > ctViewR*256) return;
  2108. if (MIPMAP && (zs > 256 * 10 && t1 || LOWRESTX)) d3dSetTexture(Textures[t1]->DataB, 64, 64);
  2109. else d3dSetTexture(Textures[t1]->DataA, 128, 128);
  2110. if (r>8) DrawTPlaneW(FALSE);
  2111. else DrawTPlaneClip(FALSE);
  2112. ev[1] = ev[2]; ev[2] = VMap2[y+1][x];
  2113. if (r>8) DrawTPlaneW(TRUE);
  2114. else DrawTPlaneClip(TRUE);
  2115. WATERREVERSE = FALSE;
  2116. }
  2117. void ProcessMapW2(int x, int y, int r)
  2118. {
  2119. if (!( (FMap[y ][x ] & fmWaterA) &&
  2120. (FMap[y ][x+2] & fmWaterA) &&
  2121. (FMap[y+2][x ] & fmWaterA) &&
  2122. (FMap[y+2][x+2] & fmWaterA) )) return;
  2123. int t1 = WaterList[ WMap[y][x] ].tindex;
  2124. ev[0] = VMap2[y-CCY+128][x-CCX+128];
  2125. if (ev[0].v.z>BackViewR) return;
  2126. //WATERREVERSE = TRUE;
  2127. ReverseOn = FALSE;
  2128. TDirection = 0;
  2129. x = x - CCX + 128;
  2130. y = y - CCY + 128;
  2131. ev[1] = VMap2[y][x+2];
  2132. ev[2] = VMap2[y+2][x+2];
  2133. float xx = (ev[0].v.x + VMap2[y+2][x+2].v.x) / 2;
  2134. float yy = (ev[0].v.y + VMap2[y+2][x+2].v.y) / 2;
  2135. float zz = (ev[0].v.z + VMap2[y+2][x+2].v.z) / 2;
  2136. if ( fabs(xx*FOVK) > -zz + BackViewR) return;
  2137. zs = (int)sqrt( xx*xx + zz*zz + yy*yy);
  2138. if (zs > ctViewR*256) return;
  2139. d3dSetTexture(Textures[t1]->DataB, 64, 64);
  2140. DrawTPlaneW(FALSE);
  2141. ev[1] = ev[2]; ev[2] = VMap2[y+2][x];
  2142. DrawTPlaneW(TRUE);
  2143. }
  2144. void RenderGround()
  2145. {
  2146. for (r=ctViewR; r>=ctViewR1; r-=2) {
  2147. for (int x=r; x>0; x-=2) {
  2148. ProcessMap2(CCX-x, CCY+r, r);
  2149. ProcessMap2(CCX+x, CCY+r, r);
  2150. ProcessMap2(CCX-x, CCY-r, r);
  2151. ProcessMap2(CCX+x, CCY-r, r);
  2152. }
  2153. ProcessMap2(CCX, CCY-r, r);
  2154. ProcessMap2(CCX, CCY+r, r);
  2155. for (int y=r-2; y>0; y-=2) {
  2156. ProcessMap2(CCX+r, CCY-y, r);
  2157. ProcessMap2(CCX+r, CCY+y, r);
  2158. ProcessMap2(CCX-r, CCY+y, r);
  2159. ProcessMap2(CCX-r, CCY-y, r);
  2160. }
  2161. ProcessMap2(CCX-r, CCY, r);
  2162. ProcessMap2(CCX+r, CCY, r);
  2163. }
  2164. r = ctViewR1-1;
  2165. for (int x=r; x>-r; x--) {
  2166. ProcessMap(CCX+r, CCY+x, r);
  2167. ProcessMap(CCX+x, CCY+r, r);
  2168. }
  2169. for (r=ctViewR1-2; r>0; r--) {
  2170. for (int x=r; x>0; x--) {
  2171. ProcessMap(CCX-x, CCY+r, r);
  2172. ProcessMap(CCX+x, CCY+r, r);
  2173. ProcessMap(CCX-x, CCY-r, r);
  2174. ProcessMap(CCX+x, CCY-r, r);
  2175. }
  2176. ProcessMap(CCX, CCY-r, r);
  2177. ProcessMap(CCX, CCY+r, r);
  2178. for (int y=r-1; y>0; y--) {
  2179. ProcessMap(CCX+r, CCY-y, r);
  2180. ProcessMap(CCX+r, CCY+y, r);
  2181. ProcessMap(CCX-r, CCY+y, r);
  2182. ProcessMap(CCX-r, CCY-y, r);
  2183. }
  2184. ProcessMap(CCX-r, CCY, r);
  2185. ProcessMap(CCX+r, CCY, r);
  2186. }
  2187. ProcessMap(CCX, CCY, 0);
  2188. }
  2189. void RenderWCircles()
  2190. {
  2191. TWCircle *wptr;
  2192. Vector3d rpos;
  2193. for (int c=0; c<WCCount; c++) {
  2194. wptr = &WCircles[c];
  2195. rpos.x = wptr->pos.x - CameraX;
  2196. rpos.y = wptr->pos.y - CameraY;
  2197. rpos.z = wptr->pos.z - CameraZ;
  2198. float r = (float)max( fabs(rpos.x), fabs(rpos.z) );
  2199. int ri = -1 + (int)(r / 256.f + 0.4f);
  2200. if (ri < 0) ri = 0;
  2201. if (ri > ctViewR) continue;
  2202. rpos = RotateVector(rpos);
  2203. if ( rpos.z > BackViewR) continue;
  2204. if ( fabs(rpos.x) > -rpos.z + BackViewR ) continue;
  2205. if ( fabs(rpos.y) > -rpos.z + BackViewR ) continue;
  2206. GlassL = 255 - (2000-wptr->FTime) / 38;
  2207. CreateMorphedModel(WCircleModel.mptr, &WCircleModel.Animation[0], (int)(wptr->FTime), wptr->scale);
  2208. if ( fabs(rpos.z) + fabs(rpos.x) < 1000)
  2209. RenderModelClip(WCircleModel.mptr,
  2210. rpos.x, rpos.y, rpos.z, 250, 0, 0, CameraBeta);
  2211. else
  2212. RenderModel(WCircleModel.mptr,
  2213. rpos.x, rpos.y, rpos.z, 250, 0, 0, CameraBeta);
  2214. }
  2215. GlassL = 0;
  2216. }
  2217. void RenderWater()
  2218. {
  2219. SetRenderStates(FALSE, D3DBLEND_INVSRCALPHA);
  2220. for (int r=ctViewR; r>=ctViewR1; r-=2) {
  2221. for (int x=r; x>0; x-=2) {
  2222. ProcessMapW2(CCX-x, CCY+r, r);
  2223. ProcessMapW2(CCX+x, CCY+r, r);
  2224. ProcessMapW2(CCX-x, CCY-r, r);
  2225. ProcessMapW2(CCX+x, CCY-r, r);
  2226. }
  2227. ProcessMapW2(CCX, CCY-r, r);
  2228. ProcessMapW2(CCX, CCY+r, r);
  2229. for (int y=r-2; y>0; y-=2) {
  2230. ProcessMapW2(CCX+r, CCY-y, r);
  2231. ProcessMapW2(CCX+r, CCY+y, r);
  2232. ProcessMapW2(CCX-r, CCY+y, r);
  2233. ProcessMapW2(CCX-r, CCY-y, r);
  2234. }
  2235. ProcessMapW2(CCX-r, CCY, r);
  2236. ProcessMapW2(CCX+r, CCY, r);
  2237. }
  2238. for (int y=-ctViewR1+2; y<ctViewR1; y++)
  2239. for (int x=-ctViewR1+2; x<ctViewR1; x++)
  2240. ProcessMapW(CCX+x, CCY+y, max(abs(x), abs(y)));
  2241. d3dEndBufferG(FALSE);
  2242. FogYBase = 0;
  2243. SetRenderStates(FALSE, D3DBLEND_ONE);
  2244. RenderWCircles();
  2245. SetRenderStates(TRUE, D3DBLEND_INVSRCALPHA);
  2246. }
  2247. void RenderCircle(float cx, float cy, float z, float _R, DWORD RGBA, DWORD RGBA2)
  2248. {
  2249. /*
  2250. RGBA = (RGBA & 0xFF00FF00) + ((RGBA & 0x000000FF)<<16) + ((RGBA & 0x00FF0000)>>16);
  2251. RGBA2= (RGBA2 & 0xFF00FF00) + ((RGBA2 & 0x000000FF)<<16) + ((RGBA2 & 0x00FF0000)>>16);
  2252. */
  2253. float R = (float)((int)( _R*16.f)) / 16.f;
  2254. float R2 = (float)((int)(0.65f*_R*16.f)) / 16.f;
  2255. float sz = _ZSCALE / z;
  2256. lpVertex->sx = cx;
  2257. lpVertex->sy = cy;
  2258. lpVertex->color = RGBA;
  2259. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2260. lpVertex->sx = cx;
  2261. lpVertex->sy = cy-R;
  2262. lpVertex->color = RGBA2;
  2263. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2264. lpVertex->sx = cx+R2;
  2265. lpVertex->sy = cy-R2;
  2266. lpVertex->color = RGBA2;
  2267. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2268. //================ 1
  2269. lpVertex->sx = cx;
  2270. lpVertex->sy = cy;
  2271. lpVertex->color = RGBA;
  2272. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2273. lpVertex->sx = cx+R2;
  2274. lpVertex->sy = cy-R2;
  2275. lpVertex->color = RGBA2;
  2276. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2277. lpVertex->sx = cx+R;
  2278. lpVertex->sy = cy;
  2279. lpVertex->color = RGBA2;
  2280. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2281. //================ 2
  2282. lpVertex->sx = cx;
  2283. lpVertex->sy = cy;
  2284. lpVertex->color = RGBA;
  2285. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2286. lpVertex->sx = cx+R;
  2287. lpVertex->sy = cy;
  2288. lpVertex->color = RGBA2;
  2289. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2290. lpVertex->sx = cx+R2;
  2291. lpVertex->sy = cy+R2;
  2292. lpVertex->color = RGBA2;
  2293. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2294. //================ 3
  2295. lpVertex->sx = cx;
  2296. lpVertex->sy = cy;
  2297. lpVertex->color = RGBA;
  2298. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2299. lpVertex->sx = cx+R2;
  2300. lpVertex->sy = cy+R2;
  2301. lpVertex->color = RGBA2;
  2302. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2303. lpVertex->sx = cx;
  2304. lpVertex->sy = cy+R;
  2305. lpVertex->color = RGBA2;
  2306. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2307. //================ 4
  2308. lpVertex->sx = cx;
  2309. lpVertex->sy = cy;
  2310. lpVertex->color = RGBA;
  2311. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2312. lpVertex->sx = cx;
  2313. lpVertex->sy = cy+R;
  2314. lpVertex->color = RGBA2;
  2315. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2316. lpVertex->sx = cx-R2;
  2317. lpVertex->sy = cy+R2;
  2318. lpVertex->color = RGBA2;
  2319. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2320. //================ 5
  2321. lpVertex->sx = cx;
  2322. lpVertex->sy = cy;
  2323. lpVertex->color = RGBA;
  2324. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2325. lpVertex->sx = cx-R2;
  2326. lpVertex->sy = cy+R2;
  2327. lpVertex->color = RGBA2;
  2328. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2329. lpVertex->sx = cx-R;
  2330. lpVertex->sy = cy;
  2331. lpVertex->color = RGBA2;
  2332. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2333. //================ 6
  2334. lpVertex->sx = cx;
  2335. lpVertex->sy = cy;
  2336. lpVertex->color = RGBA;
  2337. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2338. lpVertex->sx = cx-R;
  2339. lpVertex->sy = cy;
  2340. lpVertex->color = RGBA2;
  2341. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2342. lpVertex->sx = cx-R2;
  2343. lpVertex->sy = cy-R2;
  2344. lpVertex->color = RGBA2;
  2345. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2346. //================ 7
  2347. lpVertex->sx = cx;
  2348. lpVertex->sy = cy;
  2349. lpVertex->color = RGBA;
  2350. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2351. lpVertex->sx = cx-R2;
  2352. lpVertex->sy = cy-R2;
  2353. lpVertex->color = RGBA2;
  2354. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2355. lpVertex->sx = cx;
  2356. lpVertex->sy = cy-R;
  2357. lpVertex->color = RGBA2;
  2358. lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
  2359. //================ 8
  2360. }
  2361. void BuildTreeNoSort()
  2362. {
  2363. Vector2di v[3];
  2364. Current = -1;
  2365. int LastFace = -1;
  2366. TFace* fptr;
  2367. int sg;
  2368. for (int f=0; f<mptr->FCount; f++)
  2369. {
  2370. fptr = &mptr->gFace[f];
  2371. v[0] = gScrp[fptr->v1];
  2372. v[1] = gScrp[fptr->v2];
  2373. v[2] = gScrp[fptr->v3];
  2374. if (v[0].x == 0xFFFFFF) continue;
  2375. if (v[1].x == 0xFFFFFF) continue;
  2376. if (v[2].x == 0xFFFFFF) continue;
  2377. if (fptr->Flags & (sfDarkBack+sfNeedVC)) {
  2378. sg = (v[1].x-v[0].x)*(v[2].y-v[1].y) - (v[1].y-v[0].y)*(v[2].x-v[1].x);
  2379. if (sg<0) continue;
  2380. }
  2381. fptr->Next=-1;
  2382. if (Current==-1) { Current=f; LastFace = f; } else
  2383. { mptr->gFace[LastFace].Next=f; LastFace=f; }
  2384. }
  2385. }
  2386. int BuildTreeClipNoSort()
  2387. {
  2388. Current = -1;
  2389. int fc = 0;
  2390. int LastFace = -1;
  2391. TFace* fptr;
  2392. for (int f=0; f<mptr->FCount; f++)
  2393. {
  2394. fptr = &mptr->gFace[f];
  2395. if (fptr->Flags & (sfDarkBack + sfNeedVC) ) {
  2396. MulVectorsVect(SubVectors(rVertex[fptr->v2], rVertex[fptr->v1]), SubVectors(rVertex[fptr->v3], rVertex[fptr->v1]), nv);
  2397. if (nv.x*rVertex[fptr->v1].x + nv.y*rVertex[fptr->v1].y + nv.z*rVertex[fptr->v1].z<0) continue;
  2398. }
  2399. fc++;
  2400. fptr->Next=-1;
  2401. if (Current==-1) { Current=f; LastFace = f; } else
  2402. { mptr->gFace[LastFace].Next=f; LastFace=f; }
  2403. }
  2404. return fc;
  2405. }
  2406. void RenderBMPModel(TBMPModel* mptr, float x0, float y0, float z0, int light)
  2407. {
  2408. if (fabs(y0) > -(z0-256*6)) return;
  2409. int minx = 10241024;
  2410. int maxx =-10241024;
  2411. int miny = 10241024;
  2412. int maxy =-10241024;
  2413. BOOL FOGACTIVE = (FOGON && (FogYBase>0));
  2414. for (int s=0; s<4; s++) {
  2415. if (FOGACTIVE) {
  2416. vFogT[s] = 255-(int) (FogYBase + mptr->gVertex[s].y * FogYGrad);
  2417. if (vFogT[s]<0 ) vFogT[s] = 0;
  2418. if (vFogT[s]>255) vFogT[s]=255;
  2419. vFogT[s]<<=24;
  2420. } else vFogT[s]=255<<24;
  2421. rVertex[s].x = mptr->gVertex[s].x + x0;
  2422. rVertex[s].y = mptr->gVertex[s].y * cb + y0;
  2423. rVertex[s].z = mptr->gVertex[s].y * sb + z0;
  2424. if (rVertex[s].z<-256) {
  2425. gScrp[s].x = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
  2426. gScrp[s].y = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
  2427. } else return;
  2428. if (gScrp[s].x > maxx) maxx = gScrp[s].x;
  2429. if (gScrp[s].x < minx) minx = gScrp[s].x;
  2430. if (gScrp[s].y > maxy) maxy = gScrp[s].y;
  2431. if (gScrp[s].y < miny) miny = gScrp[s].y;
  2432. }
  2433. if (minx == 10241024) return;
  2434. if (minx>WinW || maxx<0 || miny>WinH || maxy<0) return;
  2435. int argb = light * 0x00010101 + ((255-GlassL)<<24);
  2436. float d = (float) sqrt(x0*x0 + y0*y0 + z0*z0);
  2437. d3dSetTexture(mptr->lpTexture, 128, 128);
  2438. //d3dStartBuffer();
  2439. if (!lpVertexG)
  2440. d3dStartBufferGBMP();
  2441. if (GVCnt>380) {
  2442. if (lpVertexG) d3dEndBufferG(TRUE);
  2443. d3dStartBufferGBMP();
  2444. }
  2445. lpVertexG->sx = (float)gScrp[0].x;
  2446. lpVertexG->sy = (float)gScrp[0].y;
  2447. lpVertexG->sz = _ZSCALE / rVertex[0].z;
  2448. lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
  2449. lpVertexG->color = argb;
  2450. lpVertexG->specular = vFogT[0];
  2451. lpVertexG->tu = (float)(0.0f);
  2452. lpVertexG->tv = (float)(0.0f);
  2453. lpVertexG++;
  2454. lpVertexG->sx = (float)gScrp[1].x;
  2455. lpVertexG->sy = (float)gScrp[1].y;
  2456. lpVertexG->sz = _ZSCALE / rVertex[1].z;
  2457. lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
  2458. lpVertexG->color = argb;
  2459. lpVertexG->specular = vFogT[1];
  2460. lpVertexG->tu = (float)(0.995f);
  2461. lpVertexG->tv = (float)(0.0f);
  2462. lpVertexG++;
  2463. lpVertexG->sx = (float)gScrp[2].x;
  2464. lpVertexG->sy = (float)gScrp[2].y;
  2465. lpVertexG->sz = _ZSCALE / rVertex[2].z;
  2466. lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
  2467. lpVertexG->color = argb;
  2468. lpVertexG->specular = vFogT[2];
  2469. lpVertexG->tu = (float)(0.995f);
  2470. lpVertexG->tv = (float)(0.995f);
  2471. lpVertexG++;
  2472. //=========//
  2473. lpVertexG->sx = (float)gScrp[0].x;
  2474. lpVertexG->sy = (float)gScrp[0].y;
  2475. lpVertexG->sz = _ZSCALE / rVertex[0].z;
  2476. lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
  2477. lpVertexG->color = argb;
  2478. lpVertexG->specular = vFogT[0];
  2479. lpVertexG->tu = (float)(0.0f);
  2480. lpVertexG->tv = (float)(0.0f);
  2481. lpVertexG++;
  2482. lpVertexG->sx = (float)gScrp[2].x;
  2483. lpVertexG->sy = (float)gScrp[2].y;
  2484. lpVertexG->sz = _ZSCALE / rVertex[2].z;
  2485. lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
  2486. lpVertexG->color = argb;
  2487. lpVertexG->specular = vFogT[2];
  2488. lpVertexG->tu = (float)(0.995f);
  2489. lpVertexG->tv = (float)(0.995f);
  2490. lpVertexG++;
  2491. lpVertexG->sx = (float)gScrp[3].x;
  2492. lpVertexG->sy = (float)gScrp[3].y;
  2493. lpVertexG->sz = _ZSCALE / rVertex[3].z;
  2494. lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
  2495. lpVertexG->color = argb;
  2496. lpVertexG->specular = vFogT[3];
  2497. lpVertexG->tu = (float)(0.0f);
  2498. lpVertexG->tv = (float)(0.995f);
  2499. lpVertexG++;
  2500. //d3dFlushBuffer(0, 2);
  2501. if (hGTexture!=hTexture) {
  2502. hGTexture=hTexture;
  2503. lpInstructionG->bOpcode = D3DOP_STATERENDER;
  2504. lpInstructionG->bSize = sizeof(D3DSTATE);
  2505. lpInstructionG->wCount = 1;
  2506. lpInstructionG++;
  2507. lpState = (LPD3DSTATE)lpInstructionG;
  2508. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
  2509. lpState->dwArg[0] = hTexture;
  2510. lpState++;
  2511. lpInstructionG = (LPD3DINSTRUCTION)lpState;
  2512. lpwTriCount = (&lpInstructionG->wCount);
  2513. lpInstructionG->bOpcode = D3DOP_TRIANGLE;
  2514. lpInstructionG->bSize = sizeof(D3DTRIANGLE);
  2515. lpInstructionG->wCount = 0;
  2516. lpInstructionG++;
  2517. }
  2518. lpTriangle = (LPD3DTRIANGLE)lpInstructionG;
  2519. lpTriangle->wV1 = GVCnt;
  2520. lpTriangle->wV2 = GVCnt+1;
  2521. lpTriangle->wV3 = GVCnt+2;
  2522. lpTriangle->wFlags = 0;
  2523. lpTriangle++;
  2524. lpTriangle->wV1 = GVCnt+3;
  2525. lpTriangle->wV2 = GVCnt+4;
  2526. lpTriangle->wV3 = GVCnt+5;
  2527. lpTriangle->wFlags = 0;
  2528. lpTriangle++;
  2529. *lpwTriCount = (*lpwTriCount) + 2;
  2530. lpInstructionG = (LPD3DINSTRUCTION)lpTriangle;
  2531. GVCnt+=6;
  2532. }
  2533. void RenderModel(TModel* _mptr, float x0, float y0, float z0, int light, int VT, float al, float bt)
  2534. {
  2535. int f;
  2536. if (fabs(y0) > -(z0-256*6)) return;
  2537. mptr = _mptr;
  2538. float ca = (float)cos(al);
  2539. float sa = (float)sin(al);
  2540. float cb = (float)cos(bt);
  2541. float sb = (float)sin(bt);
  2542. int minx = 10241024;
  2543. int maxx =-10241024;
  2544. int miny = 10241024;
  2545. int maxy =-10241024;
  2546. BOOL FOGACTIVE = (FOGON && (FogYBase>0));
  2547. int alphamask = (255-GlassL)<<24;
  2548. int ml = light;
  2549. TPoint3d p;
  2550. for (int s=0; s<mptr->VCount; s++) {
  2551. p = mptr->gVertex[s];
  2552. if (FOGACTIVE) {
  2553. vFogT[s] = 255-(int)(FogYBase + p.y * FogYGrad);
  2554. if (vFogT[s]<5 ) vFogT[s] = 5;
  2555. if (vFogT[s]>255) vFogT[s]=255;
  2556. vFogT[s]<<=24;
  2557. } else vFogT[s] = 255<<24;
  2558. rVertex[s].x = (p.x * ca + p.z * sa) + x0;
  2559. float vz = p.z * ca - p.x * sa;
  2560. rVertex[s].y = (p.y * cb - vz * sb) + y0;
  2561. rVertex[s].z = (vz * cb + p.y * sb) + z0;
  2562. if (rVertex[s].z<-64) {
  2563. gScrp[s].x = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
  2564. gScrp[s].y = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
  2565. } else gScrp[s].x = 0xFFFFFF;
  2566. if (gScrp[s].x > maxx) maxx = gScrp[s].x;
  2567. if (gScrp[s].x < minx) minx = gScrp[s].x;
  2568. if (gScrp[s].y > maxy) maxy = gScrp[s].y;
  2569. if (gScrp[s].y < miny) miny = gScrp[s].y;
  2570. }
  2571. if (minx == 10241024) return;
  2572. if (minx>WinW || maxx<0 || miny>WinH || maxy<0) return;
  2573. BuildTreeNoSort();
  2574. float d = (float) sqrt(x0*x0 + y0*y0 + z0*z0);
  2575. if (LOWRESTX) d = 14*256;
  2576. if (MIPMAP && (d > 12*256)) d3dSetTexture(mptr->lpTexture2, 128, 128);
  2577. else d3dSetTexture(mptr->lpTexture, 256, 256);
  2578. int PrevOpacity = 0;
  2579. int NewOpacity = 0;
  2580. int PrevTransparent = 0;
  2581. int NewTransparent = 0;
  2582. d3dStartBuffer();
  2583. int fproc1 = 0;
  2584. int fproc2 = 0;
  2585. f = Current;
  2586. BOOL CKEY = FALSE;
  2587. while( f!=-1 ) {
  2588. TFace *fptr = & mptr->gFace[f];
  2589. f = mptr->gFace[f].Next;
  2590. /*
  2591. if (minx<0)
  2592. if (gScrp[fptr->v1].x <0 && gScrp[fptr->v2].x<0 && gScrp[fptr->v3].x<0) continue;
  2593. if (maxx>WinW)
  2594. if (gScrp[fptr->v1].x >WinW && gScrp[fptr->v2].x>WinW && gScrp[fptr->v3].x>WinW) continue;
  2595. */
  2596. if (fptr->Flags & (sfOpacity | sfTransparent)) fproc2++; else fproc1++;
  2597. int _ml = ml + mptr->VLight[VT][fptr->v1];
  2598. lpVertex->sx = (float)gScrp[fptr->v1].x;
  2599. lpVertex->sy = (float)gScrp[fptr->v1].y;
  2600. lpVertex->sz = _ZSCALE / rVertex[fptr->v1].z;
  2601. lpVertex->rhw = 1.f;
  2602. lpVertex->color = _ml * 0x00010101 | alphamask;
  2603. lpVertex->specular = vFogT[fptr->v1];
  2604. lpVertex->tu = (float)(fptr->tax);
  2605. lpVertex->tv = (float)(fptr->tay);
  2606. lpVertex++;
  2607. _ml = ml + mptr->VLight[VT][fptr->v2];
  2608. lpVertex->sx = (float)gScrp[fptr->v2].x;
  2609. lpVertex->sy = (float)gScrp[fptr->v2].y;
  2610. lpVertex->sz = _ZSCALE / rVertex[fptr->v2].z;
  2611. lpVertex->rhw = 1.f;
  2612. lpVertex->color = _ml * 0x00010101 | alphamask;;
  2613. lpVertex->specular = vFogT[fptr->v2];
  2614. lpVertex->tu = (float)(fptr->tbx);
  2615. lpVertex->tv = (float)(fptr->tby);
  2616. lpVertex++;
  2617. _ml = ml + mptr->VLight[VT][fptr->v3];
  2618. lpVertex->sx = (float)gScrp[fptr->v3].x;
  2619. lpVertex->sy = (float)gScrp[fptr->v3].y;
  2620. lpVertex->sz = _ZSCALE / rVertex[fptr->v3].z;
  2621. lpVertex->rhw = 1.f;
  2622. lpVertex->color = _ml * 0x00010101 | alphamask;;
  2623. lpVertex->specular = vFogT[fptr->v3];
  2624. lpVertex->tu = (float)(fptr->tcx);
  2625. lpVertex->tv = (float)(fptr->tcy);
  2626. lpVertex++;
  2627. //f = mptr->gFace[f].Next;
  2628. }
  2629. d3dFlushBuffer(fproc1, fproc2);
  2630. }
  2631. void RenderShadowClip(TModel* _mptr,
  2632. float xm0, float ym0, float zm0,
  2633. float x0, float y0, float z0, float cal, float al, float bt)
  2634. {
  2635. int f,CMASK,j;
  2636. mptr = _mptr;
  2637. float cla = (float)cos(cal);
  2638. float sla = (float)sin(cal);
  2639. float ca = (float)cos(al);
  2640. float sa = (float)sin(al);
  2641. float cb = (float)cos(bt);
  2642. float sb = (float)sin(bt);
  2643. BOOL BL = FALSE;
  2644. for (int s=0; s<mptr->VCount; s++) {
  2645. float mrx = mptr->gVertex[s].x * cla + mptr->gVertex[s].z * sla;
  2646. float mrz = mptr->gVertex[s].z * cla - mptr->gVertex[s].x * sla;
  2647. float shx = mrx + mptr->gVertex[s].y * SunShadowK;
  2648. float shz = mrz + mptr->gVertex[s].y * SunShadowK;
  2649. float shy = GetLandH(shx + xm0, shz + zm0) - ym0;
  2650. rVertex[s].x = (shx * ca + shz * sa) + x0;
  2651. float vz = shz * ca - shx * sa;
  2652. rVertex[s].y = (shy * cb - vz * sb) + y0;
  2653. rVertex[s].z = (vz * cb + shy * sb) + z0;
  2654. if (rVertex[s].z<0) BL=TRUE;
  2655. if (rVertex[s].z>-256) { gScrp[s].x = 0xFFFFFF; gScrp[s].y = 0xFF; }
  2656. else {
  2657. int f = 0;
  2658. int sx = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
  2659. int sy = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
  2660. if (sx>=WinEX) f+=1;
  2661. if (sx<=0 ) f+=2;
  2662. if (sy>=WinEY) f+=4;
  2663. if (sy<=0 ) f+=8;
  2664. gScrp[s].y = f;
  2665. }
  2666. }
  2667. if (!BL) return;
  2668. float d = (float) sqrt(x0*x0 + y0*y0 + z0*z0);
  2669. if (LOWRESTX) d = 14*256;
  2670. if (MIPMAP && (d > 12*256)) d3dSetTexture(mptr->lpTexture2, 128, 128);
  2671. else d3dSetTexture(mptr->lpTexture, 256, 256);
  2672. BuildTreeClipNoSort();
  2673. d3dStartBuffer();
  2674. int fproc1 = 0;
  2675. f = Current;
  2676. while( f!=-1 ) {
  2677. vused = 3;
  2678. TFace *fptr = &mptr->gFace[f];
  2679. CMASK = 0;
  2680. CMASK|=gScrp[fptr->v1].y;
  2681. CMASK|=gScrp[fptr->v2].y;
  2682. CMASK|=gScrp[fptr->v3].y;
  2683. cp[0].ev.v = rVertex[fptr->v1]; cp[0].tx = fptr->tax; cp[0].ty = fptr->tay;
  2684. cp[1].ev.v = rVertex[fptr->v2]; cp[1].tx = fptr->tbx; cp[1].ty = fptr->tby;
  2685. cp[2].ev.v = rVertex[fptr->v3]; cp[2].tx = fptr->tcx; cp[2].ty = fptr->tcy;
  2686. if (CMASK == 0xFF) {
  2687. for (u=0; u<vused; u++) cp[u].ev.v.z+=16.0f;
  2688. for (u=0; u<vused; u++) ClipVector(ClipZ,u);
  2689. for (u=0; u<vused; u++) cp[u].ev.v.z-=16.0f;
  2690. if (vused<3) goto LNEXT;
  2691. }
  2692. if (CMASK & 1) for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) goto LNEXT;
  2693. if (CMASK & 2) for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) goto LNEXT;
  2694. if (CMASK & 4) for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) goto LNEXT;
  2695. if (CMASK & 8) for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) goto LNEXT;
  2696. for (j=0; j<vused-2; j++) {
  2697. u = 0;
  2698. lpVertex->sx = (float)(VideoCX - (int)(cp[u].ev.v.x / cp[u].ev.v.z * CameraW));
  2699. lpVertex->sy = (float)(VideoCY + (int)(cp[u].ev.v.y / cp[u].ev.v.z * CameraH));
  2700. lpVertex->sz = (_ZSCALE-0.5f) / cp[u].ev.v.z;
  2701. lpVertex->rhw = 1.f;
  2702. lpVertex->color = GlassL;
  2703. lpVertex->specular = 0xFF000000;
  2704. lpVertex->tu = 0.f;
  2705. lpVertex->tv = 0.f;
  2706. lpVertex++;
  2707. u = j+1;
  2708. lpVertex->sx = (float)(VideoCX - (int)(cp[u].ev.v.x / cp[u].ev.v.z * CameraW));
  2709. lpVertex->sy = (float)(VideoCY + (int)(cp[u].ev.v.y / cp[u].ev.v.z * CameraH));
  2710. lpVertex->sz = (_ZSCALE-0.5f) / cp[u].ev.v.z;
  2711. lpVertex->rhw = 1.f;
  2712. lpVertex->color = GlassL;
  2713. lpVertex->specular = 0xFF000000;
  2714. lpVertex->tu = 0.f;
  2715. lpVertex->tv = 0.f;
  2716. lpVertex++;
  2717. u = j+2;
  2718. lpVertex->sx = (float)(VideoCX - (int)(cp[u].ev.v.x / cp[u].ev.v.z * CameraW));
  2719. lpVertex->sy = (float)(VideoCY + (int)(cp[u].ev.v.y / cp[u].ev.v.z * CameraH));
  2720. lpVertex->sz = (_ZSCALE-0.5f) / cp[u].ev.v.z;
  2721. lpVertex->rhw = 1.f;
  2722. lpVertex->color = GlassL;
  2723. lpVertex->specular = 0xFF000000;
  2724. lpVertex->tu = 0.f;
  2725. lpVertex->tv = 0.f;
  2726. lpVertex++;
  2727. fproc1++;
  2728. }
  2729. LNEXT:
  2730. f = mptr->gFace[f].Next;
  2731. }
  2732. d3dFlushBuffer(fproc1, 0);
  2733. }
  2734. void RenderModelClip(TModel* _mptr, float x0, float y0, float z0, int light, int VT, float al, float bt)
  2735. {
  2736. int f,CMASK;
  2737. //if (fabs(y0) > -(z0-256*6)) return;
  2738. mptr = _mptr;
  2739. float ca = (float)cos(al);
  2740. float sa = (float)sin(al);
  2741. float cb = (float)cos(bt);
  2742. float sb = (float)sin(bt);
  2743. int flight = (int)light;
  2744. DWORD almask;
  2745. DWORD alphamask = (255-GlassL)<<24;
  2746. BOOL BL = FALSE;
  2747. BOOL FOGACTIVE = (FOGON && (FogYBase>0));
  2748. for (int s=0; s<mptr->VCount; s++) {
  2749. if (FOGACTIVE) {
  2750. vFogT[s] = 255-(int)(FogYBase + mptr->gVertex[s].y * FogYGrad);
  2751. if (vFogT[s]<5 ) vFogT[s] = 5;
  2752. if (vFogT[s]>255) vFogT[s]=255;
  2753. } else vFogT[s] = 255;
  2754. rVertex[s].x = (mptr->gVertex[s].x * ca + mptr->gVertex[s].z * sa) /* * mdlScale */ + x0;
  2755. float vz = mptr->gVertex[s].z * ca - mptr->gVertex[s].x * sa;
  2756. rVertex[s].y = (mptr->gVertex[s].y * cb - vz * sb) /* * mdlScale */ + y0;
  2757. rVertex[s].z = (vz * cb + mptr->gVertex[s].y * sb) /* * mdlScale */ + z0;
  2758. if (rVertex[s].z<0) BL=TRUE;
  2759. if (rVertex[s].z>-256) { gScrp[s].x = 0xFFFFFF; gScrp[s].y = 0xFF; }
  2760. else {
  2761. int f = 0;
  2762. int sx = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
  2763. int sy = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
  2764. if (sx>=WinEX) f+=1;
  2765. if (sx<=0 ) f+=2;
  2766. if (sy>=WinEY) f+=4;
  2767. if (sy<=0 ) f+=8;
  2768. gScrp[s].y = f;
  2769. }
  2770. }
  2771. if (!BL) return;
  2772. if (LOWRESTX) d3dSetTexture(mptr->lpTexture2, 128, 128);
  2773. else d3dSetTexture(mptr->lpTexture, 256, 256);
  2774. BuildTreeClipNoSort();
  2775. d3dStartBuffer();
  2776. f = Current;
  2777. int fproc1 = 0;
  2778. int fproc2 = 0;
  2779. BOOL CKEY = FALSE;
  2780. while( f!=-1 ) {
  2781. vused = 3;
  2782. TFace *fptr = &mptr->gFace[f];
  2783. CMASK = 0;
  2784. CMASK|=gScrp[fptr->v1].y;
  2785. CMASK|=gScrp[fptr->v2].y;
  2786. CMASK|=gScrp[fptr->v3].y;
  2787. cp[0].ev.v = rVertex[fptr->v1]; cp[0].tx = fptr->tax; cp[0].ty = fptr->tay; cp[0].ev.Fog = vFogT[fptr->v1]; cp[0].ev.Light = mptr->VLight[VT][fptr->v1];
  2788. cp[1].ev.v = rVertex[fptr->v2]; cp[1].tx = fptr->tbx; cp[1].ty = fptr->tby; cp[1].ev.Fog = vFogT[fptr->v2]; cp[1].ev.Light = mptr->VLight[VT][fptr->v2];
  2789. cp[2].ev.v = rVertex[fptr->v3]; cp[2].tx = fptr->tcx; cp[2].ty = fptr->tcy; cp[2].ev.Fog = vFogT[fptr->v3]; cp[2].ev.Light = mptr->VLight[VT][fptr->v3];
  2790. {
  2791. for (u=0; u<vused; u++) cp[u].ev.v.z+= 8.0f;
  2792. for (u=0; u<vused; u++) ClipVector(ClipZ,u);
  2793. for (u=0; u<vused; u++) cp[u].ev.v.z-= 8.0f;
  2794. if (vused<3) goto LNEXT;
  2795. }
  2796. if (CMASK & 1) for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) goto LNEXT;
  2797. if (CMASK & 2) for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) goto LNEXT;
  2798. if (CMASK & 4) for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) goto LNEXT;
  2799. if (CMASK & 8) for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) goto LNEXT;
  2800. almask = 0xFF000000;
  2801. if (fptr->Flags & sfTransparent) almask = 0x70000000;
  2802. if (almask > alphamask)
  2803. almask = alphamask;
  2804. for (u=0; u<vused-2; u++) {
  2805. int _flight = flight + cp[0].ev.Light;
  2806. lpVertex->sx = (float)(VideoCX - (int)(cp[0].ev.v.x / cp[0].ev.v.z * CameraW));
  2807. lpVertex->sy = (float)(VideoCY + (int)(cp[0].ev.v.y / cp[0].ev.v.z * CameraH));
  2808. lpVertex->sz = _ZSCALE / cp[0].ev.v.z;
  2809. lpVertex->rhw = lpVertex->sz * _AZSCALE;
  2810. lpVertex->color = _flight * 0x00010101 | almask;
  2811. lpVertex->specular = ((int)cp[0].ev.Fog)<<24;
  2812. lpVertex->tu = (float)(cp[0].tx);
  2813. lpVertex->tv = (float)(cp[0].ty);
  2814. lpVertex++;
  2815. _flight = flight + cp[u+1].ev.Light;
  2816. lpVertex->sx = (float)(VideoCX - (int)(cp[u+1].ev.v.x / cp[u+1].ev.v.z * CameraW));
  2817. lpVertex->sy = (float)(VideoCY + (int)(cp[u+1].ev.v.y / cp[u+1].ev.v.z * CameraH));
  2818. lpVertex->sz = _ZSCALE / cp[u+1].ev.v.z;
  2819. lpVertex->rhw = lpVertex->sz * _AZSCALE;
  2820. lpVertex->color = _flight * 0x00010101 | almask;
  2821. lpVertex->specular = ((int)cp[u+1].ev.Fog)<<24;
  2822. lpVertex->tu = (float)(cp[u+1].tx);
  2823. lpVertex->tv = (float)(cp[u+1].ty);
  2824. lpVertex++;
  2825. _flight = flight + cp[u+2].ev.Light;
  2826. lpVertex->sx = (float)(VideoCX - (int)(cp[u+2].ev.v.x / cp[u+2].ev.v.z * CameraW));
  2827. lpVertex->sy = (float)(VideoCY + (int)(cp[u+2].ev.v.y / cp[u+2].ev.v.z * CameraH));
  2828. lpVertex->sz = _ZSCALE / cp[u+2].ev.v.z;
  2829. lpVertex->rhw = lpVertex->sz * _AZSCALE;
  2830. lpVertex->color = _flight * 0x00010101 | almask;
  2831. lpVertex->specular = ((int)cp[u+2].ev.Fog)<<24;
  2832. lpVertex->tu = (float)(cp[u+2].tx);
  2833. lpVertex->tv = (float)(cp[u+2].ty);
  2834. lpVertex++;
  2835. if (fptr->Flags & (sfOpacity | sfTransparent)) fproc2++; else fproc1++;
  2836. }
  2837. LNEXT:
  2838. f = mptr->gFace[f].Next;
  2839. }
  2840. d3dFlushBuffer(fproc1, fproc2);
  2841. }
  2842. void RenderModelClipEnvMap(TModel* _mptr, float x0, float y0, float z0, float al, float bt)
  2843. {
  2844. int f,CMASK;
  2845. mptr = _mptr;
  2846. float ca = (float)cos(al);
  2847. float sa = (float)sin(al);
  2848. float cb = (float)cos(bt);
  2849. float sb = (float)sin(bt);
  2850. DWORD PHCOLOR = 0xFFFFFFFF;
  2851. BOOL BL = FALSE;
  2852. for (int s=0; s<mptr->VCount; s++) {
  2853. rVertex[s].x = (mptr->gVertex[s].x * ca + mptr->gVertex[s].z * sa) /* * mdlScale */ + x0;
  2854. float vz = mptr->gVertex[s].z * ca - mptr->gVertex[s].x * sa;
  2855. rVertex[s].y = (mptr->gVertex[s].y * cb - vz * sb) /* * mdlScale */ + y0;
  2856. rVertex[s].z = (vz * cb + mptr->gVertex[s].y * sb) /* * mdlScale */ + z0;
  2857. if (rVertex[s].z<0) BL=TRUE;
  2858. if (rVertex[s].z>-256) { gScrp[s].x = 0xFFFFFF; gScrp[s].y = 0xFF; }
  2859. else {
  2860. int f = 0;
  2861. int sx = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
  2862. int sy = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
  2863. if (sx>=WinEX) f+=1;
  2864. if (sx<=0 ) f+=2;
  2865. if (sy>=WinEY) f+=4;
  2866. if (sy<=0 ) f+=8;
  2867. gScrp[s].y = f;
  2868. }
  2869. }
  2870. d3dSetTexture(TFX_ENVMAP.lpImage, TFX_ENVMAP.W, TFX_ENVMAP.W);
  2871. SetRenderStates(FALSE, D3DBLEND_ONE);
  2872. BuildTreeClipNoSort();
  2873. d3dStartBuffer();
  2874. f = Current;
  2875. int fproc1 = 0;
  2876. while( f!=-1 ) {
  2877. vused = 3;
  2878. TFace *fptr = &mptr->gFace[f];
  2879. if (!(fptr->Flags & sfEnvMap)) goto LNEXT;
  2880. CMASK = 0;
  2881. CMASK|=gScrp[fptr->v1].y;
  2882. CMASK|=gScrp[fptr->v2].y;
  2883. CMASK|=gScrp[fptr->v3].y;
  2884. cp[0].ev.v = rVertex[fptr->v1]; cp[0].tx = PhongMapping[fptr->v1].x/256.f; cp[0].ty = PhongMapping[fptr->v1].y/256.f;
  2885. cp[1].ev.v = rVertex[fptr->v2]; cp[1].tx = PhongMapping[fptr->v2].x/256.f; cp[1].ty = PhongMapping[fptr->v2].y/256.f;
  2886. cp[2].ev.v = rVertex[fptr->v3]; cp[2].tx = PhongMapping[fptr->v3].x/256.f; cp[2].ty = PhongMapping[fptr->v3].y/256.f;
  2887. {
  2888. for (u=0; u<vused; u++) cp[u].ev.v.z+= 8.0f;
  2889. for (u=0; u<vused; u++) ClipVector(ClipZ,u);
  2890. for (u=0; u<vused; u++) cp[u].ev.v.z-= 8.0f;
  2891. if (vused<3) goto LNEXT;
  2892. }
  2893. if (CMASK & 1) for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) goto LNEXT;
  2894. if (CMASK & 2) for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) goto LNEXT;
  2895. if (CMASK & 4) for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) goto LNEXT;
  2896. if (CMASK & 8) for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) goto LNEXT;
  2897. for (u=0; u<vused-2; u++) {
  2898. lpVertex->sx = (float)(VideoCX - (int)(cp[0].ev.v.x / cp[0].ev.v.z * CameraW));
  2899. lpVertex->sy = (float)(VideoCY + (int)(cp[0].ev.v.y / cp[0].ev.v.z * CameraH));
  2900. lpVertex->sz = _ZSCALE / cp[0].ev.v.z;
  2901. lpVertex->rhw = lpVertex->sz * _AZSCALE;
  2902. lpVertex->color = PHCOLOR;
  2903. lpVertex->specular = 0xFF000000;
  2904. lpVertex->tu = (float)(cp[0].tx);
  2905. lpVertex->tv = (float)(cp[0].ty);
  2906. lpVertex++;
  2907. lpVertex->sx = (float)(VideoCX - (int)(cp[u+1].ev.v.x / cp[u+1].ev.v.z * CameraW));
  2908. lpVertex->sy = (float)(VideoCY + (int)(cp[u+1].ev.v.y / cp[u+1].ev.v.z * CameraH));
  2909. lpVertex->sz = _ZSCALE / cp[u+1].ev.v.z;
  2910. lpVertex->rhw = lpVertex->sz * _AZSCALE;
  2911. lpVertex->color = PHCOLOR;
  2912. lpVertex->specular = 0xFF000000;
  2913. lpVertex->tu = (float)(cp[u+1].tx);
  2914. lpVertex->tv = (float)(cp[u+1].ty);
  2915. lpVertex++;
  2916. lpVertex->sx = (float)(VideoCX - (int)(cp[u+2].ev.v.x / cp[u+2].ev.v.z * CameraW));
  2917. lpVertex->sy = (float)(VideoCY + (int)(cp[u+2].ev.v.y / cp[u+2].ev.v.z * CameraH));
  2918. lpVertex->sz = _ZSCALE / cp[u+2].ev.v.z;
  2919. lpVertex->rhw = lpVertex->sz * _AZSCALE;
  2920. lpVertex->color = PHCOLOR;
  2921. lpVertex->specular = 0xFF000000;
  2922. lpVertex->tu = (float)(cp[u+2].tx);
  2923. lpVertex->tv = (float)(cp[u+2].ty);
  2924. lpVertex++;
  2925. fproc1++;
  2926. }
  2927. LNEXT:
  2928. f = mptr->gFace[f].Next;
  2929. }
  2930. d3dFlushBuffer(fproc1, 0);
  2931. SetRenderStates(TRUE, D3DBLEND_INVSRCALPHA);
  2932. }
  2933. void RenderModelClipPhongMap(TModel* _mptr, float x0, float y0, float z0, float al, float bt)
  2934. {
  2935. int f,CMASK;
  2936. mptr = _mptr;
  2937. float ca = (float)cos(al);
  2938. float sa = (float)sin(al);
  2939. float cb = (float)cos(bt);
  2940. float sb = (float)sin(bt);
  2941. int rv = SkyR +64; if (rv>255) rv = 255;
  2942. int gv = SkyG +64; if (gv>255) gv = 255;
  2943. int bv = SkyB +64; if (bv>255) bv = 255;
  2944. DWORD PHCOLOR = 0xFF000000 + (rv<<16) + (gv<<8) + bv;
  2945. BOOL BL = FALSE;
  2946. for (int s=0; s<mptr->VCount; s++) {
  2947. rVertex[s].x = (mptr->gVertex[s].x * ca + mptr->gVertex[s].z * sa) /* * mdlScale */ + x0;
  2948. float vz = mptr->gVertex[s].z * ca - mptr->gVertex[s].x * sa;
  2949. rVertex[s].y = (mptr->gVertex[s].y * cb - vz * sb) /* * mdlScale */ + y0;
  2950. rVertex[s].z = (vz * cb + mptr->gVertex[s].y * sb) /* * mdlScale */ + z0;
  2951. if (rVertex[s].z<0) BL=TRUE;
  2952. if (rVertex[s].z>-256) { gScrp[s].x = 0xFFFFFF; gScrp[s].y = 0xFF; }
  2953. else {
  2954. int f = 0;
  2955. int sx = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
  2956. int sy = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
  2957. if (sx>=WinEX) f+=1;
  2958. if (sx<=0 ) f+=2;
  2959. if (sy>=WinEY) f+=4;
  2960. if (sy<=0 ) f+=8;
  2961. gScrp[s].y = f;
  2962. }
  2963. }
  2964. d3dSetTexture(TFX_SPECULAR.lpImage, TFX_SPECULAR.W, TFX_SPECULAR.W);
  2965. SetRenderStates(FALSE, D3DBLEND_ONE);
  2966. BuildTreeClipNoSort();
  2967. d3dStartBuffer();
  2968. f = Current;
  2969. int fproc1 = 0;
  2970. while( f!=-1 ) {
  2971. vused = 3;
  2972. TFace *fptr = &mptr->gFace[f];
  2973. if (!(fptr->Flags & sfPhong)) goto LNEXT;
  2974. CMASK = 0;
  2975. CMASK|=gScrp[fptr->v1].y;
  2976. CMASK|=gScrp[fptr->v2].y;
  2977. CMASK|=gScrp[fptr->v3].y;
  2978. cp[0].ev.v = rVertex[fptr->v1]; cp[0].tx = PhongMapping[fptr->v1].x/256.f; cp[0].ty = PhongMapping[fptr->v1].y/256.f;
  2979. cp[1].ev.v = rVertex[fptr->v2]; cp[1].tx = PhongMapping[fptr->v2].x/256.f; cp[1].ty = PhongMapping[fptr->v2].y/256.f;
  2980. cp[2].ev.v = rVertex[fptr->v3]; cp[2].tx = PhongMapping[fptr->v3].x/256.f; cp[2].ty = PhongMapping[fptr->v3].y/256.f;
  2981. {
  2982. for (u=0; u<vused; u++) cp[u].ev.v.z+= 8.0f;
  2983. for (u=0; u<vused; u++) ClipVector(ClipZ,u);
  2984. for (u=0; u<vused; u++) cp[u].ev.v.z-= 8.0f;
  2985. if (vused<3) goto LNEXT;
  2986. }
  2987. if (CMASK & 1) for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) goto LNEXT;
  2988. if (CMASK & 2) for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) goto LNEXT;
  2989. if (CMASK & 4) for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) goto LNEXT;
  2990. if (CMASK & 8) for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) goto LNEXT;
  2991. for (u=0; u<vused-2; u++) {
  2992. lpVertex->sx = (float)(VideoCX - (int)(cp[0].ev.v.x / cp[0].ev.v.z * CameraW));
  2993. lpVertex->sy = (float)(VideoCY + (int)(cp[0].ev.v.y / cp[0].ev.v.z * CameraH));
  2994. lpVertex->sz = _ZSCALE / cp[0].ev.v.z;
  2995. lpVertex->rhw = lpVertex->sz * _AZSCALE;
  2996. lpVertex->color = PHCOLOR;
  2997. lpVertex->specular = 0xFF000000;
  2998. lpVertex->tu = (float)(cp[0].tx);
  2999. lpVertex->tv = (float)(cp[0].ty);
  3000. lpVertex++;
  3001. lpVertex->sx = (float)(VideoCX - (int)(cp[u+1].ev.v.x / cp[u+1].ev.v.z * CameraW));
  3002. lpVertex->sy = (float)(VideoCY + (int)(cp[u+1].ev.v.y / cp[u+1].ev.v.z * CameraH));
  3003. lpVertex->sz = _ZSCALE / cp[u+1].ev.v.z;
  3004. lpVertex->rhw = lpVertex->sz * _AZSCALE;
  3005. lpVertex->color = PHCOLOR;
  3006. lpVertex->specular = 0xFF000000;
  3007. lpVertex->tu = (float)(cp[u+1].tx);
  3008. lpVertex->tv = (float)(cp[u+1].ty);
  3009. lpVertex++;
  3010. lpVertex->sx = (float)(VideoCX - (int)(cp[u+2].ev.v.x / cp[u+2].ev.v.z * CameraW));
  3011. lpVertex->sy = (float)(VideoCY + (int)(cp[u+2].ev.v.y / cp[u+2].ev.v.z * CameraH));
  3012. lpVertex->sz = _ZSCALE / cp[u+2].ev.v.z;
  3013. lpVertex->rhw = lpVertex->sz * _AZSCALE;
  3014. lpVertex->color = PHCOLOR;
  3015. lpVertex->specular = 0xFF000000;
  3016. lpVertex->tu = (float)(cp[u+2].tx);
  3017. lpVertex->tv = (float)(cp[u+2].ty);
  3018. lpVertex++;
  3019. fproc1++;
  3020. }
  3021. LNEXT:
  3022. f = mptr->gFace[f].Next;
  3023. }
  3024. d3dFlushBuffer(fproc1, 0);
  3025. SetRenderStates(TRUE, D3DBLEND_INVSRCALPHA);
  3026. }
  3027. void RenderModelSun(TModel* _mptr, float x0, float y0, float z0, int Alpha)
  3028. {
  3029. int f;
  3030. mptr = _mptr;
  3031. int minx = 10241024;
  3032. int maxx =-10241024;
  3033. int miny = 10241024;
  3034. int maxy =-10241024;
  3035. for (int s=0; s<mptr->VCount; s++) {
  3036. rVertex[s].x = mptr->gVertex[s].x + x0;
  3037. rVertex[s].y = mptr->gVertex[s].y + y0;
  3038. rVertex[s].z = mptr->gVertex[s].z + z0;
  3039. if (rVertex[s].z>-64) gScrp[s].x = 0xFFFFFF; else {
  3040. gScrp[s].x = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
  3041. gScrp[s].y = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH); }
  3042. if (gScrp[s].x > maxx) maxx = gScrp[s].x;
  3043. if (gScrp[s].x < minx) minx = gScrp[s].x;
  3044. if (gScrp[s].y > maxy) maxy = gScrp[s].y;
  3045. if (gScrp[s].y < miny) miny = gScrp[s].y;
  3046. }
  3047. if (minx == 10241024) return;
  3048. if (minx>WinW || maxx<0 || miny>WinH || maxy<0) return;
  3049. BuildTreeNoSort();
  3050. d3dSetTexture(mptr->lpTexture2, 128, 128);
  3051. d3dStartBuffer();
  3052. DWORD alpha = Alpha;
  3053. alpha = (alpha<<24) | 0x00FFFFFF;
  3054. int fproc1 = 0;
  3055. f = Current;
  3056. while( f!=-1 ) {
  3057. TFace *fptr = & mptr->gFace[f];
  3058. fproc1++;
  3059. lpVertex->sx = (float)gScrp[fptr->v1].x;
  3060. lpVertex->sy = (float)gScrp[fptr->v1].y;
  3061. lpVertex->sz = 0.0002;//_ZSCALE / rVertex[fptr->v1].z;
  3062. lpVertex->rhw = 1.f;
  3063. lpVertex->color = alpha;
  3064. lpVertex->specular = 0xFF000000;
  3065. lpVertex->tu = (float)(fptr->tax);
  3066. lpVertex->tv = (float)(fptr->tay);
  3067. lpVertex++;
  3068. lpVertex->sx = (float)gScrp[fptr->v2].x;
  3069. lpVertex->sy = (float)gScrp[fptr->v2].y;
  3070. lpVertex->sz = 0.0002;//_ZSCALE / rVertex[fptr->v2].z;
  3071. lpVertex->rhw = 1.f;
  3072. lpVertex->color = alpha;
  3073. lpVertex->specular = 0xFF000000;
  3074. lpVertex->tu = (float)(fptr->tbx);
  3075. lpVertex->tv = (float)(fptr->tby);
  3076. lpVertex++;
  3077. lpVertex->sx = (float)gScrp[fptr->v3].x;
  3078. lpVertex->sy = (float)gScrp[fptr->v3].y;
  3079. lpVertex->sz = 0.0002;//_ZSCALE / rVertex[fptr->v3].z;
  3080. lpVertex->rhw = 1.f;
  3081. lpVertex->color = alpha;
  3082. lpVertex->specular = 0xFF000000;
  3083. lpVertex->tu = (float)(fptr->tcx);
  3084. lpVertex->tv = (float)(fptr->tcy);
  3085. lpVertex++;
  3086. f = mptr->gFace[f].Next;
  3087. }
  3088. lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + 1024*3);
  3089. lpInstruction->bOpcode = D3DOP_STATERENDER;
  3090. lpInstruction->bSize = sizeof(D3DSTATE);
  3091. lpInstruction->wCount = 2;
  3092. lpInstruction++;
  3093. lpState = (LPD3DSTATE)lpInstruction;
  3094. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
  3095. lpState->dwArg[0] = hTexture;
  3096. lpState++;
  3097. lpState->drstRenderStateType = D3DRENDERSTATE_DESTBLEND;
  3098. lpState->dwArg[0] = D3DBLEND_ONE;
  3099. lpState++;
  3100. lpInstruction = (LPD3DINSTRUCTION)lpState;
  3101. lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
  3102. lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
  3103. lpInstruction->wCount = 1U;
  3104. lpInstruction++;
  3105. lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
  3106. lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
  3107. lpProcessVertices->wStart = 0U;
  3108. lpProcessVertices->wDest = 0U;
  3109. lpProcessVertices->dwCount = fproc1*3;
  3110. lpProcessVertices->dwReserved = 0UL;
  3111. lpProcessVertices++;
  3112. lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
  3113. lpInstruction->bOpcode = D3DOP_TRIANGLE;
  3114. lpInstruction->bSize = sizeof(D3DTRIANGLE);
  3115. lpInstruction->wCount = fproc1;
  3116. lpInstruction++;
  3117. lpTriangle = (LPD3DTRIANGLE)lpInstruction;
  3118. int ii = 0;
  3119. for (int i=0; i<fproc1; i++) {
  3120. lpTriangle->wV1 = ii++;
  3121. lpTriangle->wV2 = ii++;
  3122. lpTriangle->wV3 = ii++;
  3123. lpTriangle->wFlags = 0;
  3124. lpTriangle++;
  3125. }
  3126. lpInstruction = (LPD3DINSTRUCTION)lpTriangle;
  3127. lpInstruction->bOpcode = D3DOP_STATERENDER;
  3128. lpInstruction->bSize = sizeof(D3DSTATE);
  3129. lpInstruction->wCount = 1;
  3130. lpInstruction++;
  3131. lpState = (LPD3DSTATE)lpInstruction;
  3132. lpState->drstRenderStateType = D3DRENDERSTATE_DESTBLEND;
  3133. lpState->dwArg[0] = D3DBLEND_INVSRCALPHA;
  3134. lpState++;
  3135. lpInstruction = (LPD3DINSTRUCTION)lpState;
  3136. lpInstruction->bOpcode = D3DOP_STATERENDER;
  3137. lpInstruction->bSize = sizeof(D3DSTATE);
  3138. lpInstruction->wCount = 3;
  3139. lpInstruction++;
  3140. lpState = (LPD3DSTATE)lpInstruction;
  3141. lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
  3142. lpState->dwArg[0] = FALSE;
  3143. lpState++;
  3144. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
  3145. lpState->dwArg[0] = D3DFILTER_LINEAR;
  3146. lpState++;
  3147. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
  3148. lpState->dwArg[0] = D3DFILTER_LINEAR;
  3149. lpState++;
  3150. lpInstruction = (LPD3DINSTRUCTION)lpState;
  3151. lpInstruction->bOpcode = D3DOP_EXIT;
  3152. lpInstruction->bSize = 0UL;
  3153. lpInstruction->wCount = 0U;
  3154. lpd3dExecuteBuffer->Unlock( );
  3155. hRes = lpd3dDevice->Execute(lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
  3156. //if (FAILED(hRes)) DoHalt("Error execute buffer");
  3157. dFacesCount+=fproc1;
  3158. }
  3159. void RenderNearModel(TModel* _mptr, float x0, float y0, float z0, int light, float al, float bt)
  3160. {
  3161. BOOL b = LOWRESTX;
  3162. Vector3d v;
  3163. v.x = 0; v.y =-128; v.z = 0;
  3164. CalcFogLevel_Gradient(v);
  3165. FogYGrad = 0;
  3166. LOWRESTX = FALSE;
  3167. RenderModelClip(_mptr, x0, y0, z0, light, 0, al, bt);
  3168. LOWRESTX = b;
  3169. }
  3170. void RenderModelClipWater(TModel* _mptr, float x0, float y0, float z0, int light, int VT, float al, float bt)
  3171. {
  3172. }
  3173. void RenderCharacter(int index)
  3174. {
  3175. }
  3176. void RenderExplosion(int index)
  3177. {
  3178. }
  3179. void RenderShip()
  3180. {
  3181. }
  3182. void RenderElements()
  3183. {
  3184. d3dLastTexture = d3dmemmapsize+1;
  3185. hTexture = NULL;
  3186. int fproc1 = 0;
  3187. for (int eg = 0; eg<ElCount; eg++) {
  3188. for (int e = 0; e<Elements[eg].ECount; e++) {
  3189. Vector3d rpos;
  3190. TElement *el = &Elements[eg].EList[e];
  3191. rpos.x = el->pos.x - CameraX;
  3192. rpos.y = el->pos.y - CameraY;
  3193. rpos.z = el->pos.z - CameraZ;
  3194. float r = el->R;
  3195. rpos = RotateVector(rpos);
  3196. if (rpos.z > -64) continue;
  3197. if ( fabs(rpos.x) > -rpos.z) continue;
  3198. if ( fabs(rpos.y) > -rpos.z) continue;
  3199. if (!fproc1) d3dStartBuffer();
  3200. float sx = VideoCX - (int)(CameraW * rpos.x / rpos.z * 16) / 16.f;
  3201. float sy = VideoCY + (int)(CameraH * rpos.y / rpos.z * 16) / 16.f;
  3202. RenderCircle(sx, sy, rpos.z, -r*CameraW*0.64 / rpos.z, Elements[eg].RGBA, Elements[eg].RGBA2);
  3203. fproc1+=8;
  3204. if (fproc1>256) {
  3205. d3dFlushBuffer(fproc1, 0);
  3206. fproc1 = 0;
  3207. }
  3208. }
  3209. }
  3210. if (fproc1) d3dFlushBuffer(fproc1, 0);
  3211. fproc1 = 0;
  3212. for (int b=0; b<BloodTrail.Count; b++) {
  3213. Vector3d rpos = BloodTrail.Trail[b].pos;
  3214. DWORD A1 = (0xE0 * BloodTrail.Trail[b].LTime / 20000); if (A1>0xE0) A1=0xE0;
  3215. DWORD A2 = (0x20 * BloodTrail.Trail[b].LTime / 20000); if (A2>0x20) A2=0x20;
  3216. rpos.x = rpos.x - CameraX;
  3217. rpos.y = rpos.y - CameraY;
  3218. rpos.z = rpos.z - CameraZ;
  3219. rpos = RotateVector(rpos);
  3220. if (rpos.z > -64) continue;
  3221. if ( fabs(rpos.x) > -rpos.z) continue;
  3222. if ( fabs(rpos.y) > -rpos.z) continue;
  3223. if (!fproc1) d3dStartBuffer();
  3224. float sx = VideoCX - (int)(CameraW * rpos.x / rpos.z * 16) / 16.f;
  3225. float sy = VideoCY + (int)(CameraH * rpos.y / rpos.z * 16) / 16.f;
  3226. RenderCircle(sx, sy, rpos.z, -12*CameraW*0.64 / rpos.z, (A1<<24)+conv_xGx(0x700000), (A2<<24)+conv_xGx(0x300000));
  3227. fproc1+=8;
  3228. if (fproc1>256) {
  3229. d3dFlushBuffer(fproc1, 0);
  3230. fproc1 = 0;
  3231. }
  3232. }
  3233. if (fproc1) d3dFlushBuffer(fproc1, 0);
  3234. GlassL = 0;
  3235. }
  3236. void RenderCharacterPost(TCharacter *cptr)
  3237. {
  3238. //mdlScale = 1.0f;
  3239. CreateChMorphedModel(cptr);
  3240. float zs = (float)sqrt( cptr->rpos.x*cptr->rpos.x + cptr->rpos.y*cptr->rpos.y + cptr->rpos.z*cptr->rpos.z);
  3241. if (zs > ctViewR*256) return;
  3242. GlassL = 0;
  3243. if (zs > 256 * (ctViewR-4))
  3244. GlassL = min(255, (zs/4 - 64*(ctViewR-4)));
  3245. waterclip = FALSE;
  3246. if ( cptr->rpos.z >-256*10)
  3247. RenderModelClip(cptr->pinfo->mptr,
  3248. cptr->rpos.x, cptr->rpos.y, cptr->rpos.z, 210, 0,
  3249. -cptr->alpha + pi / 2 + CameraAlpha,
  3250. CameraBeta );
  3251. else
  3252. RenderModel(cptr->pinfo->mptr,
  3253. cptr->rpos.x, cptr->rpos.y, cptr->rpos.z, 210, 0,
  3254. -cptr->alpha + pi / 2 + CameraAlpha,
  3255. CameraBeta );
  3256. if (!SHADOWS3D) return;
  3257. if (zs > 256 * (ctViewR-8)) return;
  3258. int Al = 0x60;
  3259. if (cptr->Health==0) {
  3260. int at = cptr->pinfo->Animation[cptr->Phase].AniTime;
  3261. if (Tranq) return;
  3262. if (cptr->FTime==at-1) return;
  3263. Al = Al * (at-cptr->FTime) / at; }
  3264. if (cptr->AI==0) Al = 0x50;
  3265. GlassL = (Al<<24) + 0x00222222;
  3266. RenderShadowClip(cptr->pinfo->mptr,
  3267. cptr->pos.x, cptr->pos.y, cptr->pos.z,
  3268. cptr->rpos.x, cptr->rpos.y, cptr->rpos.z,
  3269. pi/2-cptr->alpha,
  3270. CameraAlpha,
  3271. CameraBeta );
  3272. }
  3273. void RenderShipPost()
  3274. {
  3275. if (Ship.State==-1) return;
  3276. GlassL = 0;
  3277. zs = (int)VectorLength(Ship.rpos);
  3278. if (zs > 256 * (ctViewR)) return;
  3279. if (zs > 256 * (ctViewR-4))
  3280. GlassL = min(255,(int)(zs - 256 * (ctViewR-4)) / 4);
  3281. /*grConstantColorValue( (255-GlassL) << 24);*/
  3282. CreateMorphedModel(ShipModel.mptr, &ShipModel.Animation[0], Ship.FTime, 1.0);
  3283. if ( fabs(Ship.rpos.z) < 4000)
  3284. RenderModelClip(ShipModel.mptr,
  3285. Ship.rpos.x, Ship.rpos.y, Ship.rpos.z, 210, 0, -Ship.alpha -pi/2 + CameraAlpha, CameraBeta);
  3286. else
  3287. RenderModel(ShipModel.mptr,
  3288. Ship.rpos.x, Ship.rpos.y, Ship.rpos.z, 210, 0, -Ship.alpha -pi/2+ CameraAlpha, CameraBeta);
  3289. /*grConstantColorValue( 0xFF000000);*/
  3290. }
  3291. void Render3DHardwarePosts()
  3292. {
  3293. TCharacter *cptr;
  3294. for (int c=0; c<ChCount; c++) {
  3295. cptr = &Characters[c];
  3296. cptr->rpos.x = cptr->pos.x - CameraX;
  3297. cptr->rpos.y = cptr->pos.y - CameraY;
  3298. cptr->rpos.z = cptr->pos.z - CameraZ;
  3299. float r = (float)max( fabs(cptr->rpos.x), fabs(cptr->rpos.z) );
  3300. int ri = -1 + (int)(r / 256.f + 0.5f);
  3301. if (ri < 0) ri = 0;
  3302. if (ri > ctViewR) continue;
  3303. if (FOGON)
  3304. CalcFogLevel_Gradient(cptr->rpos);
  3305. cptr->rpos = RotateVector(cptr->rpos);
  3306. float br = BackViewR + DinoInfo[cptr->CType].Radius;
  3307. if (cptr->rpos.z > br) continue;
  3308. if ( fabs(cptr->rpos.x) > -cptr->rpos.z + br ) continue;
  3309. if ( fabs(cptr->rpos.y) > -cptr->rpos.z + br ) continue;
  3310. RenderCharacterPost(cptr);
  3311. }
  3312. Ship.rpos.x = Ship.pos.x - CameraX;
  3313. Ship.rpos.y = Ship.pos.y - CameraY;
  3314. Ship.rpos.z = Ship.pos.z - CameraZ;
  3315. float r = (float)max( fabs(Ship.rpos.x), fabs(Ship.rpos.z) );
  3316. int ri = -1 + (int)(r / 256.f + 0.2f);
  3317. if (ri < 0) ri = 0;
  3318. if (ri < ctViewR) {
  3319. if (FOGON)
  3320. CalcFogLevel_Gradient(Ship.rpos);
  3321. Ship.rpos = RotateVector(Ship.rpos);
  3322. if (Ship.rpos.z > BackViewR) goto NOSHIP;
  3323. if ( fabs(Ship.rpos.x) > -Ship.rpos.z + BackViewR ) goto NOSHIP;
  3324. RenderShipPost();
  3325. }
  3326. NOSHIP: ;
  3327. SunLight *= GetTraceK(SunScrX, SunScrY);
  3328. }
  3329. void ClearVideoBuf()
  3330. {
  3331. }
  3332. int CircleCX, CircleCY;
  3333. WORD CColor;
  3334. void PutPixel(int x, int y)
  3335. { *((WORD*)ddsd.lpSurface + y*lsw + x) = CColor; }
  3336. void Put8pix(int X,int Y)
  3337. {
  3338. PutPixel(CircleCX + X, CircleCY + Y);
  3339. PutPixel(CircleCX + X, CircleCY - Y);
  3340. PutPixel(CircleCX - X, CircleCY + Y);
  3341. PutPixel(CircleCX - X, CircleCY - Y);
  3342. PutPixel(CircleCX + Y, CircleCY + X);
  3343. PutPixel(CircleCX + Y, CircleCY - X);
  3344. PutPixel(CircleCX - Y, CircleCY + X);
  3345. PutPixel(CircleCX - Y, CircleCY - X);
  3346. }
  3347. void DrawCircle(int cx, int cy, int R)
  3348. {
  3349. int d = 3 - (2 * R);
  3350. int x = 0;
  3351. int y = R;
  3352. CircleCX=cx;
  3353. CircleCY=cy;
  3354. do {
  3355. Put8pix(x,y); x++;
  3356. if (d < 0) d = d + (x<<2) + 6; else
  3357. { d = d + (x - y) * 4 + 10; y--; }
  3358. } while (x<y);
  3359. Put8pix(x,y);
  3360. }
  3361. void DrawBox( WORD *lfbPtr, int lsw, int xx, int yy, WORD c)
  3362. {
  3363. yy = yy * lsw + xx;
  3364. *(lfbPtr + yy) = c;
  3365. *(lfbPtr + yy + 1) = c;
  3366. yy+=lsw;
  3367. *(lfbPtr + yy) = c;
  3368. *(lfbPtr + yy + 1) = c;
  3369. }
  3370. void DrawHMap()
  3371. {
  3372. int c;
  3373. DrawPicture(VideoCX-MapPic.W/2, VideoCY - MapPic.H/2-6, MapPic);
  3374. ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
  3375. ddsd.dwSize = sizeof(DDSURFACEDESC);
  3376. if( lpddBack->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
  3377. lsw = ddsd.lPitch / 2;
  3378. int RShift, GShift;
  3379. if (VMFORMAT565) {
  3380. RShift=11; GShift=6;
  3381. } else {
  3382. RShift=10; GShift=5;
  3383. }
  3384. int xx = VideoCX - 128 + (CCX>>2);
  3385. int yy = VideoCY - 128 + (CCY>>2);
  3386. if (yy<0 || yy>=WinH) goto endmap;
  3387. if (xx<0 || xx>=WinW) goto endmap;
  3388. DrawBox((WORD*)ddsd.lpSurface, lsw, xx+1, yy+1, 8<<RShift);
  3389. DrawBox((WORD*)ddsd.lpSurface, lsw, xx, yy, 30<<RShift);
  3390. /*
  3391. *((WORD*)ddsd.lpSurface + yy*lsw + xx) = 30<<RShift;
  3392. *((WORD*)ddsd.lpSurface + yy*lsw + xx + 1) = 30<<RShift;
  3393. yy++;
  3394. *((WORD*)ddsd.lpSurface + yy*lsw + xx) = 30<<RShift;
  3395. *((WORD*)ddsd.lpSurface + yy*lsw + xx + 1) = 30<<RShift;
  3396. */
  3397. CColor = 4<<GShift; DrawCircle(xx+1, yy+1, (ctViewR/4));
  3398. CColor = 18<<GShift; DrawCircle(xx, yy, (ctViewR/4));
  3399. if (RadarMode)
  3400. for (c=0; c<ChCount; c++) {
  3401. if (Characters[c].AI<10) continue;
  3402. if (! (TargetDino & (1<<Characters[c].AI)) ) continue;
  3403. if (!Characters[c].Health) continue;
  3404. xx = VideoCX - 128 + (int)Characters[c].pos.x / 1024;
  3405. yy = VideoCY - 128 + (int)Characters[c].pos.z / 1024;
  3406. if (yy<=0 || yy>=WinH) goto endmap;
  3407. if (xx<=0 || xx>=WinW) goto endmap;
  3408. DrawBox((WORD*)ddsd.lpSurface, lsw, xx, yy, 30<<GShift);
  3409. }
  3410. endmap:
  3411. lpddBack->Unlock(ddsd.lpSurface);
  3412. }
  3413. void RenderSun(float x, float y, float z)
  3414. {
  3415. SunScrX = VideoCX + (int)(x / (-z) * CameraW);
  3416. SunScrY = VideoCY - (int)(y / (-z) * CameraH);
  3417. GetSkyK(SunScrX, SunScrY);
  3418. float d = (float)sqrt(x*x + y*y);
  3419. if (d<2048) {
  3420. SunLight = (220.f- d*220.f/2048.f);
  3421. if (SunLight>140) SunLight = 140;
  3422. SunLight*=SkyTraceK;
  3423. }
  3424. if (d>812.f) d = 812.f;
  3425. d = (2048.f + d) / 3048.f;
  3426. d+=(1.f-SkyTraceK)/2.f;
  3427. if (OptDayNight==2) d=1.5;
  3428. RenderModelSun(SunModel, x*d, y*d, z*d, (int)(200.f* SkyTraceK));
  3429. }
  3430. void RotateVVector(Vector3d& v)
  3431. {
  3432. float x = v.x * ca - v.z * sa;
  3433. float y = v.y;
  3434. float z = v.z * ca + v.x * sa;
  3435. float xx = x;
  3436. float xy = y * cb + z * sb;
  3437. float xz = z * cb - y * sb;
  3438. v.x = xx; v.y = xy; v.z = xz;
  3439. }
  3440. void RenderSkyPlane()
  3441. {
  3442. Vector3d v,vbase;
  3443. Vector3d tx,ty,nv;
  3444. float p,q, qx, qy, qz, px, py, pz, rx, ry, rz, ddx, ddy;
  3445. float lastdt = 0.f;
  3446. d3dSetTexture(SkyPic, 256, 256);
  3447. nv.x = 512; nv.y = 4024; nv.z=0;
  3448. cb = (float)cos(CameraBeta);
  3449. sb = (float)sin(CameraBeta);
  3450. SKYDTime = RealTime & ((1<<17) - 1);
  3451. float sh = - CameraY;
  3452. if (MapMinY==10241024)
  3453. MapMinY=0;
  3454. sh = (float)((int)MapMinY)*ctHScale - CameraY;
  3455. if (sh<-2024) sh=-2024;
  3456. v.x = 0;
  3457. v.z = ctViewR*256.f;
  3458. v.y = sh;
  3459. vbase.x = v.x;
  3460. vbase.y = v.y * cb + v.z * sb;
  3461. vbase.z = v.z * cb - v.y * sb;
  3462. if (vbase.z < 128) vbase.z = 128;
  3463. int scry = VideoCY - (int)(vbase.y / vbase.z * CameraH);
  3464. if (scry<0) return;
  3465. if (scry>WinEY+1) scry = WinEY+1;
  3466. cb = (float)cos(CameraBeta-0.15);
  3467. sb = (float)sin(CameraBeta-0.15);
  3468. v.x = 0;
  3469. v.z = 2*256.f*256.f;
  3470. v.y = 512;
  3471. vbase.x = v.x;
  3472. vbase.y = v.y * cb + v.z * sb;
  3473. vbase.z = v.z * cb - v.y * sb;
  3474. if (vbase.z < 128) vbase.z = 128;
  3475. int _scry = VideoCY - (int)(vbase.y / vbase.z * CameraH);
  3476. if (scry > _scry) scry = _scry;
  3477. tx.x=0.002f; tx.y=0; tx.z=0;
  3478. ty.x=0.0f; ty.y=0; ty.z=0.002f;
  3479. nv.x=0; nv.y=-1.f; nv.z=0;
  3480. RotateVVector(tx);
  3481. RotateVVector(ty);
  3482. RotateVVector(nv);
  3483. sh = 4*512*16;
  3484. vbase.x = -CameraX;
  3485. vbase.y = sh;
  3486. vbase.z = +CameraZ;
  3487. RotateVVector(vbase);
  3488. //============= calc render params =================//
  3489. p = nv.x * vbase.x + nv.y * vbase.y + nv.z * vbase.z;
  3490. ddx = vbase.x * tx.x + vbase.y * tx.y + vbase.z * tx.z;
  3491. ddy = vbase.x * ty.x + vbase.y * ty.y + vbase.z * ty.z;
  3492. qx = CameraH * nv.x; qy = CameraW * nv.y; qz = CameraW*CameraH * nv.z;
  3493. px = p*CameraH*tx.x; py = p*CameraW*tx.y; pz = p*CameraW*CameraH* tx.z;
  3494. rx = p*CameraH*ty.x; ry = p*CameraW*ty.y; rz = p*CameraW*CameraH* ty.z;
  3495. px=px - ddx*qx; py=py - ddx*qy; pz=pz - ddx*qz;
  3496. rx=rx - ddy*qx; ry=ry - ddy*qy; rz=rz - ddy*qz;
  3497. float za = CameraW * CameraH * p / (qy * VideoCY + qz);
  3498. float zb = CameraW * CameraH * p / (qy * (VideoCY-scry/2.f) + qz);
  3499. float zc = CameraW * CameraH * p / (qy * (VideoCY-scry) + qz);
  3500. float _za = fabs(za) - 100200.f; if (_za<0) _za=0.f;
  3501. float _zb = fabs(zb) - 100200.f; if (_zb<0) _zb=0.f;
  3502. float _zc = fabs(zc) - 100200.f; if (_zc<0) _zc=0.f;
  3503. int alpha = (int)(255*40240 / (40240+_za));
  3504. int alphb = (int)(255*40240 / (40240+_zb));
  3505. int alphc = (int)(255*40240 / (40240+_zc));
  3506. int sx1 = - VideoCX;
  3507. int sx2 = + VideoCX;
  3508. float qx1 = qx * sx1 + qz;
  3509. float qx2 = qx * sx2 + qz;
  3510. float qyy;
  3511. // d3dStartBuffer();
  3512. ZeroMemory(&d3dExeBufDesc, sizeof(d3dExeBufDesc));
  3513. d3dExeBufDesc.dwSize = sizeof(d3dExeBufDesc);
  3514. hRes = lpd3dExecuteBufferG->Lock( &d3dExeBufDesc );
  3515. if (FAILED(hRes)) DoHalt("Error locking execute buffer");
  3516. lpVertex = (LPD3DTLVERTEX)d3dExeBufDesc.lpData;
  3517. float dtt = (float)(SKYDTime) / 512.f;
  3518. float sky=0;
  3519. float sy = VideoCY - sky;
  3520. qyy = qy * sy;
  3521. q = qx1 + qyy;
  3522. float fxa = (px * sx1 + py * sy + pz) / q;
  3523. float fya = (rx * sx1 + ry * sy + rz) / q;
  3524. q = qx2 + qyy;
  3525. float fxb = (px * sx2 + py * sy + pz) / q;
  3526. float fyb = (rx * sx2 + ry * sy + rz) / q;
  3527. lpVertex->sx = 0.f;
  3528. lpVertex->sy = (float)sky;
  3529. lpVertex->sz = 0.0001f;//-8.f / za;
  3530. lpVertex->rhw = -1.f / za;
  3531. /*if (FOGENABLE) {
  3532. lpVertex->color = 0xFFFFFFFF;
  3533. lpVertex->specular = alpha<<24; } else */{
  3534. lpVertex->color = 0x00FFFFFF | alpha<<24;
  3535. lpVertex->specular = 0xFF000000; }
  3536. lpVertex->tu = (fxa + dtt) / 256.f;
  3537. lpVertex->tv = (fya - dtt) / 256.f;
  3538. lpVertex++;
  3539. lpVertex->sx = (float)WinW;
  3540. lpVertex->sy = (float)sky;
  3541. lpVertex->sz = 0.0001f;//-8.f / za;
  3542. lpVertex->rhw = -1.f / za;
  3543. /*if (FOGENABLE) {
  3544. lpVertex->color = 0xFFFFFFFF;
  3545. lpVertex->specular = alpha<<24; } else */{
  3546. lpVertex->color = 0x00FFFFFF | alpha<<24;
  3547. lpVertex->specular = 0xFF000000; }
  3548. lpVertex->tu = (fxb + dtt) / 256.f;
  3549. lpVertex->tv = (fyb - dtt) / 256.f;
  3550. lpVertex++;
  3551. sky=scry/2.f;
  3552. sy = VideoCY - sky;
  3553. qyy = qy * sy;
  3554. q = qx1 + qyy;
  3555. fxa = (px * sx1 + py * sy + pz) / q;
  3556. fya = (rx * sx1 + ry * sy + rz) / q;
  3557. q = qx2 + qyy;
  3558. fxb = (px * sx2 + py * sy + pz) / q;
  3559. fyb = (rx * sx2 + ry * sy + rz) / q;
  3560. lpVertex->sx = 0.f;
  3561. lpVertex->sy = (float)sky;
  3562. lpVertex->sz = 0.0001f;//-8.f / zb;
  3563. lpVertex->rhw = -1.f / zb;
  3564. /*if (FOGENABLE) {
  3565. lpVertex->color = 0xFFFFFFFF;
  3566. lpVertex->specular = alphb<<24; } else */{
  3567. lpVertex->color = 0x00FFFFFF | alphb<<24;
  3568. lpVertex->specular = 0xFF000000; }
  3569. lpVertex->tu = (fxa + dtt) / 256.f;
  3570. lpVertex->tv = (fya - dtt) / 256.f;
  3571. lpVertex++;
  3572. lpVertex->sx = (float)WinW;
  3573. lpVertex->sy = (float)sky;
  3574. lpVertex->sz = 0.0001f;//-8.f / zb;
  3575. lpVertex->rhw = -1.f / zb;
  3576. /*if (FOGENABLE) {
  3577. lpVertex->color = 0xFFFFFFFF;
  3578. lpVertex->specular = alphb<<24; } else */{
  3579. lpVertex->color = 0x00FFFFFF | alphb<<24;
  3580. lpVertex->specular = 0xFF000000; }
  3581. lpVertex->tu = (fxb + dtt) / 256.f;
  3582. lpVertex->tv = (fyb - dtt) / 256.f;
  3583. lpVertex++;
  3584. sky=(float)scry;
  3585. sy = VideoCY - sky;
  3586. qyy = qy * sy;
  3587. q = qx1 + qyy;
  3588. fxa = (px * sx1 + py * sy + pz) / q;
  3589. fya = (rx * sx1 + ry * sy + rz) / q;
  3590. q = qx2 + qyy;
  3591. fxb = (px * sx2 + py * sy + pz) / q;
  3592. fyb = (rx * sx2 + ry * sy + rz) / q;
  3593. lpVertex->sx = 0.f;
  3594. lpVertex->sy = (float)sky;
  3595. lpVertex->sz = 0.0001f;//-8.f / zb;
  3596. lpVertex->rhw = -1.f / zc;
  3597. /*if (FOGENABLE) {
  3598. lpVertex->color = 0xFFFFFFFF;
  3599. lpVertex->specular = alphc<<24; } else */{
  3600. lpVertex->color = 0x00FFFFFF | alphc<<24;
  3601. lpVertex->specular = 0xFF000000; }
  3602. lpVertex->tu = (fxa + dtt) / 256.f;
  3603. lpVertex->tv = (fya - dtt) / 256.f;
  3604. lpVertex++;
  3605. lpVertex->sx = (float)WinW;
  3606. lpVertex->sy = (float)sky;
  3607. lpVertex->sz = 0.0001f;//-8.f / zb;
  3608. lpVertex->rhw = -1.f / zc;
  3609. /*if (FOGENABLE) {
  3610. lpVertex->color = 0xFFFFFFFF;
  3611. lpVertex->specular = alphc<<24; } else */{
  3612. lpVertex->color = 0x00FFFFFF | alphc<<24;
  3613. lpVertex->specular = 0xFF000000; }
  3614. lpVertex->tu = (fxb + dtt) / 256.f;
  3615. lpVertex->tv = (fyb - dtt) / 256.f;
  3616. lpVertex++;
  3617. lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + 400*3);
  3618. lpInstruction->bOpcode = D3DOP_STATERENDER;
  3619. lpInstruction->bSize = sizeof(D3DSTATE);
  3620. lpInstruction->wCount = 4;
  3621. lpInstruction++;
  3622. lpState = (LPD3DSTATE)lpInstruction;
  3623. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
  3624. lpState->dwArg[0] = hTexture;
  3625. lpState++;
  3626. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
  3627. lpState->dwArg[0] = D3DFILTER_LINEAR;
  3628. lpState++;
  3629. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
  3630. lpState->dwArg[0] = D3DFILTER_LINEAR;
  3631. lpState++;
  3632. lpState->drstRenderStateType = D3DRENDERSTATE_FOGCOLOR;
  3633. if (UNDERWATER) lpState->dwArg[0] = CurFogColor;
  3634. else lpState->dwArg[0] = (SkyR<<16) + (SkyG<<8) + SkyB;
  3635. lpState++;
  3636. lpInstruction = (LPD3DINSTRUCTION)lpState;
  3637. lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
  3638. lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
  3639. lpInstruction->wCount = 1U;
  3640. lpInstruction++;
  3641. lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
  3642. lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
  3643. lpProcessVertices->wStart = 0U;
  3644. lpProcessVertices->wDest = 0U;
  3645. lpProcessVertices->dwCount = 6;
  3646. lpProcessVertices->dwReserved = 0UL;
  3647. lpProcessVertices++;
  3648. lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
  3649. lpInstruction->bOpcode = D3DOP_TRIANGLE;
  3650. lpInstruction->bSize = sizeof(D3DTRIANGLE);
  3651. lpInstruction->wCount = 4;
  3652. lpInstruction++;
  3653. lpTriangle = (LPD3DTRIANGLE)lpInstruction;
  3654. lpTriangle->wV1 = 0;
  3655. lpTriangle->wV2 = 1;
  3656. lpTriangle->wV3 = 2;
  3657. lpTriangle->wFlags = 0;
  3658. lpTriangle++;
  3659. lpTriangle->wV1 = 1;
  3660. lpTriangle->wV2 = 2;
  3661. lpTriangle->wV3 = 3;
  3662. lpTriangle->wFlags = 0;
  3663. lpTriangle++;
  3664. lpTriangle->wV1 = 2;
  3665. lpTriangle->wV2 = 3;
  3666. lpTriangle->wV3 = 4;
  3667. lpTriangle->wFlags = 0;
  3668. lpTriangle++;
  3669. lpTriangle->wV1 = 3;
  3670. lpTriangle->wV2 = 4;
  3671. lpTriangle->wV3 = 5;
  3672. lpTriangle->wFlags = 0;
  3673. lpTriangle++;
  3674. lpInstruction = (LPD3DINSTRUCTION)lpTriangle;
  3675. lpInstruction->bOpcode = D3DOP_EXIT;
  3676. lpInstruction->bSize = 0UL;
  3677. lpInstruction->wCount = 0U;
  3678. lpd3dExecuteBufferG->Unlock( );
  3679. hRes = lpd3dDevice->Execute(lpd3dExecuteBufferG, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
  3680. LINEARFILTER = TRUE;
  3681. nv = RotateVector(Sun3dPos);
  3682. SunLight = 0;
  3683. if (nv.z < -2024) RenderSun(nv.x, nv.y, nv.z);
  3684. }
  3685. void RenderFSRect(DWORD Color)
  3686. {
  3687. d3dStartBuffer();
  3688. lpVertex->sx = 0.f;
  3689. lpVertex->sy = 0.f;
  3690. lpVertex->sz = 0.999f;
  3691. lpVertex->rhw = 1.f;
  3692. lpVertex->color = Color;
  3693. lpVertex->specular = 0xFF000000;
  3694. lpVertex->tu = 0;
  3695. lpVertex->tv = 0;
  3696. lpVertex++;
  3697. lpVertex->sx = (float)WinW;
  3698. lpVertex->sy = 0.f;
  3699. lpVertex->sz = 0.999f;
  3700. lpVertex->rhw = 1.f;
  3701. lpVertex->color = Color;
  3702. lpVertex->specular = 0xFF000000;
  3703. lpVertex->tu = 0;
  3704. lpVertex->tv = 0;
  3705. lpVertex++;
  3706. lpVertex->sx = 0.f;
  3707. lpVertex->sy = (float)WinH;
  3708. lpVertex->sz = 0.999f;
  3709. lpVertex->rhw = 1.f;
  3710. lpVertex->color = Color;
  3711. lpVertex->specular = 0xFF000000;
  3712. lpVertex->tu = 0;
  3713. lpVertex->tv = 0;
  3714. lpVertex++;
  3715. lpVertex->sx = (float)WinW;
  3716. lpVertex->sy = (float)WinH;
  3717. lpVertex->sz = (float)0.999f;
  3718. lpVertex->rhw = 1.f;
  3719. lpVertex->color = Color;
  3720. lpVertex->specular = 0xFF000000;
  3721. lpVertex->tu = 0;
  3722. lpVertex->tv = 0;
  3723. lpVertex++;
  3724. lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + 1024*3);
  3725. lpInstruction->bOpcode = D3DOP_STATERENDER;
  3726. lpInstruction->bSize = sizeof(D3DSTATE);
  3727. lpInstruction->wCount = 1;
  3728. lpInstruction++;
  3729. lpState = (LPD3DSTATE)lpInstruction;
  3730. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
  3731. lpState->dwArg[0] = NULL;
  3732. lpState++;
  3733. lpInstruction = (LPD3DINSTRUCTION)lpState;
  3734. lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
  3735. lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
  3736. lpInstruction->wCount = 1U;
  3737. lpInstruction++;
  3738. lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
  3739. lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
  3740. lpProcessVertices->wStart = 0U;
  3741. lpProcessVertices->wDest = 0U;
  3742. lpProcessVertices->dwCount = 4;
  3743. lpProcessVertices->dwReserved = 0UL;
  3744. lpProcessVertices++;
  3745. lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
  3746. lpInstruction->bOpcode = D3DOP_TRIANGLE;
  3747. lpInstruction->bSize = sizeof(D3DTRIANGLE);
  3748. lpInstruction->wCount = 2;
  3749. lpInstruction++;
  3750. lpTriangle = (LPD3DTRIANGLE)lpInstruction;
  3751. lpTriangle->wV1 = 0;
  3752. lpTriangle->wV2 = 1;
  3753. lpTriangle->wV3 = 2;
  3754. lpTriangle->wFlags = 0;
  3755. lpTriangle++;
  3756. lpTriangle->wV1 = 1;
  3757. lpTriangle->wV2 = 2;
  3758. lpTriangle->wV3 = 3;
  3759. lpTriangle->wFlags = 0;
  3760. lpTriangle++;
  3761. lpInstruction = (LPD3DINSTRUCTION)lpTriangle;
  3762. lpInstruction->bOpcode = D3DOP_EXIT;
  3763. lpInstruction->bSize = 0UL;
  3764. lpInstruction->wCount = 0U;
  3765. lpd3dExecuteBuffer->Unlock( );
  3766. hRes = lpd3dDevice->Execute(lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
  3767. }
  3768. void RenderHealthBar()
  3769. {
  3770. if (MyHealth >= 100000) return;
  3771. if (MyHealth == 000000) return;
  3772. int L = WinW / 4;
  3773. int x0 = WinW - (WinW / 20) - L;
  3774. int y0 = WinH / 40;
  3775. int G = min( (MyHealth * 240 / 100000), 160);
  3776. int R = min( ( (100000 - MyHealth) * 240 / 100000), 160);
  3777. int L0 = (L * MyHealth) / 100000;
  3778. int H = WinH / 200;
  3779. d3dStartBuffer();
  3780. for (int y=0; y<4; y++) {
  3781. lpVertex->sx = (float)x0-1;
  3782. lpVertex->sy = (float)y0+y;
  3783. lpVertex->sz = 0.9999f;
  3784. lpVertex->rhw = 1.f;
  3785. lpVertex->color = 0xF0000010;
  3786. lpVertex->specular = 0xFF000000;
  3787. lpVertex->tu = 0;
  3788. lpVertex->tv = 0;
  3789. lpVertex++;
  3790. lpVertex->sx = (float)x0+L0+1;
  3791. lpVertex->sy = (float)y0+y;
  3792. lpVertex->sz = 0.9999f;
  3793. lpVertex->rhw = 1.f;
  3794. lpVertex->color = 0xF0000010;
  3795. lpVertex->specular = 0xFF000000;
  3796. lpVertex->tu = 0;
  3797. lpVertex->tv = 0;
  3798. lpVertex++;
  3799. }
  3800. for (y=1; y<3; y++) {
  3801. lpVertex->sx = (float)x0;
  3802. lpVertex->sy = (float)y0+y;
  3803. lpVertex->sz = 0.99999f;
  3804. lpVertex->rhw = 1.f;
  3805. lpVertex->color = 0xF0000000 + (G<<8) + (R<<16);
  3806. lpVertex->specular = 0xFF000000;// + (G<<8) + (R<<16);
  3807. lpVertex->tu = 0;
  3808. lpVertex->tv = 0;
  3809. lpVertex++;
  3810. lpVertex->sx = (float)x0+L0;
  3811. lpVertex->sy = (float)y0+y;
  3812. lpVertex->sz = 0.99999f;
  3813. lpVertex->rhw = 1.f;
  3814. lpVertex->color = 0xF0000000 + (G<<8) + (R<<16);
  3815. lpVertex->specular = 0xFF000000;// + (G<<8) + (R<<16);
  3816. lpVertex->tu = 0;
  3817. lpVertex->tv = 0;
  3818. lpVertex++;
  3819. }
  3820. lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + 1024*3);
  3821. lpInstruction->bOpcode = D3DOP_STATERENDER;
  3822. lpInstruction->bSize = sizeof(D3DSTATE);
  3823. lpInstruction->wCount = 1;
  3824. lpInstruction++;
  3825. lpState = (LPD3DSTATE)lpInstruction;
  3826. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
  3827. lpState->dwArg[0] = NULL;
  3828. lpState++;
  3829. lpInstruction = (LPD3DINSTRUCTION)lpState;
  3830. lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
  3831. lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
  3832. lpInstruction->wCount = 1U;
  3833. lpInstruction++;
  3834. lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
  3835. lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
  3836. lpProcessVertices->wStart = 0U;
  3837. lpProcessVertices->wDest = 0U;
  3838. lpProcessVertices->dwCount = 12;
  3839. lpProcessVertices->dwReserved = 0UL;
  3840. lpProcessVertices++;
  3841. lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
  3842. lpInstruction->bOpcode = D3DOP_LINE;
  3843. lpInstruction->bSize = sizeof(D3DLINE);
  3844. lpInstruction->wCount = 6;
  3845. lpInstruction++;
  3846. lpLine = (LPD3DLINE)lpInstruction;
  3847. for (y=0; y<6; y++) {
  3848. lpLine->wV1 = y*2;
  3849. lpLine->wV2 = y*2+1;
  3850. lpLine++;
  3851. }
  3852. lpInstruction = (LPD3DINSTRUCTION)lpLine;
  3853. lpInstruction->bOpcode = D3DOP_EXIT;
  3854. lpInstruction->bSize = 0UL;
  3855. lpInstruction->wCount = 0U;
  3856. lpd3dExecuteBuffer->Unlock( );
  3857. hRes = lpd3dDevice->Execute(lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
  3858. }
  3859. void Render_Cross(int sx, int sy)
  3860. {
  3861. float w = (float) WinW / 12.f;
  3862. d3dStartBuffer();
  3863. lpVertex->sx = (float)sx-w;
  3864. lpVertex->sy = (float)sy;
  3865. lpVertex->sz = 0.99999f;
  3866. lpVertex->rhw = 1.f;
  3867. lpVertex->color = 0x80000010;
  3868. lpVertex->specular = 0xFF000000;
  3869. lpVertex->tu = 0;
  3870. lpVertex->tv = 0;
  3871. lpVertex++;
  3872. lpVertex->sx = (float)sx+w;
  3873. lpVertex->sy = (float)sy;
  3874. lpVertex->sz = 0.99999f;
  3875. lpVertex->rhw = 1.f;
  3876. lpVertex->color = 0x80000010;
  3877. lpVertex->specular = 0xFF000000;
  3878. lpVertex->tu = 0;
  3879. lpVertex->tv = 0;
  3880. lpVertex++;
  3881. lpVertex->sx = (float)sx;
  3882. lpVertex->sy = (float)sy-w;
  3883. lpVertex->sz = 0.99999f;
  3884. lpVertex->rhw = 1.f;
  3885. lpVertex->color = 0x80000010;
  3886. lpVertex->specular = 0xFF000000;
  3887. lpVertex->tu = 0;
  3888. lpVertex->tv = 0;
  3889. lpVertex++;
  3890. lpVertex->sx = (float)sx;
  3891. lpVertex->sy = (float)sy+w;
  3892. lpVertex->sz = 0.99999f;
  3893. lpVertex->rhw = 1.f;
  3894. lpVertex->color = 0x80000010;
  3895. lpVertex->specular = 0xFF000000;
  3896. lpVertex->tu = 0;
  3897. lpVertex->tv = 0;
  3898. lpVertex++;
  3899. lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + 1024*3);
  3900. lpInstruction->bOpcode = D3DOP_STATERENDER;
  3901. lpInstruction->bSize = sizeof(D3DSTATE);
  3902. lpInstruction->wCount = 1;
  3903. lpInstruction++;
  3904. lpState = (LPD3DSTATE)lpInstruction;
  3905. lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
  3906. lpState->dwArg[0] = NULL;
  3907. lpState++;
  3908. lpInstruction = (LPD3DINSTRUCTION)lpState;
  3909. lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
  3910. lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
  3911. lpInstruction->wCount = 1U;
  3912. lpInstruction++;
  3913. lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
  3914. lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
  3915. lpProcessVertices->wStart = 0U;
  3916. lpProcessVertices->wDest = 0U;
  3917. lpProcessVertices->dwCount = 4;
  3918. lpProcessVertices->dwReserved = 0UL;
  3919. lpProcessVertices++;
  3920. lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
  3921. lpInstruction->bOpcode = D3DOP_LINE;
  3922. lpInstruction->bSize = sizeof(D3DLINE);
  3923. lpInstruction->wCount = 2;
  3924. lpInstruction++;
  3925. lpLine = (LPD3DLINE)lpInstruction;
  3926. lpLine->wV1 = 0;
  3927. lpLine->wV2 = 1;
  3928. lpLine++;
  3929. lpLine->wV1 = 2;
  3930. lpLine->wV2 = 3;
  3931. lpLine++;
  3932. lpInstruction = (LPD3DINSTRUCTION)lpLine;
  3933. lpInstruction->bOpcode = D3DOP_EXIT;
  3934. lpInstruction->bSize = 0UL;
  3935. lpInstruction->wCount = 0U;
  3936. lpd3dExecuteBuffer->Unlock( );
  3937. hRes = lpd3dDevice->Execute(lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
  3938. }
  3939. #endif