Hi everyone, i'm making my arcade 2d engine using d3d9 sprites, particles ditto. I have a problem with creating the device. First of all i tried all the ways i knew to make the hWnd handler which i guess is the problem. Any ways here's my code for creating the device.
/* dx9.pD3D is basically our d3d object d3dpp is presentation parameters and dx9.pd3dDevice is our d3ddevice object.*/
if( FAILED( dx9.pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd ,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp, &dx9.pd3dDevice ) ) )
state = false;
p.s. please give me a working source code for making a simple hWnd handler as well as the proper code for making the device.

THANX
Stubey
I'm looking forward to your answers
Milad Zarpak
awesj
You should enable the Direct3d debug runtime and activate “unmanaged debugging” in your project. This will give you some more detailed error messages. If you use Visual Studio 2005 you will noticed a loader lock error. This blog entry contains a solution: http://www.thezbuffer.com/articles/304.aspx
Common reasons why the creation of a full screen device fails are:
- Wrong back buffer size
- Wrong back buffer format
- Wrong refresh rate interval
But the debug runtime will tell you.
Pravin Indurkar
Sachin Sinha MSFT
You can limit your frame rate to the display refresh rate with the PresentationInterval property in the presentation parameters. Set it to One and the present method will wait anytime you are too fast.
You can find some good information’s about managed DX render loops at Tom Millers blog: https://blogs.msdn.com/tmiller/archive/2005/05/05/415008.aspx
They are multiple possible reasons for your fast growing memory footprint. You should lock for “new” instructions that create large arrays or objects in your periodical called render functions. Even if the managed world is more forgivable then the unmanaged when it comes to memory allocations in your render functions you should try to avoid this.
edmond koni
Please help me out
Tanek
This behavior sounds like you call present too many times. You should check your code if there are more than one place were present is called. If this is not the case you should check if there is a code path that clear the back buffer and present it but does not render anything.
Marfig
you should turn on DirectX debug version and set the debug level to 4 or 5 (max), then when you run the program, DirectX will present messages in the VS's output debug window. (To activate this go to Control Panel->DirectX->Direct3D or in VS 2005 Tools->Options->Debugging->DirectX.)
Check this tutorial for the window creation: http://www.drunkenhyena.com/cgi-bin/view_cpp_article.pl chapter=2;article=7
and this one for d3d creation:
http://www.drunkenhyena.com/cgi-bin/view_cpp_article.pl chapter=2;article=10
carsc
Milad Zarpak
David Mc Quillan
You are going to have to give us more details on the error you are getting. If you copied the device setup code from the tutorials (which I assume work just fine on your computer) then its likely that the error is elsewhere.
Vladimir Savinov
Kamran100
Thanks
Milad Zarpak
David Holcomb
When I build and compile the program I get no errors and no warnings. I tried to debug the program and appreantly when I try to create the device something goes wrong and program crashes. However, I was able to create the D3D object as well as getting the adapter information and setting the presenting parameters. here's my full source for initialization:
void initEngine(HWND hWnd)
{
state = 0;
// Create the D3D object, which is needed to create the D3DDevice.
if( FAILED( pD3D=Direct3DCreate9( D3D_SDK_VERSION ) ))
{
ofstream outFile;
outFile.open("H:/rep.txt",ios::app);
outFile << "Failed" << endl;
outFile.close;
}
else
{
ofstream outFile;
outFile.open("H:/rep.txt",ios::app);
outFile << "Passed" << endl;
outFile.close;
}
// Get the current desktop display mode
D3DDISPLAYMODE d3ddm;
if( FAILED( pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT,&d3ddm )))
{
ofstream outFile;
outFile.open("H:/rep.txt",ios::app);
outFile << "Failed" << endl;
outFile.close;
}
else
{
ofstream outFile;
outFile.open("H:/rep.txt",ios::app);
outFile << "Passed" << endl;
outFile.close;
}
// Parameters for the D3DDevice.
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.BackBufferCount = 1;
d3dpp.Windowed = false;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = GetActiveWindow();
d3dpp.BackBufferWidth = 640;
d3dpp.BackBufferHeight = 480;
d3dpp.BackBufferFormat = D3DFMT_R5G6B5;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
// Create the Direct3D device, using the default adapter
if( FAILED( pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd ,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp, &pd3dDevice ) ) )
{
ofstream outFile;
outFile.open("H:/rep.txt",ios::app);
outFile << "Failed" << endl;
outFile.close;
}
else
{
ofstream outFile;
outFile.open("H:/rep.txt",ios::app);
outFile << "Passed" << endl;
outFile.close;
}
// Device state would normally be set here
}
sonali1754
Thanks
Milad Zarpak