   Would this work?
  I'm trying to convert some direct3d code into a class and I was wondering if I did it right. Here's the code: #include<d3d8.h>#include<d3dx8.h>#pragma comment(lib,"d3d8.lib")#pragma comment(lib,"d3dx8.lib")class CD3DWindow{private:LPDIRECT3D8 *pd3d;LPDIRECT3DDEVICE8 pd3dd;D3DDISPLAYMODE d3ddm;D3DPRESENT_PARAMETERS d3dpp;public:CD3DWindow(HWND hWnd){pd3d = Direct3DCreate8(D3D_SDK_VERSION);pd3d ->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm);ZeroMemory(&d3dpp,sizeof(d3dpp));d3dpp.Windowed = TRUE;d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;d3dpp.BackBufferFormat = d3ddm.Format;d3dpp.EnableAutoDepthStencil = TRUE;d3dpp.AutoDepthStencilFormat = D3DFMT_D16;pd3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dd);pd3dd->SetRenderState(D3DRS_LIGHTING, FALSE);}void Render(){pd3dd->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,    D3DCOLOR_XRGB(0,255,0), 1.0f, 0); // What ever this does it is importantpd3dd->BeginScene(){g_pD3DDevice->EndScene();}pd3dd->Present(NULL, NULL, NULL, NULL);}void CleanUp(){if(pd3dd != NULL){pd3dd->Release();pd3dd = NULL:}if(pd3d != NULL){pd3d->Release();pd3d = NULL;}}};Thanks for all your help,Cory   Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|[edited by - ssjcory on February 16, 2004 11:22:34 AM]
  You haven''t posted enough code to determine if it''s "right"...How is a CD3DWindow constructed, what is done with this class, how is Cleanup() called?  how is it deleted?If you are initializing things in the constructor, I would recommend that you call Cleanup() in your destructor.  Also, do you want to expose Cleanup() to the outside world or make it a private/protected member?Does the following code compile?pd3dd->BeginScene(){   g_pD3DDevice->EndScene();}Regards,Jeff ;  Also, what happens if CreateDevice() fails?  You don''t check this or throw an exception if this happens.  That is why doing all the construction in the constructor can be problematic.Sometimes it''s useful to have a public Init() method that will do all the initialization and return a HRESULT error code if things fail, but otherwise return S_OK...Regards,Jeff 