home *** CD-ROM | disk | FTP | other *** search
/ PC World 2006 July & August / PCWorld_2006-07-08_cd.bin / temacd / planearcade / planearcade.exe / Tank3.bmp / engine.cpp < prev    next >
C/C++ Source or Header  |  2004-11-24  |  18KB  |  622 lines

  1. #include "main.h"
  2.  
  3. //---------------------------------------------------------------------
  4. //Globalne PremennΘ
  5. //---------------------------------------------------------------------
  6.  
  7. //DIRETCX
  8. LPDIRECT3D9             g_pD3D       = NULL; 
  9. LPDIRECT3DDEVICE9       g_pd3dDevice = NULL;
  10.  
  11. //WINDOWS
  12. HWND      hWnd = NULL;
  13. HINSTANCE hIns = NULL;
  14.  
  15. //MATICA
  16. D3DXMATRIXA16 matProj;   //projekcia
  17.  
  18. //ENGINE
  19. ENGINE Engine;
  20.  
  21. /*
  22. //--------------------------------------------------------------------
  23. // Name: Initialze()
  24. // Desc: Pred Inicializaciou musia byt zadane Height, Width a Windowed
  25. //--------------------------------------------------------------------
  26. */
  27. void ENGINE::Initialize()
  28. {
  29.  
  30.     //log start
  31.     char cBuf[80];
  32.     LogPrint(">>>Inicializijem ENGINE");
  33.     LogPrint("Nastavenia:");
  34.  
  35.     sprintf(cBuf,"   Sirka: %d  Vyska: %d",Width,Height);
  36.     LogPrint(cBuf);
  37.  
  38.     sprintf(cBuf,"   Windowed: %d ",Windowed);
  39.     LogPrint(cBuf);
  40.  
  41.     sprintf(cBuf,"   Max: %.2f  Min: %.2f",Max,Min);
  42.     LogPrint(cBuf);
  43.  
  44.     sprintf(cBuf,"   BackColor: %f %f %f",BackColor.R,BackColor.G,BackColor.B);
  45.     LogPrint(cBuf);
  46.  
  47.     sprintf(cBuf,"   Format Obrazovky: %d ",Format);
  48.     LogPrint(cBuf);
  49.  
  50.     sprintf(cBuf,"   Format Textur: %d ",TextureFormat);
  51.     LogPrint(cBuf);
  52.  
  53.     sprintf(cBuf,"   Flag Textur: %d ",TextureCreatingFlag);
  54.     LogPrint(cBuf);
  55.  
  56.     sprintf(cBuf,"   Stencil Shadows: %d ",StencilShadows);
  57.     LogPrint(cBuf);
  58.     
  59.  
  60.     /////////////////////
  61.     //Vytvorenie g_pD3D//
  62.     /////////////////////
  63.     if (FAILED(g_pD3D = Direct3DCreate9( D3D_SDK_VERSION )))
  64.     {
  65.         LogPrint("Nemozno vytvorit g_pD3D");
  66.         MessageBox(hWnd,"Chyba poΦas vytvßrania Direct3D9",
  67.                         "ERROR",MB_OK|MB_ICONERROR);
  68.     }
  69.     else
  70.     {
  71.         LogPrint("g_pD3D vytvorene");
  72.     }
  73.    
  74.  
  75.     //zisti mod obrazovky
  76.     D3DDISPLAYMODE d3ddm;
  77.     g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);
  78.  
  79.     ////////////////////////
  80.      //nastavanie Viewportu//
  81.     ////////////////////////
  82.     Viewport.Height = Height;
  83.     Viewport.Width = Width;
  84.     Viewport.X = 0;
  85.     Viewport.Y = 0;
  86.     Viewport.MaxZ = Max;
  87.     Viewport.MinZ = Min;
  88.  
  89.     ////////////////////
  90.     //paremetre obrazu//
  91.     ////////////////////
  92.     D3DPRESENT_PARAMETERS d3dpp; 
  93.  
  94.     ZeroMemory( &d3dpp, sizeof(d3dpp) );
  95.  
  96.     d3dpp.Windowed = Windowed;
  97.     d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
  98.  
  99.     d3dpp.BackBufferWidth   = Width;
  100.     d3dpp.BackBufferHeight  = Height ;
  101.     
  102.     // !! nastavi 60 hz pre moj pitomi monitor !!
  103.     //if (Resolution == 2) d3dpp.FullScreen_RefreshRateInHz = 60;
  104.  
  105.     if (Windowed == true)
  106.         d3dpp.BackBufferFormat = d3ddm.Format ;
  107.     else
  108.         d3dpp.BackBufferFormat  = Format;
  109.  
  110.     d3dpp.EnableAutoDepthStencil = TRUE;
  111.     d3dpp.Flags                  = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
  112.     d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;
  113.     d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
  114.  
  115.     ////////////////////////////////
  116.     //Zisti podporu Stencil Shadow//
  117.     ////////////////////////////////
  118.     if (StencilShadows == true)
  119.     {
  120.         d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
  121.         d3dpp.BackBufferFormat  = D3DFMT_X8R8G8B8;
  122.  
  123.         if(FAILED(g_pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
  124.             d3dpp.BackBufferFormat, D3DUSAGE_DEPTHSTENCIL, 
  125.             D3DRTYPE_SURFACE, D3DFMT_D24S8)))
  126.         {
  127.             
  128.             StencilShadows = false;
  129.             LogPrint("Grafickß karta nepodporuje Stencil Buffer");
  130.             MessageBox(hWnd,"VaÜa grafickß karta nepodporuje stencil tiene",
  131.                             "ERROR",MB_OK|MB_ICONWARNING);
  132.         }
  133.         else
  134.         {
  135.             if(FAILED(g_pD3D->CheckDepthStencilMatch(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
  136.                 d3dpp.BackBufferFormat, d3dpp.BackBufferFormat, D3DFMT_D24S8)))
  137.             {
  138.                 StencilShadows = false;
  139.                 LogPrint("Depht Stencil nieje kompatibliny s modom obrazovky");
  140.                 MessageBox(hWnd,"Depht Stencil nieje kompatiblin² s m≤dom obrazovky",
  141.                                 "ERROR",MB_OK|MB_ICONWARNING);
  142.             }
  143.         }
  144.  
  145.         //preni mod ak je stencil vypnuty
  146.         if (StencilShadows == false)
  147.         {
  148.             d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
  149.             d3dpp.BackBufferFormat  = D3DFMT_R5G6B5;
  150.         }
  151.  
  152.     }
  153.  
  154.     //////////////////////////
  155.     //inicializacia Direct3D//
  156.     //////////////////////////
  157.  
  158.     int Mode=1;
  159.     while(1==1)
  160.     {
  161.  
  162.         // Mode 1
  163.         if (Mode == 1)
  164.         {
  165.             if (FAILED(g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
  166.                                              D3DCREATE_HARDWARE_VERTEXPROCESSING,
  167.                                              &d3dpp, &g_pd3dDevice ))) 
  168.                 Mode = 2;
  169.             else
  170.                 Mode = 0;
  171.  
  172.             continue;
  173.             
  174.         }
  175.  
  176.         // Mode 2
  177.         if (Mode == 2)
  178.         {
  179.             if (FAILED(g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
  180.                                              D3DCREATE_SOFTWARE_VERTEXPROCESSING,
  181.                                              &d3dpp, &g_pd3dDevice ))) 
  182.             {
  183.                 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
  184.                 d3dpp.BackBufferFormat  = D3DFMT_R5G6B5;
  185.                 StencilShadows = false;
  186.                 Mode = 3;
  187.             }
  188.             else
  189.                 Mode = 0;
  190.  
  191.             continue;
  192.             
  193.         }
  194.  
  195.         // Mode 3
  196.         if (Mode == 3)
  197.         {
  198.             if (FAILED(g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
  199.                                              D3DCREATE_SOFTWARE_VERTEXPROCESSING,
  200.                                              &d3dpp, &g_pd3dDevice ))) 
  201.             {
  202.                 Mode = -1;
  203.             }
  204.             else
  205.                 Mode = 0;
  206.  
  207.             continue;
  208.             
  209.         }
  210.         
  211.         //ERROR
  212.         if (Mode == -1)
  213.         {
  214.             LogPrint("chyba pri inicializacii g_pd3dDevice ") ;
  215.             MessageBox(hWnd,"VaÜa grafickß karta nieje kompatibilnß s Direct3D9",
  216.                             "ERROR",MB_OK|MB_ICONERROR);
  217.             break;
  218.         }
  219.     
  220.         //OK
  221.         if (Mode == 0)
  222.         {
  223.             LogPrint("inicializacia g_pd3dDevice  uspesna") ;
  224.             break;
  225.         }
  226.     }
  227.  
  228.  
  229.     ///////////
  230.     //D3DCAPS//
  231.     ///////////
  232.     D3DCAPS9 Caps;
  233.     g_pd3dDevice->GetDeviceCaps(&Caps);
  234.  
  235.     //stencil
  236.     if (StencilShadows == true)
  237.     {
  238.         if (!(Caps.StencilCaps & D3DSTENCILCAPS_DECR) ||
  239.             !(Caps.StencilCaps & D3DSTENCILCAPS_INCR) ||
  240.             !(Caps.StencilCaps & D3DSTENCILCAPS_KEEP))
  241.         {
  242.             LogPrint("D3D Device nemoze pouzit Stencil Buffer");
  243.             StencilShadows = false;
  244.         }
  245.     }
  246.  
  247.     //////////////////////
  248.     //OSTATNE NASTAVENIA//
  249.     //////////////////////
  250.  
  251.     //normalizuj normaly
  252.     g_pd3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS,TRUE);
  253.  
  254.     //deepht bias slope scale
  255.     g_pd3dDevice->SetRenderState( D3DRS_SLOPESCALEDEPTHBIAS, FtoDW(-0.3f) );
  256.     g_pd3dDevice->SetRenderState( D3DRS_DEPTHBIAS, FtoDW(0.0f) );
  257.  
  258.     //ambient
  259.     g_pd3dDevice->SetRenderState( D3DRS_AMBIENT,0xff555555);
  260.   
  261. }
  262.  
  263. /*
  264. //--------------------------------------------------------------------
  265. // Name: CleanUp()
  266. // Desc: Vycistenie pamati
  267. //--------------------------------------------------------------------
  268. */
  269. void ENGINE::CleanUp()
  270. {
  271.     if( g_pd3dDevice != NULL ) 
  272.         g_pd3dDevice->Release();
  273.  
  274.     if( g_pD3D != NULL )       
  275.         g_pD3D->Release();
  276. }
  277.  
  278.  
  279. /*
  280. //--------------------------------------------------------------------
  281. // Name: SetBlendNone()
  282. // Desc: Ziadna priesvitnost - vypne priesvitnos¥
  283. //--------------------------------------------------------------------
  284. */
  285. void ENGINE::SetBlendNone()
  286. {
  287.     g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,false);
  288.     g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ZERO );  
  289.     g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ZERO);
  290. }
  291.  
  292. /*
  293. //--------------------------------------------------------------------
  294. // Name: SetBlendOne()
  295. // Desc: Jednoducha priesvitnost
  296. //--------------------------------------------------------------------
  297. */
  298. void ENGINE::SetBlendOne()
  299. {
  300.     g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
  301.     g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE );  
  302.     g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);
  303. }
  304.  
  305. /*
  306. //--------------------------------------------------------------------
  307. // Name: SetBlendTrans()
  308. // Desc: Jedna farba bude transparentna, zalezi na texture aka
  309. //--------------------------------------------------------------------
  310. */
  311. void ENGINE::SetBlendTrans()
  312. {
  313.     g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
  314.     g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA );  
  315.     g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
  316.  
  317. }
  318.  
  319. /*
  320. //--------------------------------------------------------------------
  321. // Name: SetBlendCustom()
  322. // Desc: Umo₧nuje si nastavi¥ vlastnu transparentnos¥ podla D3D
  323. //--------------------------------------------------------------------
  324. D3D TYPY ktore mozno pouzit
  325.     D3DBLEND_ZERO               = 1,
  326.     D3DBLEND_ONE                = 2,
  327.     D3DBLEND_SRCCOLOR           = 3,
  328.     D3DBLEND_INVSRCCOLOR        = 4,
  329.     D3DBLEND_SRCALPHA           = 5,
  330.     D3DBLEND_INVSRCALPHA        = 6,
  331.     D3DBLEND_DESTALPHA          = 7,
  332.     D3DBLEND_INVDESTALPHA       = 8,
  333.     D3DBLEND_DESTCOLOR          = 9,
  334.     D3DBLEND_INVDESTCOLOR       = 10,
  335.     D3DBLEND_SRCALPHASAT        = 11,
  336.     D3DBLEND_BOTHSRCALPHA       = 12,
  337.     D3DBLEND_BOTHINVSRCALPHA    = 13,
  338. */
  339.  
  340. void ENGINE::SetBlendCustom(_D3DBLEND Scr,_D3DBLEND Dest)
  341. {
  342.     g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
  343.     g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND,Scr );  
  344.     g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,Dest);
  345. }
  346.  
  347. /*
  348. //--------------------------------------------------------------------
  349. // Name: SetCullMode()
  350. // Desc: Nastavi orezavanie (prednΘ,zadne, ziadne)
  351. //--------------------------------------------------------------------
  352.     D3DCULL_NONE                = 1,
  353.     D3DCULL_CW                  = 2,
  354.     D3DCULL_CCW                 = 3,
  355. */
  356. void ENGINE::SetCullMode(_D3DCULL Cull)
  357. {
  358.     g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, Cull );
  359. }
  360.  
  361. /*
  362. //--------------------------------------------------------------------
  363. // Name: SetFillMode()
  364. // Desc: Nastavi mod naplnovania
  365. //--------------------------------------------------------------------
  366.     D3DFILL_POINT               = 1,
  367.     D3DFILL_WIREFRAME           = 2,
  368.     D3DFILL_SOLID               = 3,
  369. */
  370. void ENGINE::SetFillMode(_D3DFILLMODE Fill)
  371. {
  372.     g_pd3dDevice->SetRenderState(D3DRS_FILLMODE ,Fill);
  373. }
  374.  
  375. //--------------------------------------------------------------------
  376. // Name: SetFilter()
  377. // Desc: Nastavi filtrovanie textur
  378. //--------------------------------------------------------------------
  379. /*  D3DTEXF_NONE            = 0,    // filtering disabled (valid for mip filter only)
  380.     D3DTEXF_POINT           = 1,    // nearest
  381.     D3DTEXF_LINEAR          = 2,    // linear interpolation
  382.     D3DTEXF_ANISOTROPIC     = 3,    // anisotropic
  383.     D3DTEXF_PYRAMIDALQUAD   = 6,    // 4-sample tent
  384.     D3DTEXF_GAUSSIANQUAD    = 7,    // 4-sample gaussian
  385. */
  386.  
  387. void ENGINE::SetFilter(int Stage, _D3DTEXTUREFILTERTYPE Filter)
  388. {
  389.     g_pd3dDevice->SetSamplerState(Stage, D3DSAMP_MINFILTER, Filter);
  390.     g_pd3dDevice->SetSamplerState(Stage, D3DSAMP_MAGFILTER, Filter);
  391. }
  392.  
  393. /*
  394. //--------------------------------------------------------------------
  395. // Name: SetShadeMode()
  396. // Desc: Nastavi shading polygonov
  397. //--------------------------------------------------------------------
  398.     D3DSHADE_FLAT               = 1,
  399.     D3DSHADE_GOURAUD            = 2,
  400.     D3DSHADE_PHONG              = 3,
  401. */
  402. void ENGINE::SetShadeMode(_D3DSHADEMODE Shade)
  403. {
  404.     g_pd3dDevice->SetRenderState(D3DRS_SHADEMODE ,Shade);
  405. }
  406.  
  407. /*
  408. //--------------------------------------------------------------------
  409. // Name: SetZBuffer()
  410. // Desc: zapne - vypne ZBuffer
  411. //--------------------------------------------------------------------
  412. */
  413. void ENGINE::SetZBuffer(bool Activate)
  414. {
  415.     g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, Activate);
  416. }
  417.  
  418. /*
  419. //--------------------------------------------------------------------
  420. // Name: SetMipMapping()
  421. // Desc: zapne - vypne MipMapping, Levels - kolko mipmaplevelov vytvara¥
  422. //--------------------------------------------------------------------
  423. */
  424. void ENGINE::SetMipMapping(int Stage,bool Activate) 
  425. {
  426.     if (Activate == true) 
  427.     {
  428.         g_pd3dDevice->SetSamplerState(Stage, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
  429.     }
  430.     else
  431.     {
  432.         g_pd3dDevice->SetSamplerState(Stage, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
  433.     }
  434.  
  435.         
  436. }
  437.  
  438. /*
  439. //--------------------------------------------------------------------
  440. // Name: SetProjection
  441. // Desc: nastavi projekcnu maticu
  442. //--------------------------------------------------------------------
  443. */
  444. void ENGINE::SetProjection()
  445. {
  446.     D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/3.6f, 1.0f,Min, Max);
  447.     g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
  448. }
  449.  
  450. /*
  451. //--------------------------------------------------------------------
  452. // Name: SetLighting()
  453. // Desc: Vypne zapne osvetlenie
  454. //--------------------------------------------------------------------
  455. */
  456. void ENGINE::SetLighting(bool Activate)
  457. {
  458.     g_pd3dDevice->SetRenderState( D3DRS_LIGHTING,Activate);
  459. }
  460.  
  461. /*
  462. //--------------------------------------------------------------------
  463. // Name: SetFog()nastavi hmlu
  464. // Desc: Vypne zapne osvetlenie
  465. //--------------------------------------------------------------------
  466. */
  467. void ENGINE::SetupFog(COLOR Color, float Destiny) 
  468. {    
  469.     g_pd3dDevice->SetRenderState(D3DRS_FOGCOLOR, D3DXCOLOR(Color.R,Color.G,Color.B,Color.A ));
  470.     g_pd3dDevice->SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_EXP2);
  471.     g_pd3dDevice->SetRenderState(D3DRS_FOGDENSITY, FtoDW(Destiny));
  472.        
  473. }
  474.  
  475. /*
  476. //--------------------------------------------------------------------
  477. // Name: SetFogActive(()
  478. // Desc: Vypne zapne hmli
  479. //--------------------------------------------------------------------
  480. */
  481. void ENGINE::SetFog(bool Activate)
  482. {
  483.     g_pd3dDevice->SetRenderState(D3DRS_FOGENABLE, Activate);
  484. }
  485.  
  486. /*
  487. //--------------------------------------------------------------------
  488. // Name: SetSpecular()
  489. // Desc: Vypne zapne specular svetla
  490. //--------------------------------------------------------------------
  491. */
  492. void ENGINE::SetSpecular(bool Activate)
  493. {
  494.     g_pd3dDevice->SetRenderState( D3DRS_SPECULARENABLE,Activate);
  495. }
  496.  
  497. /*
  498. //--------------------------------------------------------------------
  499. // Name: SetAlphaTest()
  500. // Desc: Vypne alpha test, umo₧ni kresli¥ transparentne objekty nakoniec
  501. //--------------------------------------------------------------------
  502. */
  503. void ENGINE::SetAlphaTest(bool Activate)
  504. {
  505.     g_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE,Activate);
  506.     g_pd3dDevice->SetRenderState(D3DRS_ALPHAREF, Activate);
  507.     g_pd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);
  508. }
  509.  
  510.  
  511. /*
  512. //--------------------------------------------------------------------
  513. // Name: SetZwrite()
  514. // Desc: Vypne alebo zapne zapisovanie do hlbkoveho bufferu
  515. //--------------------------------------------------------------------
  516. */
  517. void ENGINE::SetZwrite(bool Activate)
  518. {
  519.     g_pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE,Activate);
  520. }
  521.  
  522. /*
  523. //--------------------------------------------------------------------
  524. // Name: SetStencil()
  525. // Desc: Vypne alebo zapne stencil
  526. //--------------------------------------------------------------------
  527. */
  528. void ENGINE::SetStencil(bool Activate)
  529. {
  530.     g_pd3dDevice->SetRenderState( D3DRS_STENCILENABLE,Activate );
  531. }
  532.  
  533.  
  534. /*
  535. //--------------------------------------------------------------------
  536. // Name: SetSpecular()
  537. // Desc: zresetuje nastavenia svetiel a priesvitnosti
  538. //--------------------------------------------------------------------
  539. */
  540.  
  541. void ENGINE::ResetToDefault()
  542. {
  543.     
  544.     Engine.SetLighting(false);
  545.     Engine.SetSpecular(false);
  546.     Engine.SetZBuffer(true);
  547.     Engine.SetZwrite(true);
  548.     Engine.SetStencil(false);
  549.     Engine.SetAlphaTest(false);
  550.  
  551.     Engine.SetCullMode(D3DCULL_NONE);
  552.     Engine.SetShadeMode(D3DSHADE_GOURAUD);
  553.  
  554.      g_pd3dDevice->SetTextureStageState(0 ,D3DTSS_ALPHAOP, D3DTOP_MODULATE);
  555.     g_pd3dDevice->SetTextureStageState(0 ,D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
  556.     g_pd3dDevice->SetTextureStageState(0 ,D3DTSS_ALPHAARG2, D3DTA_CURRENT);
  557.  
  558.     g_pd3dDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX,0);
  559.     g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
  560.     g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
  561.     g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
  562.  
  563.     g_pd3dDevice->SetTextureStageState(1 ,D3DTSS_ALPHAOP, D3DTOP_MODULATE);
  564.     g_pd3dDevice->SetTextureStageState(1 ,D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
  565.     g_pd3dDevice->SetTextureStageState(1 ,D3DTSS_ALPHAARG2, D3DTA_CURRENT);
  566.  
  567.     g_pd3dDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX,1);
  568.     g_pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
  569.     g_pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
  570.     g_pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
  571.  
  572. }
  573.  
  574. /*
  575. //--------------------------------------------------------------------
  576. // Name: BeginScene()
  577. // Desc: zacni vykreslovanie
  578. //--------------------------------------------------------------------
  579. */
  580. void ENGINE::BeginScene()
  581. {
  582.  
  583.     //zacniFPS
  584.     TimeStart();
  585.  
  586.     //vytvori flagy pre vycistenie
  587.     DWORD flags = 0;
  588.     flags |= D3DCLEAR_TARGET;
  589.     flags |= D3DCLEAR_ZBUFFER;
  590.  
  591.     if (StencilShadows)
  592.         flags |= D3DCLEAR_STENCIL;
  593.  
  594.     //Vicistenie backbufferu
  595.     g_pd3dDevice->Clear( 0, NULL, flags, D3DXCOLOR(Engine.BackColor.R,Engine.BackColor.G,Engine.BackColor.B,1.0f), 1.0f, 0 );
  596.     
  597.     //zacni scenu
  598.     g_pd3dDevice->BeginScene();
  599.  
  600. }
  601.  
  602. /*
  603. //--------------------------------------------------------------------
  604. // Name: EndScene()
  605. // Desc: prezentuj scenu
  606. //--------------------------------------------------------------------
  607. */
  608. void ENGINE::EndScene()
  609. {
  610.  
  611.     //ukonci scenu    
  612.     g_pd3dDevice->EndScene();
  613.  
  614.     //Zbraz na Obrazovku
  615.     g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
  616.  
  617.     //skonciFPS
  618.     TimeEnd();
  619.  
  620. }
  621.  
  622.