1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188 |
- #ifdef _d3d
- #include "Hunt.h"
- #include "stdio.h"
- #undef TCMAX
- #undef TCMIN
- #define TCMAX ((128<<16)-62024)
- #define TCMIN ((000<<16)+62024)
- #define _ZSCALE - 16.f
- #define _AZSCALE (1.f / 16.f);
- Vector2di ORList[2048];
- int ORLCount = 0;
- LPDIRECTDRAWSURFACE lpddPrimary = NULL;
- LPDIRECTDRAWSURFACE lpddBack = NULL;
- LPDIRECTDRAWSURFACE lpddZBuffer = NULL;
- LPDIRECTDRAWSURFACE lpddTexture = NULL;
- DDSURFACEDESC ddsd;
- LPDIRECT3D lpd3d = NULL;
- LPDIRECT3DDEVICE lpd3dDevice = NULL;
- LPDIRECT3DVIEWPORT lpd3dViewport = NULL;
- LPDIRECT3DEXECUTEBUFFER lpd3dExecuteBuffer = NULL;
- LPDIRECT3DEXECUTEBUFFER lpd3dExecuteBufferG = NULL;
- LPD3DTLVERTEX lpVertex, lpVertexG;
- WORD *lpwTriCount;
- HRESULT hRes;
- D3DEXECUTEBUFFERDESC d3dExeBufDesc;
- D3DEXECUTEBUFFERDESC d3dExeBufDescG;
- LPD3DINSTRUCTION lpInstruction, lpInstructionG;
- LPD3DPROCESSVERTICES lpProcessVertices;
- LPD3DTRIANGLE lpTriangle;
- LPD3DLINE lpLine;
- LPD3DSTATE lpState;
- BOOL fDeviceFound = FALSE;
- DWORD dwDeviceBitDepth = 0UL;
- GUID guidDevice;
- char szDeviceName[256];
- char szDeviceDesc[256];
- D3DDEVICEDESC d3dHWDeviceDesc;
- D3DTEXTUREHANDLE hTexture, hGTexture;
- HDC ddBackDC;
- BOOL D3DACTIVE;
- BOOL VMFORMAT565;
- BOOL STARTCONV555;
- BOOL HANDLECHANGED;
- #define NUM_INSTRUCTIONS 5UL
- #define NUM_STATES 20UL
- #define NUM_PROCESSVERTICES 1UL
- void RenderFSRect(DWORD Color);
- void d3dDownLoadTexture(int i, int w, int h, LPVOID tptr);
- BOOL d3dAllocTexture(int i, int w, int h);
- void d3dSetTexture(LPVOID tptr, int w, int h);
- void RenderShadowClip (TModel*, float, float, float, float, float, float, int, float, float);
- void ResetTextureMap();
- int WaterAlphaL = 255;
- int d3dTexturesMem;
- int d3dLastTexture;
- int d3dMemUsageCount;
- int d3dMemLoaded;
- int GVCnt;
- BOOL LINEARFILTER = TRUE;
- int zs;
- float SunLight;
- float TraceK,SkyTraceK,FogYGrad,FogYBase;;
- int SunScrX, SunScrY;
- int SkySumR, SkySumG, SkySumB;
- int LowHardMemory;
- int lsw;
- int vFogT[1024];
- BOOL SmallFont;
- typedef struct _d3dmemmap {
- int cpuaddr, size, lastused;
- LPDIRECTDRAWSURFACE lpddTexture;
- D3DTEXTUREHANDLE hTexture;
- } Td3dmemmap;
- #define d3dmemmapsize 128
- Td3dmemmap d3dMemMap[d3dmemmapsize+2];
- WORD conv_555(WORD c)
- {
- return (c & 31) + ( (c & 0xFFE0) >> 1 );
- }
- void conv_pic555(TPicture &pic)
- {
- if (!HARD3D) return;
- for (int y=0; y<pic.H; y++)
- for (int x=0; x<pic.W; x++)
- *(pic.lpImage + x + y*pic.W) = conv_555(*(pic.lpImage + x + y*pic.W));
- }
- void CalcFogLevel_Gradient(Vector3d v)
- {
- FogYBase = CalcFogLevel(v);
- if (FogYBase>0) {
- v.y+=800;
- FogYGrad = (CalcFogLevel(v) - FogYBase) / 800.f;
- } else FogYGrad=0;
- }
- void Hardware_ZBuffer(BOOL bl)
- {
- if (!bl) {
- DDBLTFX ddbltfx;
- ddbltfx.dwSize = sizeof( DDBLTFX );
- ddbltfx.dwFillDepth = 0x0000;
- lpddZBuffer->Blt( NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &ddbltfx );
- }
- }
- void d3dClearBuffers()
- {
- DDBLTFX ddbltfx;
- ddbltfx.dwSize = sizeof( DDBLTFX );
-
- if (VMFORMAT565) ddbltfx.dwFillColor = (SkyR>>3)*32*32*2 + (SkyG>>2)*32 + (SkyB>>3);
- else ddbltfx.dwFillColor = (SkyR>>3)*32*32 + (SkyG>>3)*32 + (SkyB>>3);
- lpddBack->Blt( NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx );
-
- ddbltfx.dwSize = sizeof( DDBLTFX );
- ddbltfx.dwFillDepth = 0x0000;
- lpddZBuffer->Blt( NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &ddbltfx );
- }
- void d3dStartBuffer()
- {
- ZeroMemory(&d3dExeBufDesc, sizeof(d3dExeBufDesc));
- d3dExeBufDesc.dwSize = sizeof(d3dExeBufDesc);
- hRes = lpd3dExecuteBuffer->Lock( &d3dExeBufDesc );
- if (FAILED(hRes)) DoHalt("Error locking execute buffer");
- lpVertex = (LPD3DTLVERTEX)d3dExeBufDesc.lpData;
- }
- void d3dStartBufferG()
- {
- ZeroMemory(&d3dExeBufDescG, sizeof(d3dExeBufDescG));
- d3dExeBufDescG.dwSize = sizeof(d3dExeBufDescG);
- hRes = lpd3dExecuteBufferG->Lock( &d3dExeBufDescG );
- if (FAILED(hRes)) DoHalt("Error locking execute buffer");
- GVCnt = 0;
- hGTexture = -1;
- lpVertexG = (LPD3DTLVERTEX)d3dExeBufDescG.lpData;
- lpInstructionG = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDescG.lpData + 400*3);
- lpInstructionG->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstructionG->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstructionG->wCount = 1U;
- lpInstructionG++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstructionG;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = 400*3;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
-
- lpInstructionG = (LPD3DINSTRUCTION)lpProcessVertices;
- if (!LINEARFILTER) {
- lpInstructionG->bOpcode = D3DOP_STATERENDER;
- lpInstructionG->bSize = sizeof(D3DSTATE);
- lpInstructionG->wCount = 2;
- lpInstructionG++;
- lpState = (LPD3DSTATE)lpInstructionG;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpInstructionG = (LPD3DINSTRUCTION)lpState;
- }
-
- if (FOGENABLE) {
- lpInstructionG->bOpcode = D3DOP_STATERENDER;
- lpInstructionG->bSize = sizeof(D3DSTATE);
- lpInstructionG->wCount = 1;
- lpInstructionG++;
- lpState = (LPD3DSTATE)lpInstructionG;
- lpState->drstRenderStateType = D3DRENDERSTATE_FOGCOLOR;
- lpState->dwArg[0] = CurFogColor;
-
- lpState++;
- lpInstructionG = (LPD3DINSTRUCTION)lpState;
- }
-
- }
- void d3dStartBufferGBMP()
- {
- ZeroMemory(&d3dExeBufDescG, sizeof(d3dExeBufDescG));
- d3dExeBufDescG.dwSize = sizeof(d3dExeBufDescG);
- hRes = lpd3dExecuteBufferG->Lock( &d3dExeBufDescG );
- if (FAILED(hRes)) DoHalt("Error locking execute buffer");
- GVCnt = 0;
- hGTexture = -1;
- lpVertexG = (LPD3DTLVERTEX)d3dExeBufDescG.lpData;
- lpInstructionG = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDescG.lpData + 400*3);
- lpInstructionG->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstructionG->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstructionG->wCount = 1U;
- lpInstructionG++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstructionG;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = 400*3;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
-
- lpInstructionG = (LPD3DINSTRUCTION)lpProcessVertices;
-
- lpInstructionG->bOpcode = D3DOP_STATERENDER;
- lpInstructionG->bSize = sizeof(D3DSTATE);
- if (FOGENABLE) lpInstructionG->wCount = 5;
- else lpInstructionG->wCount = 4;
- lpInstructionG++;
- lpState = (LPD3DSTATE)lpInstructionG;
- lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHATESTENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_NEAREST;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_NEAREST;
- lpState++;
- if (FOGENABLE) {
- lpState->drstRenderStateType = D3DRENDERSTATE_FOGCOLOR;
- lpState->dwArg[0] = CurFogColor;
- /*if (UNDERWATER) lpState->dwArg[0] = 0x00004560;
- else lpState->dwArg[0] = 0x00606065;*/
- lpState++;
- }
- lpInstructionG = (LPD3DINSTRUCTION)lpState;
- LINEARFILTER = FALSE;
- }
- void d3dEndBufferG(BOOL ColorKey)
- {
- if (!lpVertexG) return;
- if (ColorKey) {
- lpInstructionG->bOpcode = D3DOP_STATERENDER;
- lpInstructionG->bSize = sizeof(D3DSTATE);
- lpInstructionG->wCount = 4;
- lpInstructionG++;
-
- lpState = (LPD3DSTATE)lpInstructionG;
- lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHATESTENABLE;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpInstructionG = (LPD3DINSTRUCTION)lpState;
- }
-
- lpInstructionG->bOpcode = D3DOP_EXIT;
- lpInstructionG->bSize = 0UL;
- lpInstructionG->wCount = 0U;
- lpInstructionG = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDescG.lpData + 400*3);
- lpInstructionG->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstructionG->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstructionG->wCount = 1U;
- lpInstructionG++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstructionG;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = GVCnt;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
- lpd3dExecuteBufferG->Unlock( );
- dFacesCount+=GVCnt/3;
- lpInstructionG = NULL;
- lpVertexG = NULL;
- GVCnt = 0;
-
- hRes = lpd3dDevice->Execute(lpd3dExecuteBufferG, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
- LINEARFILTER = TRUE;
-
- }
- void d3dFlushBuffer(int fproc1, int fproc2)
- {
- BOOL ColorKey = (fproc2>0);
- lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + 1024*3);
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
-
- lpInstruction->wCount = 3;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = hTexture;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstruction->wCount = 1U;
- lpInstruction++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = (fproc1+fproc2)*3;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
- lpInstruction->bOpcode = D3DOP_TRIANGLE;
- lpInstruction->bSize = sizeof(D3DTRIANGLE);
- lpInstruction->wCount = fproc1;
- lpInstruction++;
- lpTriangle = (LPD3DTRIANGLE)lpInstruction;
-
- int ii = 0;
- for (int i=0; i<fproc1; i++) {
- lpTriangle->wV1 = ii++;
- lpTriangle->wV2 = ii++;
- lpTriangle->wV3 = ii++;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- }
- lpInstruction = (LPD3DINSTRUCTION)lpTriangle;
- if (ColorKey) {
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 4;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHATESTENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_NEAREST;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_NEAREST;
- lpState++;
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_TRIANGLE;
- lpInstruction->bSize = sizeof(D3DTRIANGLE);
- lpInstruction->wCount = fproc2;
- lpInstruction++;
- lpTriangle = (LPD3DTRIANGLE)lpInstruction;
- for (i=0; i<fproc2; i++) {
- lpTriangle->wV1 = ii++;
- lpTriangle->wV2 = ii++;
- lpTriangle->wV3 = ii++;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- }
- lpInstruction = (LPD3DINSTRUCTION)lpTriangle;
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 4;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHATESTENABLE;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- }
-
- lpInstruction->bOpcode = D3DOP_EXIT;
- lpInstruction->bSize = 0UL;
- lpInstruction->wCount = 0U;
- lpd3dExecuteBuffer->Unlock( );
- LINEARFILTER = TRUE;
-
- hRes = lpd3dDevice->Execute(lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
- //if (FAILED(hRes)) DoHalt("Error execute buffer");
- dFacesCount+=fproc1+fproc2;
- }
- DWORD BitDepthToFlags( DWORD dwBitDepth )
- {
- switch( dwBitDepth ) {
- case 1UL: return DDBD_1;
- case 2UL: return DDBD_2;
- case 4UL: return DDBD_4;
- case 8UL: return DDBD_8;
- case 16UL: return DDBD_16;
- case 24UL: return DDBD_24;
- case 32UL: return DDBD_32;
- default : return 0UL;
- }
- }
- DWORD FlagsToBitDepth( DWORD dwFlags )
- {
- if (dwFlags & DDBD_1) return 1UL;
- else if (dwFlags & DDBD_2) return 2UL;
- else if (dwFlags & DDBD_4) return 4UL;
- else if (dwFlags & DDBD_8) return 8UL;
- else if (dwFlags & DDBD_16) return 16UL;
- else if (dwFlags & DDBD_24) return 24UL;
- else if (dwFlags & DDBD_32) return 32UL;
- else return 0UL;
- }
- HRESULT FillExecuteBuffer_State( LPDIRECT3DEXECUTEBUFFER lpd3dExecuteBuffer)
- {
- HRESULT hRes;
- D3DEXECUTEBUFFERDESC d3dExeBufDesc;
- LPD3DINSTRUCTION lpInstruction;
- LPD3DSTATE lpState;
-
- ZeroMemory(&d3dExeBufDesc, sizeof(d3dExeBufDesc));
- d3dExeBufDesc.dwSize = sizeof(d3dExeBufDesc);
- hRes = lpd3dExecuteBuffer->Lock( &d3dExeBufDesc );
- if (FAILED(hRes)) {
- PrintLog( "Error locking execute buffer");
- return hRes;
- }
-
-
- lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + 1024*3);
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 24;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_ZENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ZWRITEENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
-
- lpState->drstRenderStateType = D3DRENDERSTATE_ZFUNC;
- lpState->dwArg[0] = D3DCMP_GREATEREQUAL;
- lpState++;
-
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREPERSPECTIVE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAPBLEND;
- if (OPT_ALPHA_COLORKEY) lpState->dwArg[0] = D3DTBLEND_MODULATEALPHA;
- else lpState->dwArg[0] = D3DTBLEND_MODULATE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_SHADEMODE;
- lpState->dwArg[0] = D3DSHADE_GOURAUD;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_DITHERENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_CULLMODE;
- lpState->dwArg[0] = D3DCULL_NONE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_BLENDENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
- lpState->dwArg[0] = FALSE;
- lpState++;
-
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHABLENDENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHATESTENABLE;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHAREF;
- lpState->dwArg[0] = 0;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHAFUNC;
- lpState->dwArg[0] = D3DCMP_GREATEREQUAL;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_SPECULARENABLE;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_FOGENABLE;
- lpState->dwArg[0] = FOGENABLE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_FOGCOLOR;
- lpState->dwArg[0] = 0x00606070;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_SRCBLEND;
- lpState->dwArg[0] = D3DBLEND_SRCALPHA;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_DESTBLEND;
- lpState->dwArg[0] = D3DBLEND_INVSRCALPHA;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_STIPPLEDALPHA;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_WRAPU;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_WRAPV;
- lpState->dwArg[0] = FALSE;
- lpState++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_EXIT;
- lpInstruction->bSize = 0UL;
- lpInstruction->wCount = 0U;
- lpd3dExecuteBuffer->Unlock( );
- //PrintLog( "Execute buffer filled successfully\n" );
- return DD_OK;
- }
- void SetRenderStates(BOOL ZWRITE, int DST_BLEND)
- {
- HRESULT hRes;
- D3DEXECUTEBUFFERDESC d3dExeBufDesc;
- LPD3DINSTRUCTION lpInstruction;
- LPD3DSTATE lpState;
-
- ZeroMemory(&d3dExeBufDesc, sizeof(d3dExeBufDesc));
- d3dExeBufDesc.dwSize = sizeof(d3dExeBufDesc);
- hRes = lpd3dExecuteBuffer->Lock( &d3dExeBufDesc );
- if (FAILED(hRes)) {
- PrintLog( "Error locking execute buffer");
- return;
- }
-
-
- lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + 1024*3);
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 2;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
-
- lpState->drstRenderStateType = D3DRENDERSTATE_ZWRITEENABLE;
- lpState->dwArg[0] = ZWRITE;
- lpState++;
-
- lpState->drstRenderStateType = D3DRENDERSTATE_DESTBLEND;
- lpState->dwArg[0] = DST_BLEND;
- lpState++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_EXIT;
- lpInstruction->bSize = 0UL;
- lpInstruction->wCount = 0U;
- lpd3dExecuteBuffer->Unlock( );
- lpd3dDevice->Execute( lpd3dExecuteBuffer,
- lpd3dViewport,
- D3DEXECUTE_UNCLIPPED );
- }
- HRESULT WINAPI EnumDeviceCallback(
- LPGUID lpGUID,
- LPSTR lpszDeviceDesc,
- LPSTR lpszDeviceName,
- LPD3DDEVICEDESC lpd3dHWDeviceDesc,
- LPD3DDEVICEDESC lpd3dSWDeviceDesc,
- LPVOID lpUserArg )
- {
- LPD3DDEVICEDESC lpd3dDeviceDesc;
- wsprintf(logt,"ENUMERATE: DDesc: %s DName: %s\n", lpszDeviceDesc, lpszDeviceName);
- //PrintLog(logt);
- if( !lpd3dHWDeviceDesc->dcmColorModel )
- return D3DENUMRET_OK; // we don't need SW rasterizer
- lpd3dDeviceDesc = lpd3dHWDeviceDesc;
- if( (lpd3dDeviceDesc->dwDeviceRenderBitDepth & dwDeviceBitDepth) == 0UL )
- return D3DENUMRET_OK;
- if( !(lpd3dDeviceDesc->dpcTriCaps.dwShadeCaps & D3DPSHADECAPS_COLORGOURAUDRGB) )
- return D3DENUMRET_OK;
- fDeviceFound = TRUE;
- CopyMemory( &guidDevice, lpGUID, sizeof(GUID) );
- strcpy( szDeviceDesc, lpszDeviceDesc );
- strcpy( szDeviceName, lpszDeviceName );
- CopyMemory( &d3dHWDeviceDesc, lpd3dHWDeviceDesc, sizeof(D3DDEVICEDESC) );
- return D3DENUMRET_CANCEL;
- }
- HRESULT CreateDirect3D( HWND hwnd )
- {
- HRESULT hRes;
- PrintLog("\n");
- PrintLog("=== Init Direct3D ===\n" );
- hRes = lpDD->SetCooperativeLevel( hwnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN );
- if (FAILED(hRes)) DoHalt("Error setting cooperative level\n");
- hRes = lpDD->SetDisplayMode( WinW, WinH, 16 );
- if (FAILED(hRes)) {
- PrintLog("DDraw: can't set selected video mode\n");
- WinW = 640;
- WinH = 480;
- OptRes = 3;
- hRes = lpDD->SetDisplayMode( WinW, WinH, 16 );
- }
- if (FAILED(hRes)) DoHalt("Error setting display mode\n");
- wsprintf(logt, "Set Display mode %dx%d, 16bpp\n", WinW, WinH);
- PrintLog(logt);
-
- hRes = lpDD->QueryInterface( IID_IDirect3D, (LPVOID*) &lpd3d);
- if (FAILED(hRes)) DoHalt("Error quering Direct3D interface\n");
- PrintLog("QueryInterface: Ok. (IID_IDirect3D)\n");
-
- DDSURFACEDESC ddsd;
- ZeroMemory(&ddsd, sizeof(ddsd));
- ddsd.dwSize = sizeof(ddsd);
- ddsd.dwFlags = DDSD_CAPS;
- ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
- hRes = lpDD->CreateSurface( &ddsd, &lpddPrimary, NULL );
- if (FAILED(hRes)) DoHalt( "Error creating primary surface\n");
-
- ZeroMemory(&ddsd, sizeof(ddsd) );
- ddsd.dwSize = sizeof(ddsd);
- hRes = lpddPrimary->GetSurfaceDesc( &ddsd);
- if (FAILED(hRes)) DoHalt("Error getting surface description\n");
- PrintLog("CreateSurface: Ok. (Primary)\n");
- dwDeviceBitDepth = BitDepthToFlags(ddsd.ddpfPixelFormat.dwRGBBitCount);
- fDeviceFound = FALSE;
- hRes = lpd3d->EnumDevices( EnumDeviceCallback, &fDeviceFound);
- if (FAILED(hRes) ) DoHalt("EnumDevices failed.\n");
- if (!fDeviceFound ) DoHalt("No devices found.\n");
- PrintLog("EnumDevices: Ok.\n");
-
- return DD_OK;
- }
- HRESULT CreateDevice(DWORD dwWidth, DWORD dwHeight)
- {
- DDSURFACEDESC ddsd;
- HRESULT hRes;
- DWORD dwZBufferBitDepth;
-
- ZeroMemory(&ddsd, sizeof(ddsd));
- ddsd.dwSize = sizeof(ddsd);
- ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
- ddsd.dwWidth = dwWidth;
- ddsd.dwHeight = dwHeight;
- ddsd.ddsCaps.dwCaps = DDSCAPS_3DDEVICE | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
- hRes = lpDD->CreateSurface( &ddsd, &lpddBack, NULL);
- if (FAILED(hRes)) DoHalt("Error creating back buffer surface\n");
- PrintLog("CreateSurface: Ok. (BackBuffer)\n");
-
- if( d3dHWDeviceDesc.dwDeviceZBufferBitDepth != 0UL ) {
- dwZBufferBitDepth = FlagsToBitDepth( d3dHWDeviceDesc.dwDeviceZBufferBitDepth );
- ZeroMemory(&ddsd, sizeof(ddsd));
- ddsd.dwSize = sizeof(ddsd);
- ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_ZBUFFERBITDEPTH;
- ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY;
- ddsd.dwWidth = dwWidth;
- ddsd.dwHeight = dwHeight;
- ddsd.dwZBufferBitDepth = 16;//dwZBufferBitDepth;
- hRes = lpDD->CreateSurface( &ddsd, &lpddZBuffer, NULL);
- /*
- if (FAILED(hRes)) {
- ddsd.dwZBufferBitDepth = 16;//dwZBufferBitDepth;
- hRes = lpDD->CreateSurface( &ddsd, &lpddZBuffer, NULL);
- PrintLog("Z-Buffer: 16 bit\n");
- } else
- PrintLog("Z-Buffer: 32 bit\n");
- */
- if (FAILED(hRes)) DoHalt("Error creating z-buffer\n");
-
- hRes = lpddBack->AddAttachedSurface( lpddZBuffer );
- if (FAILED(hRes)) DoHalt("Error attaching z-buffer\n");
- PrintLog("CreateSurface: Ok. (Z-buffer)\n");
- }
-
- hRes = lpddBack->QueryInterface( guidDevice, (LPVOID*) &lpd3dDevice);
- if (FAILED(hRes)) DoHalt("Error quering device interface\n");
- PrintLog("QueryInterface: Ok. (lpd3dDevice)\n");
- return DD_OK;
- }
- HRESULT CreateScene(void)
- {
- HRESULT hRes;
- DWORD dwVertexSize;
- DWORD dwInstructionSize;
- DWORD dwExecuteBufferSize;
- D3DEXECUTEBUFFERDESC d3dExecuteBufferDesc;
- D3DEXECUTEDATA d3dExecuteData;
- hRes = lpd3d->CreateViewport( &lpd3dViewport, NULL );
- if (FAILED(hRes)) DoHalt("Error creating viewport\n");
- PrintLog("CreateViewport: Ok.\n");
- hRes = lpd3dDevice->AddViewport( lpd3dViewport );
- if (FAILED(hRes)) DoHalt("Error adding viewport\n");
- //PrintLog("AddViewport: Ok.\n");
-
- D3DVIEWPORT d3dViewport;
- ZeroMemory(&d3dViewport, sizeof(d3dViewport));
- d3dViewport.dwSize = sizeof(d3dViewport);
- d3dViewport.dwX = 0UL;
- d3dViewport.dwY = 0UL;
- d3dViewport.dwWidth = (DWORD)WinW;
- d3dViewport.dwHeight = (DWORD)WinH;
- d3dViewport.dvScaleX = D3DVAL((float)d3dViewport.dwWidth / 2.0);
- d3dViewport.dvScaleY = D3DVAL((float)d3dViewport.dwHeight / 2.0);
- d3dViewport.dvMaxX = D3DVAL(1.0);
- d3dViewport.dvMaxY = D3DVAL(1.0);
-
- lpd3dViewport->SetViewport( &d3dViewport);
-
- //=========== CREATING EXECUTE BUFFER ======================//
- dwVertexSize = ((1024*3) * sizeof(D3DVERTEX));
- dwInstructionSize = (NUM_INSTRUCTIONS * sizeof(D3DINSTRUCTION)) +
- (NUM_STATES * sizeof(D3DSTATE)) +
- (NUM_PROCESSVERTICES * sizeof(D3DPROCESSVERTICES)) +
- ((1024) * sizeof(D3DTRIANGLE));
- dwExecuteBufferSize = dwVertexSize + dwInstructionSize;
- ZeroMemory(&d3dExecuteBufferDesc, sizeof(d3dExecuteBufferDesc));
- d3dExecuteBufferDesc.dwSize = sizeof(d3dExecuteBufferDesc);
- d3dExecuteBufferDesc.dwFlags = D3DDEB_BUFSIZE;
- d3dExecuteBufferDesc.dwBufferSize = dwExecuteBufferSize;
- hRes = lpd3dDevice->CreateExecuteBuffer( &d3dExecuteBufferDesc, &lpd3dExecuteBuffer, NULL);
- if (FAILED(hRes)) DoHalt( "Error creating execute buffer\n");
- PrintLog("CreateExecuteBuffer: Ok.\n");
- ZeroMemory(&d3dExecuteData, sizeof(d3dExecuteData));
- d3dExecuteData.dwSize = sizeof(d3dExecuteData);
- d3dExecuteData.dwVertexCount = 1024;
- d3dExecuteData.dwInstructionOffset = dwVertexSize;
- d3dExecuteData.dwInstructionLength = dwInstructionSize;
- hRes = lpd3dExecuteBuffer->SetExecuteData( &d3dExecuteData );
- if (FAILED(hRes)) DoHalt("Error setting execute data\n");
- //=========== CREATING EXECUTE BUFFER ======================//
- dwVertexSize = ((400*3) * sizeof(D3DVERTEX));
- dwInstructionSize = (300 * sizeof(D3DINSTRUCTION)) +
- (300 * sizeof(D3DSTATE)) +
- (10 * sizeof(D3DPROCESSVERTICES)) +
- ((400) * sizeof(D3DTRIANGLE));
- dwExecuteBufferSize = dwVertexSize + dwInstructionSize;
- ZeroMemory(&d3dExecuteBufferDesc, sizeof(d3dExecuteBufferDesc));
- d3dExecuteBufferDesc.dwSize = sizeof(d3dExecuteBufferDesc);
- d3dExecuteBufferDesc.dwFlags = D3DDEB_BUFSIZE;
- d3dExecuteBufferDesc.dwBufferSize = dwExecuteBufferSize;
- hRes = lpd3dDevice->CreateExecuteBuffer( &d3dExecuteBufferDesc, &lpd3dExecuteBufferG, NULL);
- if (FAILED(hRes)) DoHalt( "Error creating execute buffer\n");
- PrintLog("CreateExecuteBuffer: Ok.\n");
- ZeroMemory(&d3dExecuteData, sizeof(d3dExecuteData));
- d3dExecuteData.dwSize = sizeof(d3dExecuteData);
- d3dExecuteData.dwVertexCount = 400;
- d3dExecuteData.dwInstructionOffset = dwVertexSize;
- d3dExecuteData.dwInstructionLength = dwInstructionSize;
- hRes = lpd3dExecuteBufferG->SetExecuteData( &d3dExecuteData );
- if (FAILED(hRes)) DoHalt("Error setting execute data\n");
-
- FillExecuteBuffer_State(lpd3dExecuteBuffer);
- hRes = lpd3dDevice->Execute( lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
-
- return DD_OK;
- }
- void Init3DHardware()
- {
- HARD3D = TRUE;
- PrintLog("\n");
- PrintLog("==Init Direct Draw==\n");
- HRESULT hres;
- hres = DirectDrawCreate( NULL, &lpDD, NULL );
- if( hres != DD_OK ) {
- wsprintf(logt, "DirectDrawCreate Error: %Xh\n", hres);
- DoHalt(logt); }
- PrintLog("DirectDrawCreate: Ok\n");
-
- DirectActive = TRUE;
- }
- void d3dDetectCaps()
- {
- for (int t=0; t<d3dmemmapsize; t++) {
- if (!d3dAllocTexture(t, 256, 256)) break;
- }
- d3dTexturesMem = t*256*256*2;
- d3dDownLoadTexture(0, 256, 256, SkyPic);
- DWORD T;
- T = timeGetTime();
- for (t=0; t<10; t++) d3dDownLoadTexture(0, 256, 256, SkyPic);
- T = timeGetTime() - T;
-
- wsprintf(logt, "DETECTED: Texture memory : %dK.\n", d3dTexturesMem>>10);
- PrintLog(logt);
- ResetTextureMap();
- wsprintf(logt, "DETECTED: Texture transfer speed: %dK/sec.\n", 128*10000 / T);
- PrintLog(logt);
- DDSURFACEDESC ddsd;
- ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- if( lpddBack->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
- lpddBack->Unlock(ddsd.lpSurface);
- if (ddsd.ddpfPixelFormat.dwGBitMask == 0x3E0) VMFORMAT565=FALSE; else VMFORMAT565=TRUE;
- if (VMFORMAT565)
- PrintLog("DETECTED: PixelFormat RGB565\n");
- else {
- PrintLog("DETECTED: PixelFormat RGB555\n");
- if (!STARTCONV555) {
- STARTCONV555 = TRUE;
- conv_pic555(PausePic);
- conv_pic555(ExitPic);
- conv_pic555(TrophyExit);
- conv_pic555(MapPic);
- conv_pic555(TrophyPic);
- for (int c=0; c<20; c++)
- if (DinoInfo[c].CallIcon.W)
- conv_pic555(DinoInfo[c].CallIcon);
- for (int w=0; w<TotalW; w++)
- if (Weapon.BulletPic[w].W)
- conv_pic555(Weapon.BulletPic[w]);
- }
- }
-
-
- }
- void d3dTestDrawTri(float color, float tx)
- {
- d3dStartBuffer();
-
- lpVertex->sx = 0;
- lpVertex->sy = 0;
- lpVertex->sz = _ZSCALE / 10;
- lpVertex->rhw = 1.f;
- lpVertex->color = color;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = tx;
- lpVertex->tv = tx;
- lpVertex++;
- lpVertex->sx = 100;
- lpVertex->sy = 0;
- lpVertex->sz = _ZSCALE / 10;
- lpVertex->rhw = 1.f;
- lpVertex->color = color;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = tx;
- lpVertex->tv = tx;
- lpVertex++;
- lpVertex->sx = 0;
- lpVertex->sy = 100;
- lpVertex->sz = _ZSCALE / 10;
- lpVertex->rhw = 1.f;
- lpVertex->color = color;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = tx;
- lpVertex->tv = tx;
- lpVertex++;
-
- d3dFlushBuffer(0, 1);
-
- }
- int d3dTestAlpha()
- {
- int RF = 0;
-
- lpd3dDevice->BeginScene( );
- // RenderSkyPlane();
- d3dSetTexture(TFX_SPECULAR.lpImage, TFX_SPECULAR.W, TFX_SPECULAR.W);
-
- DDBLTFX ddbltfx;
- ddbltfx.dwSize = sizeof( DDBLTFX );
- ddbltfx.dwFillColor = 0xFFFF;
- lpddBack->Blt( NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx );
- FillExecuteBuffer_State(lpd3dExecuteBuffer);
- hRes = lpd3dDevice->Execute( lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
- //========= test opacity ==========//
-
- //d3dSetTexture(TFX_SPECULAR.lpImage, TFX_SPECULAR.W, TFX_SPECULAR.W);
- SetRenderStates(FALSE, D3DBLEND_INVSRCALPHA);
- d3dTestDrawTri(0xFFFFFFFF, 0.0);
-
-
- CopyBackToDIB();
- if (*((WORD*)lpVideoBuf)==0) PrintLog("[OPACITY: Failed] ");
- else { PrintLog("[OPACITY: Ok.] "); RF+=4; }
- lpd3dDevice->EndScene( );
- lpd3dDevice->BeginScene( );
- /*
- ShowVideo();
- lpd3dDevice->BeginScene( );
- Sleep(1000);
- */
- //=========== test transparent mode =============//
- lpd3dDevice->BeginScene( );
- ddbltfx.dwSize = sizeof( DDBLTFX );
- ddbltfx.dwFillColor = 0x0000;
- lpddBack->Blt( NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx );
- d3dTestDrawTri(0x00FFFFFF, 0.5);
-
- CopyBackToDIB();
- if (*((WORD*)lpVideoBuf)!=0) PrintLog("[TRANSPARENT: Failed] ");
- else { PrintLog("[TRANSPARENT: Ok.] "); RF+=2; }
- lpd3dDevice->EndScene( );
- lpd3dDevice->BeginScene( );
- /*
- ShowVideo();
- lpd3dDevice->BeginScene( );
- Sleep(1000);
- */
- //=========== test env map ==================//
- SetRenderStates(FALSE, D3DBLEND_ONE);
- lpd3dDevice->BeginScene( );
- ddbltfx.dwSize = sizeof( DDBLTFX );
- ddbltfx.dwFillColor = 0x0000;
- lpddBack->Blt( NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx );
- d3dTestDrawTri(0x00FFFFFF, 0.5);
- CopyBackToDIB();
- if (*((WORD*)lpVideoBuf)!=0) PrintLog("[ENV.BLEND : Failed]\n");
- else { PrintLog("[ENV.BLEND : Ok.]\n"); RF+=1; }
- lpd3dDevice->EndScene( );
- lpd3dDevice->BeginScene( );
- /*
- ShowVideo();
- lpd3dDevice->BeginScene( );
- Sleep(1000);
- */
- SetRenderStates(TRUE, D3DBLEND_INVSRCALPHA);
- lpd3dDevice->EndScene( );
- return RF;
- }
- void Activate3DHardware()
- {
- SetVideoMode(WinW,WinH);
- HRESULT hRes = CreateDirect3D(hwndMain);
- if (FAILED(hRes)) DoHalt("CreateDirect3D Failed.\n");
- hRes = CreateDevice((DWORD)WinW, (DWORD)WinH);
- if (FAILED(hRes)) DoHalt("Create Device Failed.\n");
- d3dClearBuffers();
- hRes = CreateScene();
- if (FAILED(hRes)) DoHalt("CreateScene Failed.\n");
- d3dDetectCaps();
- OPT_ALPHA_COLORKEY=FALSE;
- PrintLog("TEST COLOR KEY: ");
- int r1 = d3dTestAlpha();
-
- OPT_ALPHA_COLORKEY=TRUE;
- PrintLog("TEST ALPHA KEY: ");
- int r2 = d3dTestAlpha();
- OPT_ALPHA_COLORKEY = (r2>=r1);
- if (OPT_ALPHA_COLORKEY) PrintLog("ALPHA KEY mode selected.\n");
- else PrintLog("COLOR KEY mode selected.\n");
-
- hRes = lpd3dDevice->BeginScene( );
- if (OptText==0) LOWRESTX = TRUE;
- if (OptText==1) LOWRESTX = FALSE;
- if (OptText==2) LOWRESTX = FALSE;
- d3dMemLoaded = 0;
-
- D3DACTIVE = TRUE;
-
- d3dLastTexture = d3dmemmapsize+1;
- PrintLog("=== Direct3D started === \n");
- PrintLog("\n");
- }
- void ResetTextureMap()
- {
- d3dEndBufferG(FALSE);
- d3dMemUsageCount = 0;
- //d3dMemLoaded = 0;
- d3dLastTexture = d3dmemmapsize+1;
- for (int m=0; m<d3dmemmapsize+2; m++) {
- d3dMemMap[m].lastused = 0;
- d3dMemMap[m].cpuaddr = 0;
- if (d3dMemMap[m].lpddTexture) {
- d3dMemMap[m].lpddTexture->Release();
- d3dMemMap[m].lpddTexture = NULL;
- }
- }
- }
- void ShutDown3DHardware()
- {
- D3DACTIVE = FALSE;
-
- if (lpd3dDevice)
- hRes = lpd3dDevice->EndScene();
-
- ResetTextureMap();
- lpInstructionG = NULL;
- lpVertexG = NULL;
- if (NULL != lpd3dExecuteBuffer) {
- lpd3dExecuteBuffer->Release( );
- lpd3dExecuteBufferG->Release( );
- lpd3dExecuteBuffer = NULL;
- }
- if (NULL != lpd3dViewport) {
- lpd3dViewport->Release( );
- lpd3dViewport = NULL;
- }
- if (NULL != lpd3dDevice) {
- lpd3dDevice->Release( );
- lpd3dDevice = NULL;
- }
- if (NULL != lpddZBuffer) {
- lpddZBuffer->Release( );
- lpddZBuffer = NULL;
- }
-
- if (NULL != lpddBack) {
- lpddBack->Release();
- lpddBack = NULL;
- }
- if (NULL != lpddPrimary) {
- lpddPrimary->Release( );
- lpddPrimary = NULL;
- }
- if (NULL != lpd3d) {
- lpd3d->Release( );
- lpd3d = NULL;
- }
- lpDD->SetCooperativeLevel( hwndMain, DDSCL_NORMAL);
- }
- void InsertFxMM(int m)
- {
- for (int mm=d3dmemmapsize-1; mm>m; mm--)
- d3dMemMap[m] = d3dMemMap[m-1];
- }
- BOOL d3dAllocTexture(int i, int w, int h)
- {
- DDSURFACEDESC ddsd;
- DDPIXELFORMAT ddpf;
- ZeroMemory( &ddpf, sizeof(DDPIXELFORMAT) );
- ddpf.dwSize = sizeof(DDPIXELFORMAT);
- ddpf.dwFlags = DDPF_RGB;
- if (OPT_ALPHA_COLORKEY) {
- ddpf.dwFlags |= DDPF_ALPHAPIXELS;
- ddpf.dwRGBAlphaBitMask = 0x8000;
- }
- ddpf.dwRGBBitCount = 16;
- ddpf.dwRBitMask = 0x7c00;
- ddpf.dwGBitMask = 0x3e0;
- ddpf.dwBBitMask = 0x1f;
- ZeroMemory(&ddsd, sizeof(ddsd));
- ddsd.dwSize = sizeof(ddsd);
- ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
- ddsd.dwWidth = w;
- ddsd.dwHeight = h;
- CopyMemory( &ddsd.ddpfPixelFormat, &ddpf, sizeof(DDPIXELFORMAT) );
- ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
- hRes = lpDD->CreateSurface( &ddsd, &d3dMemMap[i].lpddTexture, NULL);
- if (FAILED(hRes)) {
- d3dMemMap[i].lpddTexture = NULL;
- return FALSE; }
-
- DDCOLORKEY ddck;
- ddck.dwColorSpaceLowValue = ddck.dwColorSpaceHighValue = 0x0000;
- d3dMemMap[i].lpddTexture->SetColorKey(DDCKEY_SRCBLT, &ddck);
-
- return TRUE;
- }
- void d3dDownLoadTexture(int i, int w, int h, LPVOID tptr)
- {
- DDSURFACEDESC ddsd;
- ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
- ddsd.dwSize = sizeof(DDSURFACEDESC);
-
- if( d3dMemMap[i].lpddTexture->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
- CopyMemory( ddsd.lpSurface, tptr, w*h*2 );
- d3dMemMap[i].lpddTexture->Unlock( ddsd.lpSurface );
- IDirect3DTexture* Texture;
- if( d3dMemMap[i].lpddTexture->QueryInterface( IID_IDirect3DTexture, (LPVOID*)&Texture ) != S_OK ) return;
- if( Texture->GetHandle( lpd3dDevice, &d3dMemMap[i].hTexture ) != D3D_OK ) return;
- Texture->Release( );
- d3dMemMap[i].cpuaddr = (int) tptr;
- d3dMemMap[i].size = w*h*2;
- d3dMemLoaded+=w*h*2;
- //---------------------------------------------------------------------------
- }
- int DownLoadTexture(LPVOID tptr, int w, int h)
- {
- int textureSize = w*w*2;
- int fxm = 0;
- int m;
- //========== if no memory used ==========//
- if (!d3dMemMap[0].cpuaddr) {
- d3dAllocTexture(0, w, h);
- d3dDownLoadTexture(0, w, h, tptr);
- return 0;
- }
- //====== search for last used block and try to alloc next ============//
- for (m = 0; m < d3dmemmapsize; m++)
- if (!d3dMemMap[m].cpuaddr)
- if (d3dAllocTexture(m, w, h)) {
- d3dDownLoadTexture(m, w, h, tptr);
- return m;
- } else break;
-
-
- //====== search for unused texture and replace it with new ============//
- int unusedtime = 2;
- int rt = -1;
- for (m = 0; m < d3dmemmapsize; m++) {
- if (!d3dMemMap[m].cpuaddr) break;
- if (d3dMemMap[m].size != w*h*2) continue;
- int ut = d3dMemUsageCount - d3dMemMap[m].lastused;
-
- if (ut >= unusedtime) {
- unusedtime = ut;
- rt = m; }
- }
- if (rt!=-1) {
- d3dDownLoadTexture(rt, w, h, tptr);
- return rt;
- }
-
- ResetTextureMap();
- d3dAllocTexture(0, w, h);
- d3dDownLoadTexture(0, w, h, tptr);
- return 0;
- }
- void d3dSetTexture(LPVOID tptr, int w, int h)
- {
-
- if (d3dMemMap[d3dLastTexture].cpuaddr == (int)tptr) return;
- int fxm = -1;
- for (int m=0; m<d3dmemmapsize; m++) {
- if (d3dMemMap[m].cpuaddr == (int)tptr) { fxm = m; break; }
- if (!d3dMemMap[m].cpuaddr) break;
- }
- if (fxm==-1) fxm = DownLoadTexture(tptr, w, h);
- d3dMemMap[fxm].lastused = d3dMemUsageCount;
- hTexture = d3dMemMap[fxm].hTexture;
- d3dLastTexture = fxm;
-
- }
- float GetTraceK(int x, int y)
- {
-
- if (x<8 || y<8 || x>WinW-8 || y>WinH-8) return 0.f;
-
- float k = 0;
- DDSURFACEDESC ddsd;
- ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- if( lpddZBuffer->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) {
- return 0;
- }
- WORD CC = 200;
- int bw = (ddsd.lPitch>>1);
- if ( *((WORD*)ddsd.lpSurface + (y+0)*bw + x+0) < CC ) k+=1.f;
- if ( *((WORD*)ddsd.lpSurface + (y+10)*bw + x+0) < CC ) k+=1.f;
- if ( *((WORD*)ddsd.lpSurface + (y-10)*bw + x+0) < CC ) k+=1.f;
- if ( *((WORD*)ddsd.lpSurface + (y+0)*bw + x+10) < CC ) k+=1.f;
- if ( *((WORD*)ddsd.lpSurface + (y+0)*bw + x-10) < CC ) k+=1.f;
- if ( *((WORD*)ddsd.lpSurface + (y+8)*bw + x+8) < CC ) k+=1.f;
- if ( *((WORD*)ddsd.lpSurface + (y+8)*bw + x-8) < CC ) k+=1.f;
- if ( *((WORD*)ddsd.lpSurface + (y-8)*bw + x+8) < CC ) k+=1.f;
- if ( *((WORD*)ddsd.lpSurface + (y-8)*bw + x-8) < CC ) k+=1.f;
-
- lpddZBuffer->Unlock(ddsd.lpSurface);
- k/=9.f;
-
- DeltaFunc(TraceK, k, TimeDt / 1024.f);
- return TraceK;
- }
- void AddSkySum(WORD C)
- {
- int R,G,B;
- if (VMFORMAT565) {
- R = C>>11; G = (C>>5) & 63; B = C & 31;
- } else {
- R = C>>10; G = (C>>5) & 31; B = C & 31; C=C*2;
- }
-
- SkySumR += R*8;
- SkySumG += G*4;
- SkySumB += B*8;
- }
- float GetSkyK(int x, int y)
- {
- if (x<10 || y<10 || x>WinW-10 || y>WinH-10) return 0.5;
- SkySumR = 0;
- SkySumG = 0;
- SkySumB = 0;
- float k = 0;
- DDSURFACEDESC ddsd;
- ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- if( lpddBack->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) {
- return 0;
- }
-
- int bw = (ddsd.lPitch>>1);
- AddSkySum(*((WORD*)ddsd.lpSurface + (y+0)*bw + x+0));
- AddSkySum(*((WORD*)ddsd.lpSurface + (y+6)*bw + x+0));
- AddSkySum(*((WORD*)ddsd.lpSurface + (y-6)*bw + x+0));
- AddSkySum(*((WORD*)ddsd.lpSurface + (y+0)*bw + x+6));
- AddSkySum(*((WORD*)ddsd.lpSurface + (y+0)*bw + x-6));
- AddSkySum(*((WORD*)ddsd.lpSurface + (y+4)*bw + x+4));
- AddSkySum(*((WORD*)ddsd.lpSurface + (y+4)*bw + x-4));
- AddSkySum(*((WORD*)ddsd.lpSurface + (y-4)*bw + x+4));
- AddSkySum(*((WORD*)ddsd.lpSurface + (y-4)*bw + x-4));
-
- lpddBack->Unlock(ddsd.lpSurface);
-
- SkySumR-=SkyTR*9;
- SkySumG-=SkyTG*9;
- SkySumB-=SkyTB*9;
- k = (float)sqrt(SkySumR*SkySumR + SkySumG*SkySumG + SkySumB*SkySumB) / 9;
- if (k>80) k = 80;
- if (k< 0) k = 0;
- k = 1.0f - k/80.f;
- if (k<0.2) k=0.2f;
- if (OptDayNight==2) k=0.3 + k/2.75;
- DeltaFunc(SkyTraceK, k, (0.07f + (float)fabs(k-SkyTraceK)) * (TimeDt / 512.f) );
- return SkyTraceK;
- }
- void TryHiResTx()
- {
- int UsedMem = 0;
- for (int m=0; m<d3dmemmapsize; m++) {
- if (!d3dMemMap[m].cpuaddr) break;
- if (d3dMemMap[m].lastused+2>=d3dMemUsageCount)
- UsedMem+= d3dMemMap[m].size;
- }
- /*
- wsprintf(logt, "TOTALL: %d USED: %d", d3dTexturesMem, UsedMem);
- AddMessage(logt);
- */
- if (UsedMem*4 < (int)d3dTexturesMem)
- LOWRESTX = FALSE;
- }
- void ShowVideo()
- {
- /*
- char t[128];
- wsprintf(t, "T-mem loaded: %dK", d3dMemLoaded >> 10);
- if (d3dMemLoaded) AddMessage(t);
- */
- if (d3dMemLoaded > 200*1024) LowHardMemory++;
- else LowHardMemory=0;
- if (LowHardMemory>2) {
- LOWRESTX = TRUE;
- LowHardMemory = 0; }
- if (OptText==0) LOWRESTX = TRUE;
- if (OptText==1) LOWRESTX = FALSE;
- if (OptText==2)
- if (LOWRESTX && (Takt & 63)==0) TryHiResTx();
- if (UNDERWATER)
- RenderFSRect(CurFogColor+0x70000000);
-
- if (OptDayNight!=2)
- if (!UNDERWATER && (SunLight>1.0f) ) {
- RenderFSRect(0xFFFFC0 + ((int)SunLight<<24));
- }
-
- RenderHealthBar();
-
- d3dMemUsageCount++;
- d3dMemLoaded = 0;
- hRes = lpd3dDevice->EndScene();
- hRes = lpddPrimary->Blt( NULL, lpddBack, NULL, DDBLT_WAIT, NULL );
-
- d3dClearBuffers();
- hRes = lpd3dDevice->BeginScene( );
-
- }
- void CopyBackToDIB()
- {
- DDSURFACEDESC ddsd;
- ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- if( lpddBack->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
-
- WORD *lpVMem = (WORD*) ddsd.lpSurface;
- ddsd.lPitch/=2;
- for (int y=0; y<=256; y++)
- CopyMemory( (WORD*)lpVideoBuf + y*1024,
- lpVMem + y*ddsd.lPitch,
- 256*2);
-
- lpddBack->Unlock(ddsd.lpSurface);
- }
- void CopyHARDToDIB()
- {
- DDSURFACEDESC ddsd;
- ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- if( lpddPrimary->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
-
- WORD *lpVMem = (WORD*) ddsd.lpSurface;
- ddsd.lPitch/=2;
- for (int y=0; y<=WinH; y++)
- CopyMemory( (WORD*)lpVideoBuf + y*1024,
- lpVMem + y*ddsd.lPitch,
- WinW*2);
-
- lpddPrimary->Unlock(ddsd.lpSurface);
- }
- void FXPutBitMap(int x0, int y0, int w, int h, int smw, LPVOID lpData)
- {
- DDSURFACEDESC ddsd;
- ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- if( lpddBack->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
-
- WORD *lpVMem = (WORD*) ddsd.lpSurface;
- ddsd.lPitch/=2;
- lpVMem+=x0+y0 * ddsd.lPitch;
- for (int y=0; y<h; y++)
- CopyMemory( lpVMem + y*ddsd.lPitch, ((WORD*)lpData)+y*smw, w*2);
-
- lpddBack->Unlock(ddsd.lpSurface);
- }
- void DrawPicture(int x, int y, TPicture &pic)
- {
- FXPutBitMap(x, y, pic.W, pic.H, pic.W, pic.lpImage);
- }
- void ddTextOut(int x, int y, LPSTR t, int color)
- {
- lpddBack->GetDC( &ddBackDC );
- SetBkMode( ddBackDC, TRANSPARENT );
- HFONT oldfont;
- if (SmallFont) oldfont = (HFONT)SelectObject(ddBackDC, fnt_Small);
-
- SetTextColor(ddBackDC, 0x00101010);
- TextOut(ddBackDC, x+2, y+1, t, strlen(t));
- SetTextColor(ddBackDC, color);
- TextOut(ddBackDC, x+1, y, t, strlen(t));
- if (SmallFont) SelectObject(ddBackDC, oldfont);
-
- lpddBack->ReleaseDC( ddBackDC );
- }
- void DrawTrophyText(int x0, int y0)
- {
- int x;
- SmallFont = TRUE;
- HFONT oldfont = (HFONT)SelectObject(hdcMain, fnt_Small);
- int tc = TrophyBody;
-
- int dtype = TrophyRoom.Body[tc].ctype;
- int time = TrophyRoom.Body[tc].time;
- int date = TrophyRoom.Body[tc].date;
- int wep = TrophyRoom.Body[tc].weapon;
- int score = TrophyRoom.Body[tc].score;
- float scale = TrophyRoom.Body[tc].scale;
- float range = TrophyRoom.Body[tc].range;
- char t[32];
- x0+=14; y0+=18;
- x = x0;
- ddTextOut(x, y0 , "Name: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Name: ");
- ddTextOut(x, y0 , DinoInfo[dtype].Name, 0x0000BFBF);
- x = x0;
- ddTextOut(x, y0+16, "Weight: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Weight: ");
- if (OptSys)
- sprintf(t,"%3.2ft ", DinoInfo[dtype].Mass * scale * scale / 0.907);
- else
- sprintf(t,"%3.2fT ", DinoInfo[dtype].Mass * scale * scale);
- ddTextOut(x, y0+16, t, 0x0000BFBF); x+=GetTextW(hdcMain,t);
- ddTextOut(x, y0+16, "Length: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Length: ");
-
- if (OptSys)
- sprintf(t,"%3.2fft", DinoInfo[dtype].Length * scale / 0.3);
- else
- sprintf(t,"%3.2fm", DinoInfo[dtype].Length * scale);
- ddTextOut(x, y0+16, t, 0x0000BFBF);
-
- x = x0;
- ddTextOut(x, y0+32, "Weapon: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Weapon: ");
- wsprintf(t,"%s ", WeapInfo[wep].Name);
- ddTextOut(x, y0+32, t, 0x0000BFBF); x+=GetTextW(hdcMain,t);
- ddTextOut(x, y0+32, "Score: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Score: ");
- wsprintf(t,"%d", score);
- ddTextOut(x, y0+32, t, 0x0000BFBF);
- x = x0;
- ddTextOut(x, y0+48, "Range of kill: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Range of kill: ");
- if (OptSys) sprintf(t,"%3.1fft", range / 0.3);
- else sprintf(t,"%3.1fm", range);
- ddTextOut(x, y0+48, t, 0x0000BFBF);
- x = x0;
- ddTextOut(x, y0+64, "Date: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Date: ");
- if (OptSys)
- wsprintf(t,"%d.%d.%d ", ((date>>10) & 255), (date & 255), date>>20);
- else
- wsprintf(t,"%d.%d.%d ", (date & 255), ((date>>10) & 255), date>>20);
- ddTextOut(x, y0+64, t, 0x0000BFBF); x+=GetTextW(hdcMain,t);
- ddTextOut(x, y0+64, "Time: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Time: ");
- wsprintf(t,"%d:%02d", ((time>>10) & 255), (time & 255));
- ddTextOut(x, y0+64, t, 0x0000BFBF);
- SmallFont = FALSE;
- SelectObject(hdcMain, oldfont);
-
- }
- void Render_LifeInfo(int li)
- {
- int x,y;
- SmallFont = TRUE;
- //HFONT oldfont = SelectObject(hdcMain, fnt_Small);
-
- int ctype = Characters[li].CType;
- float scale = Characters[li].scale;
- char t[32];
-
- x = VideoCX + WinW / 64;
- y = VideoCY + (int)(WinH / 6.8);
-
- ddTextOut(x, y, DinoInfo[ctype].Name, 0x0000b000);
-
- if (OptSys) sprintf(t,"Weight: %3.2ft ", DinoInfo[ctype].Mass * scale * scale / 0.907);
- else sprintf(t,"Weight: %3.2fT ", DinoInfo[ctype].Mass * scale * scale);
-
- ddTextOut(x, y+16, t, 0x0000b000);
- int R = (int)(VectorLength( SubVectors(Characters[li].pos, PlayerPos) )*3 / 64.f);
- if (OptSys) sprintf(t,"Distance: %dft ", R);
- else sprintf(t,"Distance: %dm ", R/3);
- ddTextOut(x, y+32, t, 0x0000b000);
-
- SmallFont = FALSE;
- //SelectObject(hdcMain, oldfont);
- }
- void RenderFXMMap()
- {
-
- }
- void ShowControlElements()
- {
- char buf[128];
-
- //ddTextOut(100, 100, "!", 0x0020A0A0);
- lpddBack->GetDC( &ddBackDC );
- lpddBack->ReleaseDC( ddBackDC );
- if (TIMER) {
- wsprintf(buf,"msc: %d", TimeDt);
- ddTextOut(WinEX-81, 11, buf, 0x0020A0A0);
- wsprintf(buf,"polys: %d", dFacesCount);
- ddTextOut(WinEX-90, 24, buf, 0x0020A0A0);
- wsprintf(buf,"%d", Env);
- ddTextOut(10, 24, buf, 0x0020A0A0);
- }
- if (MessageList.timeleft) {
- if (RealTime>MessageList.timeleft) MessageList.timeleft = 0;
- ddTextOut(10, 10, MessageList.mtext, 0x0020A0A0);
- }
- if (ExitTime) {
- int y = WinH / 3;
- wsprintf(buf,"Preparing for evacuation...");
- ddTextOut(VideoCX - GetTextW(hdcCMain, buf)/2, y, buf, 0x0060C0D0);
- wsprintf(buf,"%d seconds left.", 1 + ExitTime / 1000);
- ddTextOut(VideoCX - GetTextW(hdcCMain, buf)/2, y + 18, buf, 0x0060C0D0);
- }
- }
- void ClipVector(CLIPPLANE& C, int vn)
- {
- int ClipRes = 0;
- float s,s1,s2;
- int vleft = (vn-1); if (vleft <0) vleft=vused-1;
- int vright = (vn+1); if (vright>=vused) vright=0;
-
- MulVectorsScal(cp[vn].ev.v, C.nv, s); /*s=SGN(s-0.01f);*/
- if (s>=0) return;
- MulVectorsScal(cp[vleft ].ev.v, C.nv, s1); /* s1=SGN(s1+0.01f); */ //s1+=0.0001f;
- MulVectorsScal(cp[vright].ev.v, C.nv, s2); /* s2=SGN(s2+0.01f); */ //s2+=0.0001f;
-
- if (s1>0) {
- ClipRes+=1;
- /*
- CalcHitPoint(C,cp[vn].ev.v,
- cp[vleft].ev.v, hleft.ev.v);
- float ll = VectorLength(SubVectors(cp[vleft].ev.v, cp[vn].ev.v));
- float lc = VectorLength(SubVectors(hleft.ev.v, cp[vn].ev.v));
- lc = lc / ll;
- */
- float lc = -s / (s1-s);
- hleft.ev.v.x = cp[vn].ev.v.x + ((cp[vleft].ev.v.x - cp[vn].ev.v.x) * lc);
- hleft.ev.v.y = cp[vn].ev.v.y + ((cp[vleft].ev.v.y - cp[vn].ev.v.y) * lc);
- hleft.ev.v.z = cp[vn].ev.v.z + ((cp[vleft].ev.v.z - cp[vn].ev.v.z) * lc);
- hleft.tx = cp[vn].tx + ((cp[vleft].tx - cp[vn].tx) * lc);
- hleft.ty = cp[vn].ty + ((cp[vleft].ty - cp[vn].ty) * lc);
- hleft.ev.Light = cp[vn].ev.Light + (int)((cp[vleft].ev.Light - cp[vn].ev.Light) * lc);
- hleft.ev.ALPHA = cp[vn].ev.ALPHA + (int)((cp[vleft].ev.ALPHA - cp[vn].ev.ALPHA) * lc);
- hleft.ev.Fog = cp[vn].ev.Fog + ((cp[vleft].ev.Fog - cp[vn].ev.Fog ) * lc);
- }
- if (s2>0) {
- ClipRes+=2;
- /*
- CalcHitPoint(C,cp[vn].ev.v,
- cp[vright].ev.v, hright.ev.v);
- float ll = VectorLength(SubVectors(cp[vright].ev.v, cp[vn].ev.v));
- float lc = VectorLength(SubVectors(hright.ev.v, cp[vn].ev.v));
- lc = lc / ll;*/
- float lc = -s / (s2-s);
- hright.ev.v.x = cp[vn].ev.v.x + ((cp[vright].ev.v.x - cp[vn].ev.v.x) * lc);
- hright.ev.v.y = cp[vn].ev.v.y + ((cp[vright].ev.v.y - cp[vn].ev.v.y) * lc);
- hright.ev.v.z = cp[vn].ev.v.z + ((cp[vright].ev.v.z - cp[vn].ev.v.z) * lc);
- hright.tx = cp[vn].tx + ((cp[vright].tx - cp[vn].tx) * lc);
- hright.ty = cp[vn].ty + ((cp[vright].ty - cp[vn].ty) * lc);
- hright.ev.Light = cp[vn].ev.Light + (int)((cp[vright].ev.Light - cp[vn].ev.Light) * lc);
- hright.ev.ALPHA = cp[vn].ev.ALPHA + (int)((cp[vright].ev.ALPHA - cp[vn].ev.ALPHA) * lc);
- hright.ev.Fog = cp[vn].ev.Fog + ((cp[vright].ev.Fog - cp[vn].ev.Fog ) * lc);
- }
- if (ClipRes == 0) {
- u--; vused--;
- cp[vn] = cp[vn+1];
- cp[vn+1] = cp[vn+2];
- cp[vn+2] = cp[vn+3];
- cp[vn+3] = cp[vn+4];
- cp[vn+4] = cp[vn+5];
- cp[vn+5] = cp[vn+6];
- //memcpy(&cp[vn], &cp[vn+1], (15-vn)*sizeof(ClipPoint));
- }
- if (ClipRes == 1) {cp[vn] = hleft; }
- if (ClipRes == 2) {cp[vn] = hright;}
- if (ClipRes == 3) {
- u++; vused++;
- //memcpy(&cp[vn+1], &cp[vn], (15-vn)*sizeof(ClipPoint));
- cp[vn+6] = cp[vn+5];
- cp[vn+5] = cp[vn+4];
- cp[vn+4] = cp[vn+3];
- cp[vn+3] = cp[vn+2];
- cp[vn+2] = cp[vn+1];
- cp[vn+1] = cp[vn];
-
- cp[vn] = hleft;
- cp[vn+1] = hright;
- }
- }
- void DrawTPlaneClip(BOOL SECONT)
- {
- if (!WATERREVERSE) {
- MulVectorsVect(SubVectors(ev[1].v, ev[0].v), SubVectors(ev[2].v, ev[0].v), nv);
- if (nv.x*ev[0].v.x + nv.y*ev[0].v.y + nv.z*ev[0].v.z<0) return;
- }
- cp[0].ev = ev[0]; cp[1].ev = ev[1]; cp[2].ev = ev[2];
- if (ReverseOn)
- if (SECONT) {
- switch (TDirection) {
- case 0:
- cp[0].tx = TCMIN; cp[0].ty = TCMAX;
- cp[1].tx = TCMAX; cp[1].ty = TCMIN;
- cp[2].tx = TCMAX; cp[2].ty = TCMAX;
- break;
- case 1:
- cp[0].tx = TCMAX; cp[0].ty = TCMAX;
- cp[1].tx = TCMIN; cp[1].ty = TCMIN;
- cp[2].tx = TCMAX; cp[2].ty = TCMIN;
- break;
- case 2:
- cp[0].tx = TCMAX; cp[0].ty = TCMIN;
- cp[1].tx = TCMIN; cp[1].ty = TCMAX;
- cp[2].tx = TCMIN; cp[2].ty = TCMIN;
- break;
- case 3:
- cp[0].tx = TCMIN; cp[0].ty = TCMIN;
- cp[1].tx = TCMAX; cp[1].ty = TCMAX;
- cp[2].tx = TCMIN; cp[2].ty = TCMAX;
- break;
- }
- } else {
- switch (TDirection) {
- case 0:
- cp[0].tx = TCMIN; cp[0].ty = TCMIN;
- cp[1].tx = TCMAX; cp[1].ty = TCMIN;
- cp[2].tx = TCMIN; cp[2].ty = TCMAX;
- break;
- case 1:
- cp[0].tx = TCMIN; cp[0].ty = TCMAX;
- cp[1].tx = TCMIN; cp[1].ty = TCMIN;
- cp[2].tx = TCMAX; cp[2].ty = TCMAX;
- break;
- case 2:
- cp[0].tx = TCMAX; cp[0].ty = TCMAX;
- cp[1].tx = TCMIN; cp[1].ty = TCMAX;
- cp[2].tx = TCMAX; cp[2].ty = TCMIN;
- break;
- case 3:
- cp[0].tx = TCMAX; cp[0].ty = TCMIN;
- cp[1].tx = TCMAX; cp[1].ty = TCMAX;
- cp[2].tx = TCMIN; cp[2].ty = TCMIN;
- break;
- }
- }
- else
- if (SECONT) {
- switch (TDirection) {
- case 0:
- cp[0].tx = TCMIN; cp[0].ty = TCMIN;
- cp[1].tx = TCMAX; cp[1].ty = TCMAX;
- cp[2].tx = TCMIN; cp[2].ty = TCMAX;
- break;
- case 1:
- cp[0].tx = TCMIN; cp[0].ty = TCMAX;
- cp[1].tx = TCMAX; cp[1].ty = TCMIN;
- cp[2].tx = TCMAX; cp[2].ty = TCMAX;
- break;
- case 2:
- cp[0].tx = TCMAX; cp[0].ty = TCMAX;
- cp[1].tx = TCMIN; cp[1].ty = TCMIN;
- cp[2].tx = TCMAX; cp[2].ty = TCMIN;
- break;
- case 3:
- cp[0].tx = TCMAX; cp[0].ty = TCMIN;
- cp[1].tx = TCMIN; cp[1].ty = TCMAX;
- cp[2].tx = TCMIN; cp[2].ty = TCMIN;
- break;
- }
- } else {
- switch (TDirection) {
- case 0:
- cp[0].tx = TCMIN; cp[0].ty = TCMIN;
- cp[1].tx = TCMAX; cp[1].ty = TCMIN;
- cp[2].tx = TCMAX; cp[2].ty = TCMAX;
- break;
- case 1:
- cp[0].tx = TCMIN; cp[0].ty = TCMAX;
- cp[1].tx = TCMIN; cp[1].ty = TCMIN;
- cp[2].tx = TCMAX; cp[2].ty = TCMIN;
- break;
- case 2:
- cp[0].tx = TCMAX; cp[0].ty = TCMAX;
- cp[1].tx = TCMIN; cp[1].ty = TCMAX;
- cp[2].tx = TCMIN; cp[2].ty = TCMIN;
- break;
- case 3:
- cp[0].tx = TCMAX; cp[0].ty = TCMIN;
- cp[1].tx = TCMAX; cp[1].ty = TCMAX;
- cp[2].tx = TCMIN; cp[2].ty = TCMAX;
- break;
- }
- }
-
- vused = 3;
- for (u=0; u<vused; u++) cp[u].ev.v.z+=16.0f;
- for (u=0; u<vused; u++) ClipVector(ClipZ,u);
- for (u=0; u<vused; u++) cp[u].ev.v.z-=16.0f;
- if (vused<3) return;
- for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) return;
- for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) return;
- for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) return;
- for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) return;
-
- for (u=0; u<vused; u++) {
- cp[u].ev.scrx = (VideoCX)*16 - (int)(16.f * cp[u].ev.v.x / cp[u].ev.v.z * CameraW);
- cp[u].ev.scry = (VideoCY)*16 + (int)(16.f * cp[u].ev.v.y / cp[u].ev.v.z * CameraH);
- }
-
-
- if (!lpVertexG)
- d3dStartBufferG();
-
- if (GVCnt>380) {
- if (lpVertexG) d3dEndBufferG(FALSE);
- d3dStartBufferG();
- }
- if (hGTexture!=hTexture) {
- hGTexture=hTexture;
- lpInstructionG->bOpcode = D3DOP_STATERENDER;
- lpInstructionG->bSize = sizeof(D3DSTATE);
- lpInstructionG->wCount = 1;
- lpInstructionG++;
- lpState = (LPD3DSTATE)lpInstructionG;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = hTexture;
- lpState++;
- lpInstructionG = (LPD3DINSTRUCTION)lpState;
- lpwTriCount = &(lpInstructionG->wCount);
- lpInstructionG->bOpcode = D3DOP_TRIANGLE;
- lpInstructionG->bSize = sizeof(D3DTRIANGLE);
- lpInstructionG->wCount = 0;
- lpInstructionG++;
-
- }
-
- lpTriangle = (LPD3DTRIANGLE)lpInstructionG;
- for (u=0; u<vused-2; u++) {
- lpVertexG->sx = (float)cp[0].ev.scrx / 16.f;
- lpVertexG->sy = (float)cp[0].ev.scry / 16.f;
- lpVertexG->sz = _ZSCALE / cp[0].ev.v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(cp[0].ev.Light) * 0x00010101 | ((int)cp[0].ev.ALPHA<<24);
- lpVertexG->specular = (255-(int)cp[0].ev.Fog)<<24;//0x7F000000;
- lpVertexG->tu = (float)(cp[0].tx) / (128.f*65536.f);
- lpVertexG->tv = (float)(cp[0].ty) / (128.f*65536.f);
- lpVertexG++;
- lpVertexG->sx = (float)cp[u+1].ev.scrx / 16.f;
- lpVertexG->sy = (float)cp[u+1].ev.scry / 16.f;
- lpVertexG->sz = _ZSCALE / cp[u+1].ev.v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(cp[u+1].ev.Light) * 0x00010101 | ((int)cp[u+1].ev.ALPHA<<24);
- lpVertexG->specular = (255-(int)cp[u+1].ev.Fog)<<24;//0x7F000000;
- lpVertexG->tu = (float)(cp[u+1].tx) / (128.f*65536.f);
- lpVertexG->tv = (float)(cp[u+1].ty) / (128.f*65536.f);
- lpVertexG++;
- lpVertexG->sx = (float)cp[u+2].ev.scrx / 16.f;
- lpVertexG->sy = (float)cp[u+2].ev.scry / 16.f;
- lpVertexG->sz = _ZSCALE / cp[u+2].ev.v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(cp[u+2].ev.Light) * 0x00010101 | ((int)cp[u+2].ev.ALPHA<<24);
- lpVertexG->specular = (255-(int)cp[u+2].ev.Fog)<<24;//0x7F000000;
- lpVertexG->tu = (float)(cp[u+2].tx) / (128.f*65536.f);
- lpVertexG->tv = (float)(cp[u+2].ty) / (128.f*65536.f);
- lpVertexG++;
-
- lpTriangle->wV1 = GVCnt;
- lpTriangle->wV2 = GVCnt+1;
- lpTriangle->wV3 = GVCnt+2;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- *lpwTriCount = (*lpwTriCount) + 1;
- GVCnt+=3;
- }
-
- lpInstructionG = (LPD3DINSTRUCTION)lpTriangle;
- }
- void DrawTPlane(BOOL SECONT)
- {
- int n;
-
- //if (!WATERREVERSE) {
- MulVectorsVect(SubVectors(ev[1].v, ev[0].v), SubVectors(ev[2].v, ev[0].v), nv);
- if (nv.x*ev[0].v.x + nv.y*ev[0].v.y + nv.z*ev[0].v.z<0) return;
- //}
- Mask1=0x007F;
- for (n=0; n<3; n++) {
- if (ev[n].DFlags & 128) return;
- Mask1=Mask1 & ev[n].DFlags; }
- if (Mask1>0) return;
- if (ReverseOn)
- if (SECONT) {
- switch (TDirection) {
- case 0:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
- break;
- case 1:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
- break;
- case 2:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
- break;
- case 3:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
- break;
- }
- } else {
- switch (TDirection) {
- case 0:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
- break;
- case 1:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
- break;
- case 2:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
- break;
- case 3:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
- break;
- }
- }
- else
- if (SECONT) {
- switch (TDirection) {
- case 0:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
- break;
- case 1:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
- break;
- case 2:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
- break;
- case 3:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
- break;
- }
- } else {
- switch (TDirection) {
- case 0:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
- break;
- case 1:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
- break;
- case 2:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
- break;
- case 3:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
- break;
- }
- }
-
- int alpha1 = 255;
- int alpha2 = 255;
- int alpha3 = 255;
- //if (!WATERREVERSE)
-
- if (zs > (ctViewR-8)<<8) {
- int zz;
- zz = (int)VectorLength(ev[0].v) - 256 * (ctViewR-4);
- if (zz > 0) alpha1 = max(0, 255 - zz / 3); else alpha1 = 255;
-
- zz = (int)VectorLength(ev[1].v) - 256 * (ctViewR-4);
- if (zz > 0) alpha2 = max(0, 255 - zz / 3); else alpha2 = 255;
- zz = (int)VectorLength(ev[2].v) - 256 * (ctViewR-4);
- if (zz > 0) alpha3 = max(0, 255 - zz / 3); else alpha3 = 255;
- }
-
- if (!lpVertexG)
- d3dStartBufferG();
-
- if (GVCnt>380) {
- if (lpVertexG) d3dEndBufferG(FALSE);
- d3dStartBufferG();
- }
- lpVertexG->sx = (float)ev[0].scrx / 16;
- lpVertexG->sy = (float)ev[0].scry / 16;
- lpVertexG->sz = _ZSCALE / ev[0].v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(ev[0].Light) * 0x00010101 | alpha1<<24;
- lpVertexG->specular = (255-(int)ev[0].Fog)<<24;//0x7F000000;
- lpVertexG->tu = (float)(scrp[0].tx) / (128.f*65536.f);
- lpVertexG->tv = (float)(scrp[0].ty) / (128.f*65536.f);
- lpVertexG++;
- lpVertexG->sx = (float)ev[1].scrx / 16;
- lpVertexG->sy = (float)ev[1].scry / 16;
- lpVertexG->sz = _ZSCALE / ev[1].v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(ev[1].Light) * 0x00010101 | alpha2<<24;
- lpVertexG->specular = (255-(int)ev[1].Fog)<<24;//0x7F000000;
- lpVertexG->tu = (float)(scrp[1].tx) / (128.f*65536.f);
- lpVertexG->tv = (float)(scrp[1].ty) / (128.f*65536.f);
- lpVertexG++;
- lpVertexG->sx = (float)ev[2].scrx / 16;
- lpVertexG->sy = (float)ev[2].scry / 16;
- lpVertexG->sz = _ZSCALE / ev[2].v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(ev[2].Light) * 0x00010101 | alpha3<<24;
- lpVertexG->specular = (255-(int)ev[2].Fog)<<24;//0x7F000000;
- lpVertexG->tu = (float)(scrp[2].tx) / (128.f*65536.f);
- lpVertexG->tv = (float)(scrp[2].ty) / (128.f*65536.f);
- lpVertexG++;
- if (hGTexture!=hTexture) {
- hGTexture=hTexture;
- lpInstructionG->bOpcode = D3DOP_STATERENDER;
- lpInstructionG->bSize = sizeof(D3DSTATE);
- lpInstructionG->wCount = 1;
- lpInstructionG++;
- lpState = (LPD3DSTATE)lpInstructionG;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = hTexture;
- lpState++;
- lpInstructionG = (LPD3DINSTRUCTION)lpState;
- lpwTriCount = (&lpInstructionG->wCount);
- lpInstructionG->bOpcode = D3DOP_TRIANGLE;
- lpInstructionG->bSize = sizeof(D3DTRIANGLE);
- lpInstructionG->wCount = 0;
- lpInstructionG++;
- }
-
- lpTriangle = (LPD3DTRIANGLE)lpInstructionG;
- lpTriangle->wV1 = GVCnt;
- lpTriangle->wV2 = GVCnt+1;
- lpTriangle->wV3 = GVCnt+2;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- *lpwTriCount = (*lpwTriCount) + 1;
- lpInstructionG = (LPD3DINSTRUCTION)lpTriangle;
- GVCnt+=3;
- }
- void DrawTPlaneW(BOOL SECONT)
- {
- int n;
-
- Mask1=0x007F;
- for (n=0; n<3; n++) {
- if (ev[n].DFlags & 128) return;
- Mask1=Mask1 & ev[n].DFlags; }
- if (Mask1>0) return;
- /*
- for (n=0; n<3; n++) {
- scrp[n].x = (float)(VideoCX) - (ev[n].v.x / ev[n].v.z * CameraW);
- scrp[n].y = (float)(VideoCY) + (ev[n].v.y / ev[n].v.z * CameraH);
- scrp[n].Light = ev[n].Light;
- } */
- if (ReverseOn)
- if (SECONT) {
- switch (TDirection) {
- case 0:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
- break;
- case 1:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
- break;
- case 2:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
- break;
- case 3:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
- break;
- }
- } else {
- switch (TDirection) {
- case 0:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
- break;
- case 1:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
- break;
- case 2:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
- break;
- case 3:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
- break;
- }
- }
- else
- if (SECONT) {
- switch (TDirection) {
- case 0:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
- break;
- case 1:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
- break;
- case 2:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
- break;
- case 3:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
- break;
- }
- } else {
- switch (TDirection) {
- case 0:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
- break;
- case 1:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
- break;
- case 2:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
- break;
- case 3:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
- break;
- }
- }
-
- if (!UNDERWATER)
- if (zs > (ctViewR-8)<<8) {
- float zz;
- zz = VectorLength(ev[0].v) - 256 * (ctViewR-4);
- if (zz > 0) ev[0].ALPHA = max(0.f,255.f - zz / 3.f);
-
- zz = VectorLength(ev[1].v) - 256 * (ctViewR-4);
- if (zz > 0) ev[1].ALPHA = max(0.f, 255.f - zz / 3.f);
- zz = VectorLength(ev[2].v) - 256 * (ctViewR-4);
- if (zz > 0) ev[2].ALPHA = max(0,255.f - zz / 3.f);
- }
-
- if (!lpVertexG)
- d3dStartBufferG();
-
- if (GVCnt>380) {
- if (lpVertexG) d3dEndBufferG(FALSE);
- d3dStartBufferG();
- }
- lpVertexG->sx = (float)ev[0].scrx / 16;
- lpVertexG->sy = (float)ev[0].scry / 16;
- lpVertexG->sz = _ZSCALE / ev[0].v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(ev[0].Light) * 0x00010101 | ev[0].ALPHA<<24;
- lpVertexG->specular = (255-(int)ev[0].Fog)<<24;
- lpVertexG->tu = (float)(scrp[0].tx) / (128.f*65536.f);
- lpVertexG->tv = (float)(scrp[0].ty) / (128.f*65536.f);
- lpVertexG++;
- lpVertexG->sx = (float)ev[1].scrx / 16;
- lpVertexG->sy = (float)ev[1].scry / 16;
- lpVertexG->sz = _ZSCALE / ev[1].v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(ev[1].Light) * 0x00010101 | ev[1].ALPHA<<24;
- lpVertexG->specular = (255-(int)ev[1].Fog)<<24;
- lpVertexG->tu = (float)(scrp[1].tx) / (128.f*65536.f);
- lpVertexG->tv = (float)(scrp[1].ty) / (128.f*65536.f);
- lpVertexG++;
- lpVertexG->sx = (float)ev[2].scrx / 16;
- lpVertexG->sy = (float)ev[2].scry / 16;
- lpVertexG->sz = _ZSCALE / ev[2].v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(ev[2].Light) * 0x00010101 | ev[2].ALPHA<<24;
- lpVertexG->specular = (255-(int)ev[2].Fog)<<24;
- lpVertexG->tu = (float)(scrp[2].tx) / (128.f*65536.f);
- lpVertexG->tv = (float)(scrp[2].ty) / (128.f*65536.f);
- lpVertexG++;
- if (hGTexture!=hTexture) {
- hGTexture=hTexture;
- lpInstructionG->bOpcode = D3DOP_STATERENDER;
- lpInstructionG->bSize = sizeof(D3DSTATE);
- lpInstructionG->wCount = 1;
- lpInstructionG++;
- lpState = (LPD3DSTATE)lpInstructionG;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = hTexture;
- lpState++;
- lpInstructionG = (LPD3DINSTRUCTION)lpState;
- lpwTriCount = (&lpInstructionG->wCount);
- lpInstructionG->bOpcode = D3DOP_TRIANGLE;
- lpInstructionG->bSize = sizeof(D3DTRIANGLE);
- lpInstructionG->wCount = 0;
- lpInstructionG++;
- }
-
- lpTriangle = (LPD3DTRIANGLE)lpInstructionG;
- lpTriangle->wV1 = GVCnt;
- lpTriangle->wV2 = GVCnt+1;
- lpTriangle->wV3 = GVCnt+2;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- *lpwTriCount = (*lpwTriCount) + 1;
- lpInstructionG = (LPD3DINSTRUCTION)lpTriangle;
- GVCnt+=3;
- }
- void _RenderObject(int x, int y)
- {
- int ob = OMap[y][x];
- if (!MObjects[ob].model) {
- //return;
- wsprintf(logt,"Incorrect model at [%d][%d]!", x, y);
- DoHalt(logt);
- }
- //int mlight = -(RandomMap[y & 31][x & 31] >> 5) + (LMap[y][x]>>1) + 96;
- int FI = (FMap[y][x] >> 2) & 3;
- float fi = CameraAlpha + (float)(FI * 2.f*pi / 4.f);
- int mlight;
- if (MObjects[ob].info.flags & ofDEFLIGHT)
- mlight = MObjects[ob].info.DefLight; else
- if (MObjects[ob].info.flags & ofGRNDLIGHT)
- {
- mlight = 128;
- CalcModelGroundLight(MObjects[ob].model, x*256+128, y*256+128, FI);
- FI = 0;
- }
- else
- mlight = -(RandomMap[y & 31][x & 31] >> 5) + (LMap[y][x]>>1) + 96;
- if (mlight >192) mlight =192;
- if (mlight < 64) mlight = 64;
-
- v[0].x = x*256+128 - CameraX;
- v[0].z = y*256+128 - CameraZ;
- v[0].y = (float)(HMapO[y][x]) * ctHScale - CameraY;
- float zs = VectorLength(v[0]);
- //if (v[0].y + MObjects[ob].info.YHi < (int)(HMap[y][x]+HMap[y+1][x+1]) / 2 * ctHScale - CameraY) return;
-
- CalcFogLevel_Gradient(v[0]);
-
-
- v[0] = RotateVector(v[0]);
- GlassL = 0;
-
- if (zs > 256 * (ctViewR-8))
- GlassL=min(255,(int)(zs - 256 * (ctViewR-8)) / 4);
- if (GlassL==255) return;
-
- if (MObjects[ob].info.flags & ofANIMATED)
- if (MObjects[ob].info.LastAniTime!=RealTime) {
- MObjects[ob].info.LastAniTime=RealTime;
- CreateMorphedObject(MObjects[ob].model,
- MObjects[ob].vtl,
- RealTime % MObjects[ob].vtl.AniTime);
- }
-
- if (MObjects[ob].info.flags & ofNOBMP) zs = 0;
- /*
- if (!NeedWater && zs>ctViewRM*256 && zs<(ctViewRM+1)*256) {
- GlassL = 255-(int)(zs - ctViewRM*256);
- RenderBMPModel(&MObjects[ob].bmpmodel, v[0].x, v[0].y, v[0].z, mlight-32);
- GlassL=255-GlassL;
- RenderModel(MObjects[ob].model, v[0].x, v[0].y, v[0].z, mlight, FI, fi, CameraBeta);
- } else */
- if (zs>ctViewRM*256)
- RenderBMPModel(&MObjects[ob].bmpmodel, v[0].x, v[0].y, v[0].z, mlight-16);
- else
- if (v[0].z<-256*8)
- RenderModel(MObjects[ob].model, v[0].x, v[0].y, v[0].z, mlight, FI, fi, CameraBeta);
- else
- RenderModelClip(MObjects[ob].model, v[0].x, v[0].y, v[0].z, mlight, FI, fi, CameraBeta);
-
- }
- void RenderObject(int x, int y)
- {
- if (OMap[y][x]==255) return;
- if (!MODELS) return;
- if (ORLCount>2000) return;
- ORList[ORLCount].x = x;
- ORList[ORLCount].y = y;
- ORLCount++;
- }
- void RenderModelsList()
- {
- d3dEndBufferG(FALSE);
- for (int o=0; o<ORLCount; o++)
- _RenderObject(ORList[o].x, ORList[o].y);
- ORLCount=0;
- d3dEndBufferG(TRUE);
- }
- void ProcessMap(int x, int y, int r)
- {
- //WATERREVERSE = FALSE;
- if (x>=ctMapSize-1 || y>=ctMapSize-1 ||
- x<0 || y<0) return;
- float BackR = BackViewR;
- if (OMap[y][x]!=255) BackR+=MObjects[OMap[y][x]].info.BoundR;
- ev[0] = VMap[y-CCY+128][x-CCX+128];
- if (ev[0].v.z>BackR) return;
-
- int t1 = TMap1[y][x];
- ReverseOn = (FMap[y][x] & fmReverse);
- TDirection = (FMap[y][x] & 3);
-
- x = x - CCX + 128;
- y = y - CCY + 128;
- ev[1] = VMap[y][x+1];
- if (ReverseOn) ev[2] = VMap[y+1][x];
- else ev[2] = VMap[y+1][x+1];
-
- float xx = (ev[0].v.x + VMap[y+1][x+1].v.x) / 2;
- float yy = (ev[0].v.y + VMap[y+1][x+1].v.y) / 2;
- float zz = (ev[0].v.z + VMap[y+1][x+1].v.z) / 2;
- if ( fabs(xx*FOVK) > -zz + BackR) return;
-
-
- zs = (int)sqrt( xx*xx + zz*zz + yy*yy);
-
-
- if (MIPMAP && (zs > 256 * 10 && t1 || LOWRESTX)) d3dSetTexture(Textures[t1]->DataB, 64, 64);
- else d3dSetTexture(Textures[t1]->DataA, 128, 128);
- if (r>8) DrawTPlane(FALSE);
- else DrawTPlaneClip(FALSE);
- if (ReverseOn) { ev[0] = ev[2]; ev[2] = VMap[y+1][x+1]; }
- else { ev[1] = ev[2]; ev[2] = VMap[y+1][x]; }
- if (r>8) DrawTPlane(TRUE);
- else DrawTPlaneClip(TRUE);
-
- x = x + CCX - 128;
- y = y + CCY - 128;
- if (OMap[y][x]==255) return;
-
- if (zz<BackR)
- RenderObject(x, y);
- }
- void ProcessMap2(int x, int y, int r)
- {
- //WATERREVERSE = FALSE;
- if (x>=ctMapSize-1 || y>=ctMapSize-1 ||
- x<0 || y<0) return;
- ev[0] = VMap[y-CCY+128][x-CCX+128];
- if (ev[0].v.z>BackViewR) return;
-
- int t1 = TMap2[y][x];
- TDirection = ((FMap[y][x]>>8) & 3);
- ReverseOn = FALSE;
-
- x = x - CCX + 128;
- y = y - CCY + 128;
- ev[1] = VMap[y][x+2];
- if (ReverseOn) ev[2] = VMap[y+2][x];
- else ev[2] = VMap[y+2][x+2];
-
- float xx = (ev[0].v.x + VMap[y+2][x+2].v.x) / 2;
- float yy = (ev[0].v.y + VMap[y+2][x+2].v.y) / 2;
- float zz = (ev[0].v.z + VMap[y+2][x+2].v.z) / 2;
- if ( fabs(xx*FOVK) > -zz + BackViewR) return;
-
- zs = (int)sqrt( xx*xx + zz*zz + yy*yy);
- if (zs>ctViewR*256) return;
-
- d3dSetTexture(Textures[t1]->DataB, 64, 64);
- DrawTPlane(FALSE);
-
- if (ReverseOn) { ev[0] = ev[2]; ev[2] = VMap[y+2][x+2]; }
- else { ev[1] = ev[2]; ev[2] = VMap[y+2][x]; }
- DrawTPlane(TRUE);
-
-
- x = x + CCX - 128;
- y = y + CCY - 128;
- RenderObject(x , y);
- RenderObject(x+1, y);
- RenderObject(x , y+1);
- RenderObject(x+1, y+1);
- }
- void ProcessMapW(int x, int y, int r)
- {
- if (!( (FMap[y ][x ] & fmWaterA) &&
- (FMap[y ][x+1] & fmWaterA) &&
- (FMap[y+1][x ] & fmWaterA) &&
- (FMap[y+1][x+1] & fmWaterA) )) return;
-
- WATERREVERSE = TRUE;
- int t1 = WaterList[ WMap[y][x] ].tindex;
- ev[0] = VMap2[y-CCY+128][x-CCX+128];
- if (ev[0].v.z>BackViewR) return;
-
- ReverseOn = FALSE;
- TDirection = 0;
-
- x = x - CCX + 128;
- y = y - CCY + 128;
- ev[1] = VMap2[y][x+1];
- ev[2] = VMap2[y+1][x+1];
-
- float xx = (ev[0].v.x + VMap2[y+1][x+1].v.x) / 2;
- float yy = (ev[0].v.y + VMap2[y+1][x+1].v.y) / 2;
- float zz = (ev[0].v.z + VMap2[y+1][x+1].v.z) / 2;
-
- if ( fabs(xx*FOVK) > -zz + BackViewR) return;
-
- zs = (int)sqrt( xx*xx + zz*zz + yy*yy);
- if (zs > ctViewR*256) return;
-
- if (MIPMAP && (zs > 256 * 10 && t1 || LOWRESTX)) d3dSetTexture(Textures[t1]->DataB, 64, 64);
- else d3dSetTexture(Textures[t1]->DataA, 128, 128);
- if (r>8) DrawTPlaneW(FALSE);
- else DrawTPlaneClip(FALSE);
-
- ev[1] = ev[2]; ev[2] = VMap2[y+1][x];
-
- if (r>8) DrawTPlaneW(TRUE);
- else DrawTPlaneClip(TRUE);
- WATERREVERSE = FALSE;
- }
- void ProcessMapW2(int x, int y, int r)
- {
- if (!( (FMap[y ][x ] & fmWaterA) &&
- (FMap[y ][x+2] & fmWaterA) &&
- (FMap[y+2][x ] & fmWaterA) &&
- (FMap[y+2][x+2] & fmWaterA) )) return;
-
- int t1 = WaterList[ WMap[y][x] ].tindex;
- ev[0] = VMap2[y-CCY+128][x-CCX+128];
- if (ev[0].v.z>BackViewR) return;
-
- //WATERREVERSE = TRUE;
- ReverseOn = FALSE;
- TDirection = 0;
-
- x = x - CCX + 128;
- y = y - CCY + 128;
- ev[1] = VMap2[y][x+2];
- ev[2] = VMap2[y+2][x+2];
-
- float xx = (ev[0].v.x + VMap2[y+2][x+2].v.x) / 2;
- float yy = (ev[0].v.y + VMap2[y+2][x+2].v.y) / 2;
- float zz = (ev[0].v.z + VMap2[y+2][x+2].v.z) / 2;
-
- if ( fabs(xx*FOVK) > -zz + BackViewR) return;
-
- zs = (int)sqrt( xx*xx + zz*zz + yy*yy);
- if (zs > ctViewR*256) return;
-
-
- d3dSetTexture(Textures[t1]->DataB, 64, 64);
-
- DrawTPlaneW(FALSE);
- ev[1] = ev[2]; ev[2] = VMap2[y+2][x];
-
- DrawTPlaneW(TRUE);
- }
- void RenderGround()
- {
- for (r=ctViewR; r>=ctViewR1; r-=2) {
-
- for (int x=r; x>0; x-=2) {
- ProcessMap2(CCX-x, CCY+r, r);
- ProcessMap2(CCX+x, CCY+r, r);
- ProcessMap2(CCX-x, CCY-r, r);
- ProcessMap2(CCX+x, CCY-r, r);
- }
-
- ProcessMap2(CCX, CCY-r, r);
- ProcessMap2(CCX, CCY+r, r);
- for (int y=r-2; y>0; y-=2) {
- ProcessMap2(CCX+r, CCY-y, r);
- ProcessMap2(CCX+r, CCY+y, r);
- ProcessMap2(CCX-r, CCY+y, r);
- ProcessMap2(CCX-r, CCY-y, r);
- }
- ProcessMap2(CCX-r, CCY, r);
- ProcessMap2(CCX+r, CCY, r);
-
- }
-
- r = ctViewR1-1;
- for (int x=r; x>-r; x--) {
- ProcessMap(CCX+r, CCY+x, r);
- ProcessMap(CCX+x, CCY+r, r);
- }
- for (r=ctViewR1-2; r>0; r--) {
-
- for (int x=r; x>0; x--) {
- ProcessMap(CCX-x, CCY+r, r);
- ProcessMap(CCX+x, CCY+r, r);
- ProcessMap(CCX-x, CCY-r, r);
- ProcessMap(CCX+x, CCY-r, r);
- }
-
- ProcessMap(CCX, CCY-r, r);
- ProcessMap(CCX, CCY+r, r);
- for (int y=r-1; y>0; y--) {
- ProcessMap(CCX+r, CCY-y, r);
- ProcessMap(CCX+r, CCY+y, r);
- ProcessMap(CCX-r, CCY+y, r);
- ProcessMap(CCX-r, CCY-y, r);
- }
- ProcessMap(CCX-r, CCY, r);
- ProcessMap(CCX+r, CCY, r);
-
- }
- ProcessMap(CCX, CCY, 0);
- }
- void RenderWCircles()
- {
-
- TWCircle *wptr;
- Vector3d rpos;
- for (int c=0; c<WCCount; c++) {
-
- wptr = &WCircles[c];
- rpos.x = wptr->pos.x - CameraX;
- rpos.y = wptr->pos.y - CameraY;
- rpos.z = wptr->pos.z - CameraZ;
- float r = (float)max( fabs(rpos.x), fabs(rpos.z) );
- int ri = -1 + (int)(r / 256.f + 0.4f);
- if (ri < 0) ri = 0;
- if (ri > ctViewR) continue;
- rpos = RotateVector(rpos);
- if ( rpos.z > BackViewR) continue;
- if ( fabs(rpos.x) > -rpos.z + BackViewR ) continue;
- if ( fabs(rpos.y) > -rpos.z + BackViewR ) continue;
-
- GlassL = 255 - (2000-wptr->FTime) / 38;
- CreateMorphedModel(WCircleModel.mptr, &WCircleModel.Animation[0], (int)(wptr->FTime), wptr->scale);
- if ( fabs(rpos.z) + fabs(rpos.x) < 1000)
- RenderModelClip(WCircleModel.mptr,
- rpos.x, rpos.y, rpos.z, 250, 0, 0, CameraBeta);
- else
- RenderModel(WCircleModel.mptr,
- rpos.x, rpos.y, rpos.z, 250, 0, 0, CameraBeta);
- }
- GlassL = 0;
- }
- void RenderWater()
- {
- SetRenderStates(FALSE, D3DBLEND_INVSRCALPHA);
-
- for (int r=ctViewR; r>=ctViewR1; r-=2) {
-
- for (int x=r; x>0; x-=2) {
- ProcessMapW2(CCX-x, CCY+r, r);
- ProcessMapW2(CCX+x, CCY+r, r);
- ProcessMapW2(CCX-x, CCY-r, r);
- ProcessMapW2(CCX+x, CCY-r, r);
- }
-
- ProcessMapW2(CCX, CCY-r, r);
- ProcessMapW2(CCX, CCY+r, r);
- for (int y=r-2; y>0; y-=2) {
- ProcessMapW2(CCX+r, CCY-y, r);
- ProcessMapW2(CCX+r, CCY+y, r);
- ProcessMapW2(CCX-r, CCY+y, r);
- ProcessMapW2(CCX-r, CCY-y, r);
- }
- ProcessMapW2(CCX-r, CCY, r);
- ProcessMapW2(CCX+r, CCY, r);
- }
- for (int y=-ctViewR1+2; y<ctViewR1; y++)
- for (int x=-ctViewR1+2; x<ctViewR1; x++)
- ProcessMapW(CCX+x, CCY+y, max(abs(x), abs(y)));
-
- d3dEndBufferG(FALSE);
- FogYBase = 0;
- SetRenderStates(FALSE, D3DBLEND_ONE);
- RenderWCircles();
- SetRenderStates(TRUE, D3DBLEND_INVSRCALPHA);
- }
- void RenderCircle(float cx, float cy, float z, float _R, DWORD RGBA, DWORD RGBA2)
- {
- /*
- RGBA = (RGBA & 0xFF00FF00) + ((RGBA & 0x000000FF)<<16) + ((RGBA & 0x00FF0000)>>16);
- RGBA2= (RGBA2 & 0xFF00FF00) + ((RGBA2 & 0x000000FF)<<16) + ((RGBA2 & 0x00FF0000)>>16);
- */
- float R = (float)((int)( _R*16.f)) / 16.f;
- float R2 = (float)((int)(0.65f*_R*16.f)) / 16.f;
- float sz = _ZSCALE / z;
- lpVertex->sx = cx;
- lpVertex->sy = cy;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx;
- lpVertex->sy = cy-R;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx+R2;
- lpVertex->sy = cy-R2;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 1
-
- lpVertex->sx = cx;
- lpVertex->sy = cy;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
-
- lpVertex->sx = cx+R2;
- lpVertex->sy = cy-R2;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx+R;
- lpVertex->sy = cy;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 2
- lpVertex->sx = cx;
- lpVertex->sy = cy;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
-
- lpVertex->sx = cx+R;
- lpVertex->sy = cy;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
-
- lpVertex->sx = cx+R2;
- lpVertex->sy = cy+R2;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 3
- lpVertex->sx = cx;
- lpVertex->sy = cy;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx+R2;
- lpVertex->sy = cy+R2;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
-
- lpVertex->sx = cx;
- lpVertex->sy = cy+R;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 4
- lpVertex->sx = cx;
- lpVertex->sy = cy;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx;
- lpVertex->sy = cy+R;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx-R2;
- lpVertex->sy = cy+R2;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 5
-
- lpVertex->sx = cx;
- lpVertex->sy = cy;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx-R2;
- lpVertex->sy = cy+R2;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx-R;
- lpVertex->sy = cy;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 6
- lpVertex->sx = cx;
- lpVertex->sy = cy;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx-R;
- lpVertex->sy = cy;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx-R2;
- lpVertex->sy = cy-R2;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 7
- lpVertex->sx = cx;
- lpVertex->sy = cy;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx-R2;
- lpVertex->sy = cy-R2;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx;
- lpVertex->sy = cy-R;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 8
- }
- void BuildTreeNoSort()
- {
- Vector2di v[3];
- Current = -1;
- int LastFace = -1;
- TFace* fptr;
- int sg;
-
- for (int f=0; f<mptr->FCount; f++)
- {
- fptr = &mptr->gFace[f];
- v[0] = gScrp[fptr->v1];
- v[1] = gScrp[fptr->v2];
- v[2] = gScrp[fptr->v3];
- if (v[0].x == 0xFFFFFF) continue;
- if (v[1].x == 0xFFFFFF) continue;
- if (v[2].x == 0xFFFFFF) continue;
- if (fptr->Flags & (sfDarkBack+sfNeedVC)) {
- 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);
- if (sg<0) continue;
- }
-
- fptr->Next=-1;
- if (Current==-1) { Current=f; LastFace = f; } else
- { mptr->gFace[LastFace].Next=f; LastFace=f; }
-
- }
- }
- int BuildTreeClipNoSort()
- {
- Current = -1;
- int fc = 0;
- int LastFace = -1;
- TFace* fptr;
- for (int f=0; f<mptr->FCount; f++)
- {
- fptr = &mptr->gFace[f];
-
- if (fptr->Flags & (sfDarkBack + sfNeedVC) ) {
- MulVectorsVect(SubVectors(rVertex[fptr->v2], rVertex[fptr->v1]), SubVectors(rVertex[fptr->v3], rVertex[fptr->v1]), nv);
- if (nv.x*rVertex[fptr->v1].x + nv.y*rVertex[fptr->v1].y + nv.z*rVertex[fptr->v1].z<0) continue;
- }
- fc++;
- fptr->Next=-1;
- if (Current==-1) { Current=f; LastFace = f; } else
- { mptr->gFace[LastFace].Next=f; LastFace=f; }
-
- }
- return fc;
- }
- void RenderBMPModel(TBMPModel* mptr, float x0, float y0, float z0, int light)
- {
- if (fabs(y0) > -(z0-256*6)) return;
-
- int minx = 10241024;
- int maxx =-10241024;
- int miny = 10241024;
- int maxy =-10241024;
-
- BOOL FOGACTIVE = (FOGON && (FogYBase>0));
- for (int s=0; s<4; s++) {
- if (FOGACTIVE) {
- vFogT[s] = 255-(int) (FogYBase + mptr->gVertex[s].y * FogYGrad);
- if (vFogT[s]<0 ) vFogT[s] = 0;
- if (vFogT[s]>255) vFogT[s]=255;
- vFogT[s]<<=24;
- } else vFogT[s]=255<<24;
-
- rVertex[s].x = mptr->gVertex[s].x + x0;
- rVertex[s].y = mptr->gVertex[s].y * cb + y0;
- rVertex[s].z = mptr->gVertex[s].y * sb + z0;
- if (rVertex[s].z<-256) {
- gScrp[s].x = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
- gScrp[s].y = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
- } else return;
- if (gScrp[s].x > maxx) maxx = gScrp[s].x;
- if (gScrp[s].x < minx) minx = gScrp[s].x;
- if (gScrp[s].y > maxy) maxy = gScrp[s].y;
- if (gScrp[s].y < miny) miny = gScrp[s].y;
- }
- if (minx == 10241024) return;
- if (minx>WinW || maxx<0 || miny>WinH || maxy<0) return;
- int argb = light * 0x00010101 + ((255-GlassL)<<24);
-
- float d = (float) sqrt(x0*x0 + y0*y0 + z0*z0);
- d3dSetTexture(mptr->lpTexture, 128, 128);
-
- //d3dStartBuffer();
-
- if (!lpVertexG)
- d3dStartBufferGBMP();
-
- if (GVCnt>380) {
- if (lpVertexG) d3dEndBufferG(TRUE);
- d3dStartBufferGBMP();
- }
- lpVertexG->sx = (float)gScrp[0].x;
- lpVertexG->sy = (float)gScrp[0].y;
- lpVertexG->sz = _ZSCALE / rVertex[0].z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = argb;
- lpVertexG->specular = vFogT[0];
- lpVertexG->tu = (float)(0.0f);
- lpVertexG->tv = (float)(0.0f);
- lpVertexG++;
- lpVertexG->sx = (float)gScrp[1].x;
- lpVertexG->sy = (float)gScrp[1].y;
- lpVertexG->sz = _ZSCALE / rVertex[1].z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = argb;
- lpVertexG->specular = vFogT[1];
- lpVertexG->tu = (float)(0.995f);
- lpVertexG->tv = (float)(0.0f);
- lpVertexG++;
- lpVertexG->sx = (float)gScrp[2].x;
- lpVertexG->sy = (float)gScrp[2].y;
- lpVertexG->sz = _ZSCALE / rVertex[2].z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = argb;
- lpVertexG->specular = vFogT[2];
- lpVertexG->tu = (float)(0.995f);
- lpVertexG->tv = (float)(0.995f);
- lpVertexG++;
- //=========//
- lpVertexG->sx = (float)gScrp[0].x;
- lpVertexG->sy = (float)gScrp[0].y;
- lpVertexG->sz = _ZSCALE / rVertex[0].z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = argb;
- lpVertexG->specular = vFogT[0];
- lpVertexG->tu = (float)(0.0f);
- lpVertexG->tv = (float)(0.0f);
- lpVertexG++;
- lpVertexG->sx = (float)gScrp[2].x;
- lpVertexG->sy = (float)gScrp[2].y;
- lpVertexG->sz = _ZSCALE / rVertex[2].z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = argb;
- lpVertexG->specular = vFogT[2];
- lpVertexG->tu = (float)(0.995f);
- lpVertexG->tv = (float)(0.995f);
- lpVertexG++;
- lpVertexG->sx = (float)gScrp[3].x;
- lpVertexG->sy = (float)gScrp[3].y;
- lpVertexG->sz = _ZSCALE / rVertex[3].z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = argb;
- lpVertexG->specular = vFogT[3];
- lpVertexG->tu = (float)(0.0f);
- lpVertexG->tv = (float)(0.995f);
- lpVertexG++;
- //d3dFlushBuffer(0, 2);
-
- if (hGTexture!=hTexture) {
- hGTexture=hTexture;
- lpInstructionG->bOpcode = D3DOP_STATERENDER;
- lpInstructionG->bSize = sizeof(D3DSTATE);
- lpInstructionG->wCount = 1;
- lpInstructionG++;
- lpState = (LPD3DSTATE)lpInstructionG;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = hTexture;
- lpState++;
- lpInstructionG = (LPD3DINSTRUCTION)lpState;
- lpwTriCount = (&lpInstructionG->wCount);
- lpInstructionG->bOpcode = D3DOP_TRIANGLE;
- lpInstructionG->bSize = sizeof(D3DTRIANGLE);
- lpInstructionG->wCount = 0;
- lpInstructionG++;
- }
-
- lpTriangle = (LPD3DTRIANGLE)lpInstructionG;
- lpTriangle->wV1 = GVCnt;
- lpTriangle->wV2 = GVCnt+1;
- lpTriangle->wV3 = GVCnt+2;
- lpTriangle->wFlags = 0;
- lpTriangle++;
-
- lpTriangle->wV1 = GVCnt+3;
- lpTriangle->wV2 = GVCnt+4;
- lpTriangle->wV3 = GVCnt+5;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- *lpwTriCount = (*lpwTriCount) + 2;
- lpInstructionG = (LPD3DINSTRUCTION)lpTriangle;
- GVCnt+=6;
- }
- void RenderModel(TModel* _mptr, float x0, float y0, float z0, int light, int VT, float al, float bt)
- {
- int f;
-
- if (fabs(y0) > -(z0-256*6)) return;
- mptr = _mptr;
-
- float ca = (float)cos(al);
- float sa = (float)sin(al);
-
- float cb = (float)cos(bt);
- float sb = (float)sin(bt);
- int minx = 10241024;
- int maxx =-10241024;
- int miny = 10241024;
- int maxy =-10241024;
- BOOL FOGACTIVE = (FOGON && (FogYBase>0));
- int alphamask = (255-GlassL)<<24;
- int ml = light;
-
- TPoint3d p;
- for (int s=0; s<mptr->VCount; s++) {
- p = mptr->gVertex[s];
- if (FOGACTIVE) {
- vFogT[s] = 255-(int)(FogYBase + p.y * FogYGrad);
- if (vFogT[s]<5 ) vFogT[s] = 5;
- if (vFogT[s]>255) vFogT[s]=255;
- vFogT[s]<<=24;
- } else vFogT[s] = 255<<24;
-
- rVertex[s].x = (p.x * ca + p.z * sa) + x0;
- float vz = p.z * ca - p.x * sa;
- rVertex[s].y = (p.y * cb - vz * sb) + y0;
- rVertex[s].z = (vz * cb + p.y * sb) + z0;
- if (rVertex[s].z<-64) {
- gScrp[s].x = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
- gScrp[s].y = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
- } else gScrp[s].x = 0xFFFFFF;
- if (gScrp[s].x > maxx) maxx = gScrp[s].x;
- if (gScrp[s].x < minx) minx = gScrp[s].x;
- if (gScrp[s].y > maxy) maxy = gScrp[s].y;
- if (gScrp[s].y < miny) miny = gScrp[s].y;
- }
- if (minx == 10241024) return;
- if (minx>WinW || maxx<0 || miny>WinH || maxy<0) return;
-
-
- BuildTreeNoSort();
-
- float d = (float) sqrt(x0*x0 + y0*y0 + z0*z0);
- if (LOWRESTX) d = 14*256;
- if (MIPMAP && (d > 12*256)) d3dSetTexture(mptr->lpTexture2, 128, 128);
- else d3dSetTexture(mptr->lpTexture, 256, 256);
- int PrevOpacity = 0;
- int NewOpacity = 0;
- int PrevTransparent = 0;
- int NewTransparent = 0;
-
- d3dStartBuffer();
- int fproc1 = 0;
- int fproc2 = 0;
- f = Current;
- BOOL CKEY = FALSE;
- while( f!=-1 ) {
- TFace *fptr = & mptr->gFace[f];
- f = mptr->gFace[f].Next;
- /*
- if (minx<0)
- if (gScrp[fptr->v1].x <0 && gScrp[fptr->v2].x<0 && gScrp[fptr->v3].x<0) continue;
- if (maxx>WinW)
- if (gScrp[fptr->v1].x >WinW && gScrp[fptr->v2].x>WinW && gScrp[fptr->v3].x>WinW) continue;
- */
- if (fptr->Flags & (sfOpacity | sfTransparent)) fproc2++; else fproc1++;
- int _ml = ml + mptr->VLight[VT][fptr->v1];
- lpVertex->sx = (float)gScrp[fptr->v1].x;
- lpVertex->sy = (float)gScrp[fptr->v1].y;
- lpVertex->sz = _ZSCALE / rVertex[fptr->v1].z;
- lpVertex->rhw = 1.f;
- lpVertex->color = _ml * 0x00010101 | alphamask;
- lpVertex->specular = vFogT[fptr->v1];
- lpVertex->tu = (float)(fptr->tax);
- lpVertex->tv = (float)(fptr->tay);
- lpVertex++;
- _ml = ml + mptr->VLight[VT][fptr->v2];
- lpVertex->sx = (float)gScrp[fptr->v2].x;
- lpVertex->sy = (float)gScrp[fptr->v2].y;
- lpVertex->sz = _ZSCALE / rVertex[fptr->v2].z;
- lpVertex->rhw = 1.f;
- lpVertex->color = _ml * 0x00010101 | alphamask;;
- lpVertex->specular = vFogT[fptr->v2];
- lpVertex->tu = (float)(fptr->tbx);
- lpVertex->tv = (float)(fptr->tby);
- lpVertex++;
- _ml = ml + mptr->VLight[VT][fptr->v3];
- lpVertex->sx = (float)gScrp[fptr->v3].x;
- lpVertex->sy = (float)gScrp[fptr->v3].y;
- lpVertex->sz = _ZSCALE / rVertex[fptr->v3].z;
- lpVertex->rhw = 1.f;
- lpVertex->color = _ml * 0x00010101 | alphamask;;
- lpVertex->specular = vFogT[fptr->v3];
- lpVertex->tu = (float)(fptr->tcx);
- lpVertex->tv = (float)(fptr->tcy);
- lpVertex++;
-
-
- //f = mptr->gFace[f].Next;
- }
- d3dFlushBuffer(fproc1, fproc2);
- }
- void RenderShadowClip(TModel* _mptr,
- float xm0, float ym0, float zm0,
- float x0, float y0, float z0, float cal, float al, float bt)
- {
- int f,CMASK,j;
- mptr = _mptr;
-
- float cla = (float)cos(cal);
- float sla = (float)sin(cal);
- float ca = (float)cos(al);
- float sa = (float)sin(al);
-
- float cb = (float)cos(bt);
- float sb = (float)sin(bt);
-
-
- BOOL BL = FALSE;
- for (int s=0; s<mptr->VCount; s++) {
- float mrx = mptr->gVertex[s].x * cla + mptr->gVertex[s].z * sla;
- float mrz = mptr->gVertex[s].z * cla - mptr->gVertex[s].x * sla;
- float shx = mrx + mptr->gVertex[s].y * SunShadowK;
- float shz = mrz + mptr->gVertex[s].y * SunShadowK;
- float shy = GetLandH(shx + xm0, shz + zm0) - ym0;
- rVertex[s].x = (shx * ca + shz * sa) + x0;
- float vz = shz * ca - shx * sa;
- rVertex[s].y = (shy * cb - vz * sb) + y0;
- rVertex[s].z = (vz * cb + shy * sb) + z0;
- if (rVertex[s].z<0) BL=TRUE;
- if (rVertex[s].z>-256) { gScrp[s].x = 0xFFFFFF; gScrp[s].y = 0xFF; }
- else {
- int f = 0;
- int sx = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
- int sy = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
-
- if (sx>=WinEX) f+=1;
- if (sx<=0 ) f+=2;
- if (sy>=WinEY) f+=4;
- if (sy<=0 ) f+=8;
- gScrp[s].y = f;
- }
- }
-
- if (!BL) return;
-
- float d = (float) sqrt(x0*x0 + y0*y0 + z0*z0);
- if (LOWRESTX) d = 14*256;
- if (MIPMAP && (d > 12*256)) d3dSetTexture(mptr->lpTexture2, 128, 128);
- else d3dSetTexture(mptr->lpTexture, 256, 256);
-
- BuildTreeClipNoSort();
- d3dStartBuffer();
- int fproc1 = 0;
- f = Current;
- while( f!=-1 ) {
-
- vused = 3;
- TFace *fptr = &mptr->gFace[f];
-
- CMASK = 0;
- CMASK|=gScrp[fptr->v1].y;
- CMASK|=gScrp[fptr->v2].y;
- CMASK|=gScrp[fptr->v3].y;
- cp[0].ev.v = rVertex[fptr->v1]; cp[0].tx = fptr->tax; cp[0].ty = fptr->tay;
- cp[1].ev.v = rVertex[fptr->v2]; cp[1].tx = fptr->tbx; cp[1].ty = fptr->tby;
- cp[2].ev.v = rVertex[fptr->v3]; cp[2].tx = fptr->tcx; cp[2].ty = fptr->tcy;
- if (CMASK == 0xFF) {
- for (u=0; u<vused; u++) cp[u].ev.v.z+=16.0f;
- for (u=0; u<vused; u++) ClipVector(ClipZ,u);
- for (u=0; u<vused; u++) cp[u].ev.v.z-=16.0f;
- if (vused<3) goto LNEXT;
- }
-
- if (CMASK & 1) for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) goto LNEXT;
- if (CMASK & 2) for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) goto LNEXT;
- if (CMASK & 4) for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) goto LNEXT;
- if (CMASK & 8) for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) goto LNEXT;
-
- for (j=0; j<vused-2; j++) {
- u = 0;
- lpVertex->sx = (float)(VideoCX - (int)(cp[u].ev.v.x / cp[u].ev.v.z * CameraW));
- lpVertex->sy = (float)(VideoCY + (int)(cp[u].ev.v.y / cp[u].ev.v.z * CameraH));
- lpVertex->sz = (_ZSCALE-0.5f) / cp[u].ev.v.z;
- lpVertex->rhw = 1.f;
- lpVertex->color = GlassL;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0.f;
- lpVertex->tv = 0.f;
- lpVertex++;
- u = j+1;
- lpVertex->sx = (float)(VideoCX - (int)(cp[u].ev.v.x / cp[u].ev.v.z * CameraW));
- lpVertex->sy = (float)(VideoCY + (int)(cp[u].ev.v.y / cp[u].ev.v.z * CameraH));
- lpVertex->sz = (_ZSCALE-0.5f) / cp[u].ev.v.z;
- lpVertex->rhw = 1.f;
- lpVertex->color = GlassL;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0.f;
- lpVertex->tv = 0.f;
- lpVertex++;
- u = j+2;
- lpVertex->sx = (float)(VideoCX - (int)(cp[u].ev.v.x / cp[u].ev.v.z * CameraW));
- lpVertex->sy = (float)(VideoCY + (int)(cp[u].ev.v.y / cp[u].ev.v.z * CameraH));
- lpVertex->sz = (_ZSCALE-0.5f) / cp[u].ev.v.z;
- lpVertex->rhw = 1.f;
- lpVertex->color = GlassL;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0.f;
- lpVertex->tv = 0.f;
- lpVertex++;
- fproc1++;
- }
-
- LNEXT:
- f = mptr->gFace[f].Next;
- }
- d3dFlushBuffer(fproc1, 0);
-
- }
- void RenderModelClip(TModel* _mptr, float x0, float y0, float z0, int light, int VT, float al, float bt)
- {
- int f,CMASK;
- //if (fabs(y0) > -(z0-256*6)) return;
- mptr = _mptr;
-
- float ca = (float)cos(al);
- float sa = (float)sin(al);
-
- float cb = (float)cos(bt);
- float sb = (float)sin(bt);
-
- int flight = (int)light;
- DWORD almask;
- DWORD alphamask = (255-GlassL)<<24;
-
-
- BOOL BL = FALSE;
- BOOL FOGACTIVE = (FOGON && (FogYBase>0));
- for (int s=0; s<mptr->VCount; s++) {
- if (FOGACTIVE) {
- vFogT[s] = 255-(int)(FogYBase + mptr->gVertex[s].y * FogYGrad);
- if (vFogT[s]<5 ) vFogT[s] = 5;
- if (vFogT[s]>255) vFogT[s]=255;
- } else vFogT[s] = 255;
-
- rVertex[s].x = (mptr->gVertex[s].x * ca + mptr->gVertex[s].z * sa) /* * mdlScale */ + x0;
- float vz = mptr->gVertex[s].z * ca - mptr->gVertex[s].x * sa;
- rVertex[s].y = (mptr->gVertex[s].y * cb - vz * sb) /* * mdlScale */ + y0;
- rVertex[s].z = (vz * cb + mptr->gVertex[s].y * sb) /* * mdlScale */ + z0;
- if (rVertex[s].z<0) BL=TRUE;
- if (rVertex[s].z>-256) { gScrp[s].x = 0xFFFFFF; gScrp[s].y = 0xFF; }
- else {
- int f = 0;
- int sx = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
- int sy = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
-
- if (sx>=WinEX) f+=1;
- if (sx<=0 ) f+=2;
- if (sy>=WinEY) f+=4;
- if (sy<=0 ) f+=8;
- gScrp[s].y = f;
- }
- }
-
- if (!BL) return;
-
- if (LOWRESTX) d3dSetTexture(mptr->lpTexture2, 128, 128);
- else d3dSetTexture(mptr->lpTexture, 256, 256);
-
- BuildTreeClipNoSort();
-
- d3dStartBuffer();
- f = Current;
- int fproc1 = 0;
- int fproc2 = 0;
- BOOL CKEY = FALSE;
- while( f!=-1 ) {
-
- vused = 3;
- TFace *fptr = &mptr->gFace[f];
-
- CMASK = 0;
-
- CMASK|=gScrp[fptr->v1].y;
- CMASK|=gScrp[fptr->v2].y;
- CMASK|=gScrp[fptr->v3].y;
-
- 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];
- 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];
- 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];
-
- {
- for (u=0; u<vused; u++) cp[u].ev.v.z+= 8.0f;
- for (u=0; u<vused; u++) ClipVector(ClipZ,u);
- for (u=0; u<vused; u++) cp[u].ev.v.z-= 8.0f;
- if (vused<3) goto LNEXT;
- }
-
- if (CMASK & 1) for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) goto LNEXT;
- if (CMASK & 2) for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) goto LNEXT;
- if (CMASK & 4) for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) goto LNEXT;
- if (CMASK & 8) for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) goto LNEXT;
- almask = 0xFF000000;
- if (fptr->Flags & sfTransparent) almask = 0x70000000;
- if (almask > alphamask)
- almask = alphamask;
-
- for (u=0; u<vused-2; u++) {
- int _flight = flight + cp[0].ev.Light;
- lpVertex->sx = (float)(VideoCX - (int)(cp[0].ev.v.x / cp[0].ev.v.z * CameraW));
- lpVertex->sy = (float)(VideoCY + (int)(cp[0].ev.v.y / cp[0].ev.v.z * CameraH));
- lpVertex->sz = _ZSCALE / cp[0].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = _flight * 0x00010101 | almask;
- lpVertex->specular = ((int)cp[0].ev.Fog)<<24;
- lpVertex->tu = (float)(cp[0].tx);
- lpVertex->tv = (float)(cp[0].ty);
- lpVertex++;
- _flight = flight + cp[u+1].ev.Light;
- lpVertex->sx = (float)(VideoCX - (int)(cp[u+1].ev.v.x / cp[u+1].ev.v.z * CameraW));
- lpVertex->sy = (float)(VideoCY + (int)(cp[u+1].ev.v.y / cp[u+1].ev.v.z * CameraH));
- lpVertex->sz = _ZSCALE / cp[u+1].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = _flight * 0x00010101 | almask;
- lpVertex->specular = ((int)cp[u+1].ev.Fog)<<24;
- lpVertex->tu = (float)(cp[u+1].tx);
- lpVertex->tv = (float)(cp[u+1].ty);
- lpVertex++;
- _flight = flight + cp[u+2].ev.Light;
- lpVertex->sx = (float)(VideoCX - (int)(cp[u+2].ev.v.x / cp[u+2].ev.v.z * CameraW));
- lpVertex->sy = (float)(VideoCY + (int)(cp[u+2].ev.v.y / cp[u+2].ev.v.z * CameraH));
- lpVertex->sz = _ZSCALE / cp[u+2].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = _flight * 0x00010101 | almask;
- lpVertex->specular = ((int)cp[u+2].ev.Fog)<<24;
- lpVertex->tu = (float)(cp[u+2].tx);
- lpVertex->tv = (float)(cp[u+2].ty);
- lpVertex++;
- if (fptr->Flags & (sfOpacity | sfTransparent)) fproc2++; else fproc1++;
- }
- LNEXT:
- f = mptr->gFace[f].Next;
- }
- d3dFlushBuffer(fproc1, fproc2);
- }
- void RenderModelClipEnvMap(TModel* _mptr, float x0, float y0, float z0, float al, float bt)
- {
- int f,CMASK;
- mptr = _mptr;
-
- float ca = (float)cos(al);
- float sa = (float)sin(al);
- float cb = (float)cos(bt);
- float sb = (float)sin(bt);
-
- DWORD PHCOLOR = 0xFFFFFFFF;
-
- BOOL BL = FALSE;
-
- for (int s=0; s<mptr->VCount; s++) {
-
- rVertex[s].x = (mptr->gVertex[s].x * ca + mptr->gVertex[s].z * sa) /* * mdlScale */ + x0;
- float vz = mptr->gVertex[s].z * ca - mptr->gVertex[s].x * sa;
- rVertex[s].y = (mptr->gVertex[s].y * cb - vz * sb) /* * mdlScale */ + y0;
- rVertex[s].z = (vz * cb + mptr->gVertex[s].y * sb) /* * mdlScale */ + z0;
- if (rVertex[s].z<0) BL=TRUE;
- if (rVertex[s].z>-256) { gScrp[s].x = 0xFFFFFF; gScrp[s].y = 0xFF; }
- else {
- int f = 0;
- int sx = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
- int sy = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
-
- if (sx>=WinEX) f+=1;
- if (sx<=0 ) f+=2;
- if (sy>=WinEY) f+=4;
- if (sy<=0 ) f+=8;
- gScrp[s].y = f;
- }
- }
-
- d3dSetTexture(TFX_ENVMAP.lpImage, TFX_ENVMAP.W, TFX_ENVMAP.W);
- SetRenderStates(FALSE, D3DBLEND_ONE);
-
- BuildTreeClipNoSort();
-
- d3dStartBuffer();
- f = Current;
- int fproc1 = 0;
-
- while( f!=-1 ) {
-
- vused = 3;
- TFace *fptr = &mptr->gFace[f];
- if (!(fptr->Flags & sfEnvMap)) goto LNEXT;
-
- CMASK = 0;
-
- CMASK|=gScrp[fptr->v1].y;
- CMASK|=gScrp[fptr->v2].y;
- CMASK|=gScrp[fptr->v3].y;
-
- 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;
- 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;
- 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;
-
-
- {
- for (u=0; u<vused; u++) cp[u].ev.v.z+= 8.0f;
- for (u=0; u<vused; u++) ClipVector(ClipZ,u);
- for (u=0; u<vused; u++) cp[u].ev.v.z-= 8.0f;
- if (vused<3) goto LNEXT;
- }
-
- if (CMASK & 1) for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) goto LNEXT;
- if (CMASK & 2) for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) goto LNEXT;
- if (CMASK & 4) for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) goto LNEXT;
- if (CMASK & 8) for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) goto LNEXT;
-
- for (u=0; u<vused-2; u++) {
- lpVertex->sx = (float)(VideoCX - (int)(cp[0].ev.v.x / cp[0].ev.v.z * CameraW));
- lpVertex->sy = (float)(VideoCY + (int)(cp[0].ev.v.y / cp[0].ev.v.z * CameraH));
- lpVertex->sz = _ZSCALE / cp[0].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = PHCOLOR;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(cp[0].tx);
- lpVertex->tv = (float)(cp[0].ty);
- lpVertex++;
-
- lpVertex->sx = (float)(VideoCX - (int)(cp[u+1].ev.v.x / cp[u+1].ev.v.z * CameraW));
- lpVertex->sy = (float)(VideoCY + (int)(cp[u+1].ev.v.y / cp[u+1].ev.v.z * CameraH));
- lpVertex->sz = _ZSCALE / cp[u+1].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = PHCOLOR;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(cp[u+1].tx);
- lpVertex->tv = (float)(cp[u+1].ty);
- lpVertex++;
-
- lpVertex->sx = (float)(VideoCX - (int)(cp[u+2].ev.v.x / cp[u+2].ev.v.z * CameraW));
- lpVertex->sy = (float)(VideoCY + (int)(cp[u+2].ev.v.y / cp[u+2].ev.v.z * CameraH));
- lpVertex->sz = _ZSCALE / cp[u+2].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = PHCOLOR;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(cp[u+2].tx);
- lpVertex->tv = (float)(cp[u+2].ty);
- lpVertex++;
- fproc1++;
- }
- LNEXT:
- f = mptr->gFace[f].Next;
- }
- d3dFlushBuffer(fproc1, 0);
- SetRenderStates(TRUE, D3DBLEND_INVSRCALPHA);
- }
- void RenderModelClipPhongMap(TModel* _mptr, float x0, float y0, float z0, float al, float bt)
- {
- int f,CMASK;
- mptr = _mptr;
-
- float ca = (float)cos(al);
- float sa = (float)sin(al);
- float cb = (float)cos(bt);
- float sb = (float)sin(bt);
- int rv = SkyR +64; if (rv>255) rv = 255;
- int gv = SkyG +64; if (gv>255) gv = 255;
- int bv = SkyB +64; if (bv>255) bv = 255;
- DWORD PHCOLOR = 0xFF000000 + (rv<<16) + (gv<<8) + bv;
-
- BOOL BL = FALSE;
-
- for (int s=0; s<mptr->VCount; s++) {
-
- rVertex[s].x = (mptr->gVertex[s].x * ca + mptr->gVertex[s].z * sa) /* * mdlScale */ + x0;
- float vz = mptr->gVertex[s].z * ca - mptr->gVertex[s].x * sa;
- rVertex[s].y = (mptr->gVertex[s].y * cb - vz * sb) /* * mdlScale */ + y0;
- rVertex[s].z = (vz * cb + mptr->gVertex[s].y * sb) /* * mdlScale */ + z0;
- if (rVertex[s].z<0) BL=TRUE;
- if (rVertex[s].z>-256) { gScrp[s].x = 0xFFFFFF; gScrp[s].y = 0xFF; }
- else {
- int f = 0;
- int sx = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
- int sy = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
-
- if (sx>=WinEX) f+=1;
- if (sx<=0 ) f+=2;
- if (sy>=WinEY) f+=4;
- if (sy<=0 ) f+=8;
- gScrp[s].y = f;
- }
- }
-
- d3dSetTexture(TFX_SPECULAR.lpImage, TFX_SPECULAR.W, TFX_SPECULAR.W);
- SetRenderStates(FALSE, D3DBLEND_ONE);
-
- BuildTreeClipNoSort();
-
- d3dStartBuffer();
- f = Current;
- int fproc1 = 0;
-
- while( f!=-1 ) {
-
- vused = 3;
- TFace *fptr = &mptr->gFace[f];
- if (!(fptr->Flags & sfPhong)) goto LNEXT;
-
- CMASK = 0;
-
- CMASK|=gScrp[fptr->v1].y;
- CMASK|=gScrp[fptr->v2].y;
- CMASK|=gScrp[fptr->v3].y;
-
- 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;
- 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;
- 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;
-
- {
- for (u=0; u<vused; u++) cp[u].ev.v.z+= 8.0f;
- for (u=0; u<vused; u++) ClipVector(ClipZ,u);
- for (u=0; u<vused; u++) cp[u].ev.v.z-= 8.0f;
- if (vused<3) goto LNEXT;
- }
-
- if (CMASK & 1) for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) goto LNEXT;
- if (CMASK & 2) for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) goto LNEXT;
- if (CMASK & 4) for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) goto LNEXT;
- if (CMASK & 8) for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) goto LNEXT;
-
- for (u=0; u<vused-2; u++) {
- lpVertex->sx = (float)(VideoCX - (int)(cp[0].ev.v.x / cp[0].ev.v.z * CameraW));
- lpVertex->sy = (float)(VideoCY + (int)(cp[0].ev.v.y / cp[0].ev.v.z * CameraH));
- lpVertex->sz = _ZSCALE / cp[0].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = PHCOLOR;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(cp[0].tx);
- lpVertex->tv = (float)(cp[0].ty);
- lpVertex++;
-
- lpVertex->sx = (float)(VideoCX - (int)(cp[u+1].ev.v.x / cp[u+1].ev.v.z * CameraW));
- lpVertex->sy = (float)(VideoCY + (int)(cp[u+1].ev.v.y / cp[u+1].ev.v.z * CameraH));
- lpVertex->sz = _ZSCALE / cp[u+1].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = PHCOLOR;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(cp[u+1].tx);
- lpVertex->tv = (float)(cp[u+1].ty);
- lpVertex++;
-
- lpVertex->sx = (float)(VideoCX - (int)(cp[u+2].ev.v.x / cp[u+2].ev.v.z * CameraW));
- lpVertex->sy = (float)(VideoCY + (int)(cp[u+2].ev.v.y / cp[u+2].ev.v.z * CameraH));
- lpVertex->sz = _ZSCALE / cp[u+2].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = PHCOLOR;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(cp[u+2].tx);
- lpVertex->tv = (float)(cp[u+2].ty);
- lpVertex++;
- fproc1++;
- }
- LNEXT:
- f = mptr->gFace[f].Next;
- }
- d3dFlushBuffer(fproc1, 0);
- SetRenderStates(TRUE, D3DBLEND_INVSRCALPHA);
- }
- void RenderModelSun(TModel* _mptr, float x0, float y0, float z0, int Alpha)
- {
- int f;
- mptr = _mptr;
- int minx = 10241024;
- int maxx =-10241024;
- int miny = 10241024;
- int maxy =-10241024;
-
- for (int s=0; s<mptr->VCount; s++) {
- rVertex[s].x = mptr->gVertex[s].x + x0;
- rVertex[s].y = mptr->gVertex[s].y + y0;
- rVertex[s].z = mptr->gVertex[s].z + z0;
- if (rVertex[s].z>-64) gScrp[s].x = 0xFFFFFF; else {
- gScrp[s].x = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
- gScrp[s].y = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH); }
- if (gScrp[s].x > maxx) maxx = gScrp[s].x;
- if (gScrp[s].x < minx) minx = gScrp[s].x;
- if (gScrp[s].y > maxy) maxy = gScrp[s].y;
- if (gScrp[s].y < miny) miny = gScrp[s].y;
- }
- if (minx == 10241024) return;
- if (minx>WinW || maxx<0 || miny>WinH || maxy<0) return;
-
- BuildTreeNoSort();
-
- d3dSetTexture(mptr->lpTexture2, 128, 128);
-
- d3dStartBuffer();
- DWORD alpha = Alpha;
- alpha = (alpha<<24) | 0x00FFFFFF;
- int fproc1 = 0;
- f = Current;
- while( f!=-1 ) {
- TFace *fptr = & mptr->gFace[f];
- fproc1++;
- lpVertex->sx = (float)gScrp[fptr->v1].x;
- lpVertex->sy = (float)gScrp[fptr->v1].y;
- lpVertex->sz = 0.0002;//_ZSCALE / rVertex[fptr->v1].z;
- lpVertex->rhw = 1.f;
- lpVertex->color = alpha;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(fptr->tax);
- lpVertex->tv = (float)(fptr->tay);
- lpVertex++;
- lpVertex->sx = (float)gScrp[fptr->v2].x;
- lpVertex->sy = (float)gScrp[fptr->v2].y;
- lpVertex->sz = 0.0002;//_ZSCALE / rVertex[fptr->v2].z;
- lpVertex->rhw = 1.f;
- lpVertex->color = alpha;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(fptr->tbx);
- lpVertex->tv = (float)(fptr->tby);
- lpVertex++;
- lpVertex->sx = (float)gScrp[fptr->v3].x;
- lpVertex->sy = (float)gScrp[fptr->v3].y;
- lpVertex->sz = 0.0002;//_ZSCALE / rVertex[fptr->v3].z;
- lpVertex->rhw = 1.f;
- lpVertex->color = alpha;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(fptr->tcx);
- lpVertex->tv = (float)(fptr->tcy);
- lpVertex++;
-
- f = mptr->gFace[f].Next;
- }
- lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + 1024*3);
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 2;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = hTexture;
- lpState++;
-
- lpState->drstRenderStateType = D3DRENDERSTATE_DESTBLEND;
- lpState->dwArg[0] = D3DBLEND_ONE;
- lpState++;
-
-
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstruction->wCount = 1U;
- lpInstruction++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = fproc1*3;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
- lpInstruction->bOpcode = D3DOP_TRIANGLE;
- lpInstruction->bSize = sizeof(D3DTRIANGLE);
- lpInstruction->wCount = fproc1;
- lpInstruction++;
- lpTriangle = (LPD3DTRIANGLE)lpInstruction;
-
- int ii = 0;
- for (int i=0; i<fproc1; i++) {
- lpTriangle->wV1 = ii++;
- lpTriangle->wV2 = ii++;
- lpTriangle->wV3 = ii++;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- }
- lpInstruction = (LPD3DINSTRUCTION)lpTriangle;
-
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 1;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_DESTBLEND;
- lpState->dwArg[0] = D3DBLEND_INVSRCALPHA;
- lpState++;
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 3;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpInstruction = (LPD3DINSTRUCTION)lpState;
-
-
- lpInstruction->bOpcode = D3DOP_EXIT;
- lpInstruction->bSize = 0UL;
- lpInstruction->wCount = 0U;
- lpd3dExecuteBuffer->Unlock( );
-
- hRes = lpd3dDevice->Execute(lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
- //if (FAILED(hRes)) DoHalt("Error execute buffer");
- dFacesCount+=fproc1;
- }
- void RenderNearModel(TModel* _mptr, float x0, float y0, float z0, int light, float al, float bt)
- {
- BOOL b = LOWRESTX;
- Vector3d v;
- v.x = 0; v.y =-128; v.z = 0;
- CalcFogLevel_Gradient(v);
- FogYGrad = 0;
-
- LOWRESTX = FALSE;
- RenderModelClip(_mptr, x0, y0, z0, light, 0, al, bt);
- LOWRESTX = b;
- }
- void RenderModelClipWater(TModel* _mptr, float x0, float y0, float z0, int light, int VT, float al, float bt)
- {
- }
- void RenderCharacter(int index)
- {
- }
- void RenderExplosion(int index)
- {
- }
- void RenderShip()
- {
- }
- void RenderElements()
- {
- d3dLastTexture = d3dmemmapsize+1;
- hTexture = NULL;
- int fproc1 = 0;
-
- for (int eg = 0; eg<ElCount; eg++) {
- for (int e = 0; e<Elements[eg].ECount; e++) {
- Vector3d rpos;
- TElement *el = &Elements[eg].EList[e];
- rpos.x = el->pos.x - CameraX;
- rpos.y = el->pos.y - CameraY;
- rpos.z = el->pos.z - CameraZ;
- float r = el->R;
- rpos = RotateVector(rpos);
- if (rpos.z > -64) continue;
- if ( fabs(rpos.x) > -rpos.z) continue;
- if ( fabs(rpos.y) > -rpos.z) continue;
- if (!fproc1) d3dStartBuffer();
- float sx = VideoCX - (int)(CameraW * rpos.x / rpos.z * 16) / 16.f;
- float sy = VideoCY + (int)(CameraH * rpos.y / rpos.z * 16) / 16.f;
- RenderCircle(sx, sy, rpos.z, -r*CameraW*0.64 / rpos.z, Elements[eg].RGBA, Elements[eg].RGBA2);
- fproc1+=8;
- if (fproc1>256) {
- d3dFlushBuffer(fproc1, 0);
- fproc1 = 0;
- }
- }
-
- }
- if (fproc1) d3dFlushBuffer(fproc1, 0);
-
- fproc1 = 0;
- for (int b=0; b<BloodTrail.Count; b++) {
- Vector3d rpos = BloodTrail.Trail[b].pos;
- DWORD A1 = (0xE0 * BloodTrail.Trail[b].LTime / 20000); if (A1>0xE0) A1=0xE0;
- DWORD A2 = (0x20 * BloodTrail.Trail[b].LTime / 20000); if (A2>0x20) A2=0x20;
- rpos.x = rpos.x - CameraX;
- rpos.y = rpos.y - CameraY;
- rpos.z = rpos.z - CameraZ;
- rpos = RotateVector(rpos);
- if (rpos.z > -64) continue;
- if ( fabs(rpos.x) > -rpos.z) continue;
- if ( fabs(rpos.y) > -rpos.z) continue;
- if (!fproc1) d3dStartBuffer();
- float sx = VideoCX - (int)(CameraW * rpos.x / rpos.z * 16) / 16.f;
- float sy = VideoCY + (int)(CameraH * rpos.y / rpos.z * 16) / 16.f;
- RenderCircle(sx, sy, rpos.z, -12*CameraW*0.64 / rpos.z, (A1<<24)+conv_xGx(0x700000), (A2<<24)+conv_xGx(0x300000));
- fproc1+=8;
-
- if (fproc1>256) {
- d3dFlushBuffer(fproc1, 0);
- fproc1 = 0;
- }
- }
-
- if (fproc1) d3dFlushBuffer(fproc1, 0);
-
- GlassL = 0;
- }
- void RenderCharacterPost(TCharacter *cptr)
- {
- //mdlScale = 1.0f;
-
- CreateChMorphedModel(cptr);
-
- float zs = (float)sqrt( cptr->rpos.x*cptr->rpos.x + cptr->rpos.y*cptr->rpos.y + cptr->rpos.z*cptr->rpos.z);
- if (zs > ctViewR*256) return;
- GlassL = 0;
- if (zs > 256 * (ctViewR-4))
- GlassL = min(255, (zs/4 - 64*(ctViewR-4)));
-
- waterclip = FALSE;
-
- if ( cptr->rpos.z >-256*10)
- RenderModelClip(cptr->pinfo->mptr,
- cptr->rpos.x, cptr->rpos.y, cptr->rpos.z, 210, 0,
- -cptr->alpha + pi / 2 + CameraAlpha,
- CameraBeta );
- else
- RenderModel(cptr->pinfo->mptr,
- cptr->rpos.x, cptr->rpos.y, cptr->rpos.z, 210, 0,
- -cptr->alpha + pi / 2 + CameraAlpha,
- CameraBeta );
-
- if (!SHADOWS3D) return;
- if (zs > 256 * (ctViewR-8)) return;
-
- int Al = 0x60;
-
- if (cptr->Health==0) {
- int at = cptr->pinfo->Animation[cptr->Phase].AniTime;
- if (Tranq) return;
- if (cptr->FTime==at-1) return;
- Al = Al * (at-cptr->FTime) / at; }
- if (cptr->AI==0) Al = 0x50;
- GlassL = (Al<<24) + 0x00222222;
-
- RenderShadowClip(cptr->pinfo->mptr,
- cptr->pos.x, cptr->pos.y, cptr->pos.z,
- cptr->rpos.x, cptr->rpos.y, cptr->rpos.z,
- pi/2-cptr->alpha,
- CameraAlpha,
- CameraBeta );
- }
- void RenderShipPost()
- {
- if (Ship.State==-1) return;
- GlassL = 0;
- zs = (int)VectorLength(Ship.rpos);
- if (zs > 256 * (ctViewR)) return;
-
- if (zs > 256 * (ctViewR-4))
- GlassL = min(255,(int)(zs - 256 * (ctViewR-4)) / 4);
-
-
- /*grConstantColorValue( (255-GlassL) << 24);*/
- CreateMorphedModel(ShipModel.mptr, &ShipModel.Animation[0], Ship.FTime, 1.0);
-
- if ( fabs(Ship.rpos.z) < 4000)
- RenderModelClip(ShipModel.mptr,
- Ship.rpos.x, Ship.rpos.y, Ship.rpos.z, 210, 0, -Ship.alpha -pi/2 + CameraAlpha, CameraBeta);
- else
- RenderModel(ShipModel.mptr,
- Ship.rpos.x, Ship.rpos.y, Ship.rpos.z, 210, 0, -Ship.alpha -pi/2+ CameraAlpha, CameraBeta);
-
- /*grConstantColorValue( 0xFF000000);*/
- }
- void Render3DHardwarePosts()
- {
-
-
- TCharacter *cptr;
- for (int c=0; c<ChCount; c++) {
- cptr = &Characters[c];
- cptr->rpos.x = cptr->pos.x - CameraX;
- cptr->rpos.y = cptr->pos.y - CameraY;
- cptr->rpos.z = cptr->pos.z - CameraZ;
-
- float r = (float)max( fabs(cptr->rpos.x), fabs(cptr->rpos.z) );
- int ri = -1 + (int)(r / 256.f + 0.5f);
- if (ri < 0) ri = 0;
- if (ri > ctViewR) continue;
- if (FOGON)
- CalcFogLevel_Gradient(cptr->rpos);
-
- cptr->rpos = RotateVector(cptr->rpos);
- float br = BackViewR + DinoInfo[cptr->CType].Radius;
- if (cptr->rpos.z > br) continue;
- if ( fabs(cptr->rpos.x) > -cptr->rpos.z + br ) continue;
- if ( fabs(cptr->rpos.y) > -cptr->rpos.z + br ) continue;
- RenderCharacterPost(cptr);
- }
- Ship.rpos.x = Ship.pos.x - CameraX;
- Ship.rpos.y = Ship.pos.y - CameraY;
- Ship.rpos.z = Ship.pos.z - CameraZ;
- float r = (float)max( fabs(Ship.rpos.x), fabs(Ship.rpos.z) );
- int ri = -1 + (int)(r / 256.f + 0.2f);
- if (ri < 0) ri = 0;
- if (ri < ctViewR) {
- if (FOGON)
- CalcFogLevel_Gradient(Ship.rpos);
- Ship.rpos = RotateVector(Ship.rpos);
- if (Ship.rpos.z > BackViewR) goto NOSHIP;
- if ( fabs(Ship.rpos.x) > -Ship.rpos.z + BackViewR ) goto NOSHIP;
- RenderShipPost();
- }
- NOSHIP: ;
- SunLight *= GetTraceK(SunScrX, SunScrY);
- }
- void ClearVideoBuf()
- {
- }
- int CircleCX, CircleCY;
- WORD CColor;
- void PutPixel(int x, int y)
- { *((WORD*)ddsd.lpSurface + y*lsw + x) = CColor; }
- void Put8pix(int X,int Y)
- {
- PutPixel(CircleCX + X, CircleCY + Y);
- PutPixel(CircleCX + X, CircleCY - Y);
- PutPixel(CircleCX - X, CircleCY + Y);
- PutPixel(CircleCX - X, CircleCY - Y);
- PutPixel(CircleCX + Y, CircleCY + X);
- PutPixel(CircleCX + Y, CircleCY - X);
- PutPixel(CircleCX - Y, CircleCY + X);
- PutPixel(CircleCX - Y, CircleCY - X);
- }
- void DrawCircle(int cx, int cy, int R)
- {
- int d = 3 - (2 * R);
- int x = 0;
- int y = R;
- CircleCX=cx;
- CircleCY=cy;
- do {
- Put8pix(x,y); x++;
- if (d < 0) d = d + (x<<2) + 6; else
- { d = d + (x - y) * 4 + 10; y--; }
- } while (x<y);
- Put8pix(x,y);
- }
- void DrawBox( WORD *lfbPtr, int lsw, int xx, int yy, WORD c)
- {
- yy = yy * lsw + xx;
- *(lfbPtr + yy) = c;
- *(lfbPtr + yy + 1) = c;
- yy+=lsw;
- *(lfbPtr + yy) = c;
- *(lfbPtr + yy + 1) = c;
- }
- void DrawHMap()
- {
- int c;
- DrawPicture(VideoCX-MapPic.W/2, VideoCY - MapPic.H/2-6, MapPic);
-
- ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- if( lpddBack->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
- lsw = ddsd.lPitch / 2;
- int RShift, GShift;
- if (VMFORMAT565) {
- RShift=11; GShift=6;
- } else {
- RShift=10; GShift=5;
- }
- int xx = VideoCX - 128 + (CCX>>2);
- int yy = VideoCY - 128 + (CCY>>2);
- if (yy<0 || yy>=WinH) goto endmap;
- if (xx<0 || xx>=WinW) goto endmap;
- DrawBox((WORD*)ddsd.lpSurface, lsw, xx+1, yy+1, 8<<RShift);
- DrawBox((WORD*)ddsd.lpSurface, lsw, xx, yy, 30<<RShift);
- /*
- *((WORD*)ddsd.lpSurface + yy*lsw + xx) = 30<<RShift;
- *((WORD*)ddsd.lpSurface + yy*lsw + xx + 1) = 30<<RShift;
- yy++;
- *((WORD*)ddsd.lpSurface + yy*lsw + xx) = 30<<RShift;
- *((WORD*)ddsd.lpSurface + yy*lsw + xx + 1) = 30<<RShift;
- */
- CColor = 4<<GShift; DrawCircle(xx+1, yy+1, (ctViewR/4));
- CColor = 18<<GShift; DrawCircle(xx, yy, (ctViewR/4));
- if (RadarMode)
- for (c=0; c<ChCount; c++) {
- if (Characters[c].AI<10) continue;
- if (! (TargetDino & (1<<Characters[c].AI)) ) continue;
- if (!Characters[c].Health) continue;
- xx = VideoCX - 128 + (int)Characters[c].pos.x / 1024;
- yy = VideoCY - 128 + (int)Characters[c].pos.z / 1024;
- if (yy<=0 || yy>=WinH) goto endmap;
- if (xx<=0 || xx>=WinW) goto endmap;
- DrawBox((WORD*)ddsd.lpSurface, lsw, xx, yy, 30<<GShift);
- }
-
- endmap:
- lpddBack->Unlock(ddsd.lpSurface);
- }
- void RenderSun(float x, float y, float z)
- {
- SunScrX = VideoCX + (int)(x / (-z) * CameraW);
- SunScrY = VideoCY - (int)(y / (-z) * CameraH);
- GetSkyK(SunScrX, SunScrY);
-
- float d = (float)sqrt(x*x + y*y);
- if (d<2048) {
- SunLight = (220.f- d*220.f/2048.f);
- if (SunLight>140) SunLight = 140;
- SunLight*=SkyTraceK;
- }
-
-
- if (d>812.f) d = 812.f;
- d = (2048.f + d) / 3048.f;
- d+=(1.f-SkyTraceK)/2.f;
- if (OptDayNight==2) d=1.5;
- RenderModelSun(SunModel, x*d, y*d, z*d, (int)(200.f* SkyTraceK));
- }
- void RotateVVector(Vector3d& v)
- {
- float x = v.x * ca - v.z * sa;
- float y = v.y;
- float z = v.z * ca + v.x * sa;
- float xx = x;
- float xy = y * cb + z * sb;
- float xz = z * cb - y * sb;
-
- v.x = xx; v.y = xy; v.z = xz;
- }
- void RenderSkyPlane()
- {
-
- Vector3d v,vbase;
- Vector3d tx,ty,nv;
- float p,q, qx, qy, qz, px, py, pz, rx, ry, rz, ddx, ddy;
- float lastdt = 0.f;
- d3dSetTexture(SkyPic, 256, 256);
-
- nv.x = 512; nv.y = 4024; nv.z=0;
- cb = (float)cos(CameraBeta);
- sb = (float)sin(CameraBeta);
- SKYDTime = RealTime & ((1<<17) - 1);
- float sh = - CameraY;
- if (MapMinY==10241024)
- MapMinY=0;
- sh = (float)((int)MapMinY)*ctHScale - CameraY;
- if (sh<-2024) sh=-2024;
- v.x = 0;
- v.z = ctViewR*256.f;
- v.y = sh;
-
- vbase.x = v.x;
- vbase.y = v.y * cb + v.z * sb;
- vbase.z = v.z * cb - v.y * sb;
- if (vbase.z < 128) vbase.z = 128;
- int scry = VideoCY - (int)(vbase.y / vbase.z * CameraH);
-
- if (scry<0) return;
- if (scry>WinEY+1) scry = WinEY+1;
-
- cb = (float)cos(CameraBeta-0.15);
- sb = (float)sin(CameraBeta-0.15);
- v.x = 0;
- v.z = 2*256.f*256.f;
- v.y = 512;
- vbase.x = v.x;
- vbase.y = v.y * cb + v.z * sb;
- vbase.z = v.z * cb - v.y * sb;
- if (vbase.z < 128) vbase.z = 128;
- int _scry = VideoCY - (int)(vbase.y / vbase.z * CameraH);
- if (scry > _scry) scry = _scry;
-
- tx.x=0.002f; tx.y=0; tx.z=0;
- ty.x=0.0f; ty.y=0; ty.z=0.002f;
- nv.x=0; nv.y=-1.f; nv.z=0;
-
- RotateVVector(tx);
- RotateVVector(ty);
- RotateVVector(nv);
-
- sh = 4*512*16;
- vbase.x = -CameraX;
- vbase.y = sh;
- vbase.z = +CameraZ;
- RotateVVector(vbase);
- //============= calc render params =================//
- p = nv.x * vbase.x + nv.y * vbase.y + nv.z * vbase.z;
- ddx = vbase.x * tx.x + vbase.y * tx.y + vbase.z * tx.z;
- ddy = vbase.x * ty.x + vbase.y * ty.y + vbase.z * ty.z;
- qx = CameraH * nv.x; qy = CameraW * nv.y; qz = CameraW*CameraH * nv.z;
- px = p*CameraH*tx.x; py = p*CameraW*tx.y; pz = p*CameraW*CameraH* tx.z;
- rx = p*CameraH*ty.x; ry = p*CameraW*ty.y; rz = p*CameraW*CameraH* ty.z;
- px=px - ddx*qx; py=py - ddx*qy; pz=pz - ddx*qz;
- rx=rx - ddy*qx; ry=ry - ddy*qy; rz=rz - ddy*qz;
- float za = CameraW * CameraH * p / (qy * VideoCY + qz);
- float zb = CameraW * CameraH * p / (qy * (VideoCY-scry/2.f) + qz);
- float zc = CameraW * CameraH * p / (qy * (VideoCY-scry) + qz);
- float _za = fabs(za) - 100200.f; if (_za<0) _za=0.f;
- float _zb = fabs(zb) - 100200.f; if (_zb<0) _zb=0.f;
- float _zc = fabs(zc) - 100200.f; if (_zc<0) _zc=0.f;
-
- int alpha = (int)(255*40240 / (40240+_za));
- int alphb = (int)(255*40240 / (40240+_zb));
- int alphc = (int)(255*40240 / (40240+_zc));
-
- int sx1 = - VideoCX;
- int sx2 = + VideoCX;
- float qx1 = qx * sx1 + qz;
- float qx2 = qx * sx2 + qz;
- float qyy;
- // d3dStartBuffer();
- ZeroMemory(&d3dExeBufDesc, sizeof(d3dExeBufDesc));
- d3dExeBufDesc.dwSize = sizeof(d3dExeBufDesc);
- hRes = lpd3dExecuteBufferG->Lock( &d3dExeBufDesc );
- if (FAILED(hRes)) DoHalt("Error locking execute buffer");
- lpVertex = (LPD3DTLVERTEX)d3dExeBufDesc.lpData;
- float dtt = (float)(SKYDTime) / 512.f;
- float sky=0;
- float sy = VideoCY - sky;
- qyy = qy * sy;
- q = qx1 + qyy;
- float fxa = (px * sx1 + py * sy + pz) / q;
- float fya = (rx * sx1 + ry * sy + rz) / q;
- q = qx2 + qyy;
- float fxb = (px * sx2 + py * sy + pz) / q;
- float fyb = (rx * sx2 + ry * sy + rz) / q;
-
- lpVertex->sx = 0.f;
- lpVertex->sy = (float)sky;
- lpVertex->sz = 0.0001f;//-8.f / za;
- lpVertex->rhw = -1.f / za;
- /*if (FOGENABLE) {
- lpVertex->color = 0xFFFFFFFF;
- lpVertex->specular = alpha<<24; } else */{
- lpVertex->color = 0x00FFFFFF | alpha<<24;
- lpVertex->specular = 0xFF000000; }
- lpVertex->tu = (fxa + dtt) / 256.f;
- lpVertex->tv = (fya - dtt) / 256.f;
- lpVertex++;
- lpVertex->sx = (float)WinW;
- lpVertex->sy = (float)sky;
- lpVertex->sz = 0.0001f;//-8.f / za;
- lpVertex->rhw = -1.f / za;
- /*if (FOGENABLE) {
- lpVertex->color = 0xFFFFFFFF;
- lpVertex->specular = alpha<<24; } else */{
- lpVertex->color = 0x00FFFFFF | alpha<<24;
- lpVertex->specular = 0xFF000000; }
- lpVertex->tu = (fxb + dtt) / 256.f;
- lpVertex->tv = (fyb - dtt) / 256.f;
- lpVertex++;
- sky=scry/2.f;
- sy = VideoCY - sky;
- qyy = qy * sy;
- q = qx1 + qyy;
- fxa = (px * sx1 + py * sy + pz) / q;
- fya = (rx * sx1 + ry * sy + rz) / q;
- q = qx2 + qyy;
- fxb = (px * sx2 + py * sy + pz) / q;
- fyb = (rx * sx2 + ry * sy + rz) / q;
-
- lpVertex->sx = 0.f;
- lpVertex->sy = (float)sky;
- lpVertex->sz = 0.0001f;//-8.f / zb;
- lpVertex->rhw = -1.f / zb;
- /*if (FOGENABLE) {
- lpVertex->color = 0xFFFFFFFF;
- lpVertex->specular = alphb<<24; } else */{
- lpVertex->color = 0x00FFFFFF | alphb<<24;
- lpVertex->specular = 0xFF000000; }
- lpVertex->tu = (fxa + dtt) / 256.f;
- lpVertex->tv = (fya - dtt) / 256.f;
- lpVertex++;
- lpVertex->sx = (float)WinW;
- lpVertex->sy = (float)sky;
- lpVertex->sz = 0.0001f;//-8.f / zb;
- lpVertex->rhw = -1.f / zb;
- /*if (FOGENABLE) {
- lpVertex->color = 0xFFFFFFFF;
- lpVertex->specular = alphb<<24; } else */{
- lpVertex->color = 0x00FFFFFF | alphb<<24;
- lpVertex->specular = 0xFF000000; }
- lpVertex->tu = (fxb + dtt) / 256.f;
- lpVertex->tv = (fyb - dtt) / 256.f;
- lpVertex++;
- sky=(float)scry;
- sy = VideoCY - sky;
- qyy = qy * sy;
- q = qx1 + qyy;
- fxa = (px * sx1 + py * sy + pz) / q;
- fya = (rx * sx1 + ry * sy + rz) / q;
- q = qx2 + qyy;
- fxb = (px * sx2 + py * sy + pz) / q;
- fyb = (rx * sx2 + ry * sy + rz) / q;
-
- lpVertex->sx = 0.f;
- lpVertex->sy = (float)sky;
- lpVertex->sz = 0.0001f;//-8.f / zb;
- lpVertex->rhw = -1.f / zc;
- /*if (FOGENABLE) {
- lpVertex->color = 0xFFFFFFFF;
- lpVertex->specular = alphc<<24; } else */{
- lpVertex->color = 0x00FFFFFF | alphc<<24;
- lpVertex->specular = 0xFF000000; }
- lpVertex->tu = (fxa + dtt) / 256.f;
- lpVertex->tv = (fya - dtt) / 256.f;
- lpVertex++;
- lpVertex->sx = (float)WinW;
- lpVertex->sy = (float)sky;
- lpVertex->sz = 0.0001f;//-8.f / zb;
- lpVertex->rhw = -1.f / zc;
- /*if (FOGENABLE) {
- lpVertex->color = 0xFFFFFFFF;
- lpVertex->specular = alphc<<24; } else */{
- lpVertex->color = 0x00FFFFFF | alphc<<24;
- lpVertex->specular = 0xFF000000; }
- lpVertex->tu = (fxb + dtt) / 256.f;
- lpVertex->tv = (fyb - dtt) / 256.f;
- lpVertex++;
-
-
- lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + 400*3);
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 4;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = hTexture;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_FOGCOLOR;
- if (UNDERWATER) lpState->dwArg[0] = CurFogColor;
- else lpState->dwArg[0] = (SkyR<<16) + (SkyG<<8) + SkyB;
- lpState++;
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstruction->wCount = 1U;
- lpInstruction++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = 6;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
- lpInstruction->bOpcode = D3DOP_TRIANGLE;
- lpInstruction->bSize = sizeof(D3DTRIANGLE);
- lpInstruction->wCount = 4;
- lpInstruction++;
- lpTriangle = (LPD3DTRIANGLE)lpInstruction;
-
- lpTriangle->wV1 = 0;
- lpTriangle->wV2 = 1;
- lpTriangle->wV3 = 2;
- lpTriangle->wFlags = 0;
- lpTriangle++;
-
- lpTriangle->wV1 = 1;
- lpTriangle->wV2 = 2;
- lpTriangle->wV3 = 3;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- lpTriangle->wV1 = 2;
- lpTriangle->wV2 = 3;
- lpTriangle->wV3 = 4;
- lpTriangle->wFlags = 0;
- lpTriangle++;
-
- lpTriangle->wV1 = 3;
- lpTriangle->wV2 = 4;
- lpTriangle->wV3 = 5;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- lpInstruction = (LPD3DINSTRUCTION)lpTriangle;
- lpInstruction->bOpcode = D3DOP_EXIT;
- lpInstruction->bSize = 0UL;
- lpInstruction->wCount = 0U;
- lpd3dExecuteBufferG->Unlock( );
-
- hRes = lpd3dDevice->Execute(lpd3dExecuteBufferG, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
- LINEARFILTER = TRUE;
-
- nv = RotateVector(Sun3dPos);
- SunLight = 0;
- if (nv.z < -2024) RenderSun(nv.x, nv.y, nv.z);
- }
- void RenderFSRect(DWORD Color)
- {
- d3dStartBuffer();
- lpVertex->sx = 0.f;
- lpVertex->sy = 0.f;
- lpVertex->sz = 0.999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = Color;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpVertex->sx = (float)WinW;
- lpVertex->sy = 0.f;
- lpVertex->sz = 0.999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = Color;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpVertex->sx = 0.f;
- lpVertex->sy = (float)WinH;
- lpVertex->sz = 0.999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = Color;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpVertex->sx = (float)WinW;
- lpVertex->sy = (float)WinH;
- lpVertex->sz = (float)0.999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = Color;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + 1024*3);
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 1;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = NULL;
- lpState++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstruction->wCount = 1U;
- lpInstruction++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = 4;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
- lpInstruction->bOpcode = D3DOP_TRIANGLE;
- lpInstruction->bSize = sizeof(D3DTRIANGLE);
- lpInstruction->wCount = 2;
- lpInstruction++;
- lpTriangle = (LPD3DTRIANGLE)lpInstruction;
-
- lpTriangle->wV1 = 0;
- lpTriangle->wV2 = 1;
- lpTriangle->wV3 = 2;
- lpTriangle->wFlags = 0;
- lpTriangle++;
-
- lpTriangle->wV1 = 1;
- lpTriangle->wV2 = 2;
- lpTriangle->wV3 = 3;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- lpInstruction = (LPD3DINSTRUCTION)lpTriangle;
- lpInstruction->bOpcode = D3DOP_EXIT;
- lpInstruction->bSize = 0UL;
- lpInstruction->wCount = 0U;
- lpd3dExecuteBuffer->Unlock( );
-
- hRes = lpd3dDevice->Execute(lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
- }
- void RenderHealthBar()
- {
- if (MyHealth >= 100000) return;
- if (MyHealth == 000000) return;
-
- int L = WinW / 4;
- int x0 = WinW - (WinW / 20) - L;
- int y0 = WinH / 40;
- int G = min( (MyHealth * 240 / 100000), 160);
- int R = min( ( (100000 - MyHealth) * 240 / 100000), 160);
-
-
- int L0 = (L * MyHealth) / 100000;
- int H = WinH / 200;
- d3dStartBuffer();
- for (int y=0; y<4; y++) {
- lpVertex->sx = (float)x0-1;
- lpVertex->sy = (float)y0+y;
- lpVertex->sz = 0.9999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = 0xF0000010;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpVertex->sx = (float)x0+L0+1;
- lpVertex->sy = (float)y0+y;
- lpVertex->sz = 0.9999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = 0xF0000010;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- }
- for (y=1; y<3; y++) {
- lpVertex->sx = (float)x0;
- lpVertex->sy = (float)y0+y;
- lpVertex->sz = 0.99999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = 0xF0000000 + (G<<8) + (R<<16);
- lpVertex->specular = 0xFF000000;// + (G<<8) + (R<<16);
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpVertex->sx = (float)x0+L0;
- lpVertex->sy = (float)y0+y;
- lpVertex->sz = 0.99999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = 0xF0000000 + (G<<8) + (R<<16);
- lpVertex->specular = 0xFF000000;// + (G<<8) + (R<<16);
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- }
- lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + 1024*3);
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 1;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = NULL;
- lpState++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstruction->wCount = 1U;
- lpInstruction++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = 12;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
- lpInstruction->bOpcode = D3DOP_LINE;
- lpInstruction->bSize = sizeof(D3DLINE);
- lpInstruction->wCount = 6;
- lpInstruction++;
- lpLine = (LPD3DLINE)lpInstruction;
- for (y=0; y<6; y++) {
- lpLine->wV1 = y*2;
- lpLine->wV2 = y*2+1;
- lpLine++;
- }
-
- lpInstruction = (LPD3DINSTRUCTION)lpLine;
- lpInstruction->bOpcode = D3DOP_EXIT;
- lpInstruction->bSize = 0UL;
- lpInstruction->wCount = 0U;
- lpd3dExecuteBuffer->Unlock( );
-
- hRes = lpd3dDevice->Execute(lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
- }
- void Render_Cross(int sx, int sy)
- {
- float w = (float) WinW / 12.f;
- d3dStartBuffer();
- lpVertex->sx = (float)sx-w;
- lpVertex->sy = (float)sy;
- lpVertex->sz = 0.99999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = 0x80000010;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpVertex->sx = (float)sx+w;
- lpVertex->sy = (float)sy;
- lpVertex->sz = 0.99999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = 0x80000010;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpVertex->sx = (float)sx;
- lpVertex->sy = (float)sy-w;
- lpVertex->sz = 0.99999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = 0x80000010;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpVertex->sx = (float)sx;
- lpVertex->sy = (float)sy+w;
- lpVertex->sz = 0.99999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = 0x80000010;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + 1024*3);
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 1;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = NULL;
- lpState++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstruction->wCount = 1U;
- lpInstruction++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = 4;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
- lpInstruction->bOpcode = D3DOP_LINE;
- lpInstruction->bSize = sizeof(D3DLINE);
- lpInstruction->wCount = 2;
- lpInstruction++;
- lpLine = (LPD3DLINE)lpInstruction;
-
- lpLine->wV1 = 0;
- lpLine->wV2 = 1;
- lpLine++;
- lpLine->wV1 = 2;
- lpLine->wV2 = 3;
- lpLine++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpLine;
- lpInstruction->bOpcode = D3DOP_EXIT;
- lpInstruction->bSize = 0UL;
- lpInstruction->wCount = 0U;
- lpd3dExecuteBuffer->Unlock( );
-
- hRes = lpd3dDevice->Execute(lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
- }
- #endif
|