THANX

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.


Answer this question

THANX

  • Stubey

    Thanks Ralf. I have one more question, and this thread shall end afterwards. I finished my program in C#. Thankfully, the graphics are apearing as they should. I've put my rendering loop in a timer so that I have a fixed framerate. Now my problem is after a few seconds when I check with Tesk manager the memory usage is increasing very fast. I'm using 2d sprites in D3D and I have a function to draw every layer. In all of these functions, I start my scene, start my sprite, draw my sprite, close the sprite, close the scene, and finally I present it. I'm not sure this could be a logical bug and I have no idea where to put the render loop except in a timer.

    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

    When you enable the depth buffer with d3dpp.EnableAutoDepthStencil = true you have to set d3dpp.AutoDepthStencilFormat to a valid and supported format too. Direct3D will never select a depth stencil format for you.

  • 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

    Thank you Ralf I really appreciate your the time you spend to answer my questions. I'm almost finished with my graphics engine and it works almost flawlessly, however, the screen is flashing to black and to the actual game display non-stop. I tried to change the interval for the clearing the device but it was no use.
    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

    Hi,
    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

    Thanx Ralf, I believe that I have to many present functions since i have function for each layer. Will try ur solution 2 see whether it worx or not.

    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

    Also check out the 6 tutorials that come in the SDK - they all create windows, devices and handle events properly

  • Kamran100

    Thanks Ralf, I finally decided to work with C# since I already have more experience working with C# than C++. Now I successfully managed to initialize direct3d in windowed mode and I managed to draw sprites. However, the program crashes when I try to open it in full screen. Any ideas

    Thanks


    Milad Zarpak

  • David Holcomb

    I beleive my main problem is with window creation, I already have experience working with OpenGL, SDL, and GDI but this time I wanted to give direct X a try.
    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 for the response. However, I tried all the samples and still my engine crashes. Please help me.

    Thanks

    Milad Zarpak

  • THANX