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

  1.  
  2. #include "main.h"
  3.  
  4.  
  5. //------------------------------------------------------------------
  6. // Name: OFFSCREEN()
  7. // Desc: konstruktor
  8. //------------------------------------------------------------------
  9. OFFSCREEN::OFFSCREEN()
  10. {
  11.  
  12.     RenderToSurface   = NULL ;
  13.     DynamicTexture    = NULL;
  14.     TextureSurface  = NULL;
  15.  
  16.     Width = 256;
  17.     Height = 256;
  18.  
  19. }
  20.  
  21. //------------------------------------------------------------------
  22. // Name: ~OFFSCREEN()
  23. // Desc: destruktor
  24. //------------------------------------------------------------------
  25. OFFSCREEN::~OFFSCREEN()
  26. {
  27.  
  28.     if( RenderToSurface != NULL )
  29.         RenderToSurface->Release();
  30.  
  31.     if( DynamicTexture != NULL )
  32.         DynamicTexture->Release();
  33.  
  34.     if( TextureSurface != NULL )
  35.         TextureSurface->Release();
  36.  
  37. }
  38.  
  39.  
  40. //------------------------------------------------------------------
  41. // Name: Initialize()
  42. // Desc: inicializacia textur a povrchov
  43. //------------------------------------------------------------------
  44. void OFFSCREEN::Initialize()
  45. {
  46.  
  47.     LogPrint("Inicializujem Texturu pre rendering");
  48.  
  49.     //
  50.     // Create our dynamic texture for use by the "render to" surface...
  51.     //
  52.     if (FAILED(D3DXCreateTexture( g_pd3dDevice, 
  53.                                   Width, 
  54.                                   Height, 
  55.                                     1, 
  56.                                     D3DUSAGE_RENDERTARGET, 
  57.                                   D3DFMT_A8R8G8B8, 
  58.                                   Engine.TextureCreatingFlag, 
  59.                                   &DynamicTexture )))
  60.     {
  61.         LogPrint("  Nepodarilo sa vytvorit dynamicku texturu");
  62.     }
  63.     else
  64.     {
  65.         LogPrint("  Dynamicka textura vytvorena");
  66.     }
  67.  
  68.     //
  69.     // Create an off-screen "render to" surface...
  70.     //
  71.     D3DSURFACE_DESC desc;
  72.     DynamicTexture->GetSurfaceLevel( 0, &TextureSurface );
  73.     TextureSurface->GetDesc( &desc );
  74.  
  75.     if (FAILED(D3DXCreateRenderToSurface( g_pd3dDevice, 
  76.                                           desc.Width, 
  77.                                           desc.Height, 
  78.                                           desc.Format, 
  79.                                           TRUE, 
  80.                                           D3DFMT_D16, 
  81.                                           &RenderToSurface )))
  82.     {
  83.         LogPrint("  Nepodarilo sa vytvorit povrch");
  84.     }
  85.     else
  86.     {
  87.         LogPrint("  Povrch vytvoreny");
  88.     }
  89.  
  90.     //
  91.     //Vytvorenie projekcnej matice
  92.     //
  93.     D3DXMatrixPerspectiveFovLH( &Projection, 45.0f, 
  94.                                 (float)Width / (float)Height, 
  95.                                 0.1f, 100.0f );
  96. }
  97.  
  98. //------------------------------------------------------------------
  99. // Name: BeginRender()
  100. // Desc: zaciatok render-> vycistenie bufferu
  101. //------------------------------------------------------------------
  102. void OFFSCREEN::BeginRender()
  103. {
  104.  
  105.     RenderToSurface->BeginScene( TextureSurface, NULL );
  106.  
  107.     g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 
  108.                          D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0);
  109.  
  110.     
  111.  
  112. }
  113.  
  114. //------------------------------------------------------------------
  115. // Name: EndRender()
  116. // Desc: koniec renderu -> prezentacia dßt
  117. //------------------------------------------------------------------
  118. void OFFSCREEN::EndRender()
  119. {
  120.     RenderToSurface->EndScene( 0 );
  121. }
  122.  
  123. //------------------------------------------------------------------
  124. // Name: GetTexture()
  125. // Desc: vrati texturu do ktorej sa renderovalo
  126. //------------------------------------------------------------------
  127. LPDIRECT3DTEXTURE9 OFFSCREEN::GetTexture()
  128. {
  129.     return DynamicTexture;
  130. }
  131.