Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. bool Draw()
  2. {
  3.     Device->Clear(0, 0, D3DCLEAR_TARGET, WHITE, 1, 0);
  4.     Device->BeginScene();
  5.  
  6.     DrawEnvironment(Device,Environment);
  7.  
  8.     Device->EndScene();
  9.     if (FAILED(Device->Present(0,0,0,0)))
  10.     {
  11.         while(Device->TestCooperativeLevel() == D3DERR_DEVICELOST) Sleep(100);
  12.         D3DPRESENT_PARAMETERS D3dPresParams = GetDeviceParams(Window);
  13.         if (FAILED(Device->Reset(&D3dPresParams)))
  14.             return true;
  15.     }
  16.  
  17.     return false;
  18. }
  19.  
  20. LPDIRECT3DVERTEXBUFFER9 CreateEnvironment(LPDIRECT3DDEVICE9 D3dDevice)
  21. {
  22.     LPDIRECT3DVERTEXBUFFER9     Buffer      = 0;
  23.     ENV_VERTEX*                 Vertices    = 0;
  24.  
  25.     Vertices = new (std::nothrow) ENV_VERTEX[40];
  26.  
  27.     for (UINT i=0, ii=-10; i<10; i+=2, ii+=2)
  28.     {
  29.         Vertices[i].P = D3DXVECTOR3((float)ii,0,10);
  30.         Vertices[i+1].P = D3DXVECTOR3((float)ii,0,-10);
  31.     }
  32.  
  33.     for (UINT i=10, ii=10; i<20; i+=2, ii-=2)
  34.     {
  35.         Vertices[i].P = D3DXVECTOR3((float)ii,0,10);
  36.         Vertices[i+1].P = D3DXVECTOR3((float)ii,0,-10);
  37.     }
  38.  
  39.     for (UINT i=20, ii=-10; i<30; i+=2, ii+=2)
  40.     {
  41.         Vertices[i].P = D3DXVECTOR3(10,0,(float)ii);
  42.         Vertices[i+1].P = D3DXVECTOR3(-10,0,(float)ii);
  43.     }
  44.  
  45.     for (UINT i=30, ii=10; i<40; i+=2, ii-=2)
  46.     {
  47.         Vertices[i].P = D3DXVECTOR3(10,0,(float)ii);
  48.         Vertices[i+1].P = D3DXVECTOR3(-10,0,(float)ii);
  49.     }
  50.  
  51.     for (UINT i=0; i<40; ++i)
  52.         Vertices[i].C = GREY;
  53.  
  54.     if (FAILED(D3dDevice->CreateVertexBuffer(40*sizeof(ENV_VERTEX), 0, ENVFVF, D3DPOOL_MANAGED, &Buffer, 0)))
  55.         return 0;
  56.  
  57.     VOID* Address;
  58.     Buffer->Lock(0,0,&Address,0);
  59.     memcpy(Address,Vertices,40*sizeof(ENV_VERTEX));
  60.     Buffer->Unlock();
  61.  
  62.     SAFE_ARRAY_DELETE(Vertices);
  63.  
  64.     return Buffer;
  65. }
  66.  
  67. void DrawEnvironment(LPDIRECT3DDEVICE9 D3dDevice, LPDIRECT3DVERTEXBUFFER9 Buffer)
  68. {
  69.     D3dDevice->SetFVF(ENVFVF);
  70.     D3dDevice->SetStreamSource(0,Buffer,0,sizeof(ENV_VERTEX));
  71.     D3dDevice->DrawPrimitive(D3DPT_LINELIST,0,20);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement