vgasave中的D3D设备

时间:2011-01-02 15:53:25

标签: c++ directx

当pc使用vgasave模式时,是否可以创建device / directx应用程序? 这是我的初始化函数:

 d3d = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface

    D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information

    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use
    d3dpp.Windowed = TRUE;    // program windowed, not fullscreen
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames
    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D


    // create a device class using this information and the info from the d3dpp stuct
    d3d->CreateDevice(D3DADAPTER_DEFAULT,
                      D3DDEVTYPE_HAL,
                      hWnd,
                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                      &d3dpp,
                      &d3ddev);

然而,当我稍后打电话时

d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);

程序崩溃,报告未处理的违规行为。或者也许不是关于vga,只是我做错了什么?


CreateDevice返回D3DERR_NOTAVAILABLE

1 个答案:

答案 0 :(得分:2)

你在D3DPRESENT_PARAMETERS中填写的参数太少了。你确实对后端缓冲区和那种东西设置了不好的设置。如果CreateDevice返回D3DERR_NOTAVAILABLE,则d3ddev指针为NULL,当您尝试清除后台缓冲区时会导致访问冲突 - 因为没有设备。

D3DDeviceParameters.Windowed = true;
D3DDeviceParameters.BackBufferHeight = 0;
D3DDeviceParameters.BackBufferWidth = 0;
D3DDeviceParameters.BackBufferCount = 1;
D3DDeviceParameters.BackBufferFormat = D3DFMT_X8R8G8B8;
D3DDeviceParameters.MultiSampleQuality = 0;
D3DDeviceParameters.MultiSampleType = D3DMULTISAMPLE_NONE;
D3DDeviceParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
D3DDeviceParameters.hDeviceWindow = OS->GetHWND();
D3DDeviceParameters.EnableAutoDepthStencil = true;
D3DDeviceParameters.AutoDepthStencilFormat = D3DFMT_D24S8;
D3DDeviceParameters.Flags = 0;
D3DDeviceParameters.FullScreen_RefreshRateInHz = 0;
D3DDeviceParameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Vsync.

这是我的D3DPRESENT_PARAMETERS。