c++ - vgasave 中的 D3D 设备

标签 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

最佳答案

您在 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。

关于c++ - vgasave 中的 D3D 设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4579148/

相关文章:

c++ - 如何在虚幻引擎中记录来自字符串变量的消息?

c++ - 求勒让德多项式的递归程序

c++ - Vector w/Structure w/char buffer[] 的静态初始化

c++ - 如何从 Qt4 传递 OpenGL 上下文?

c++ - 为什么在读取非 HTTP 服务器的套接字时需要异步 IO

opengl - 3D图形: Normal mapping vs Bump mapping?

directx - Direct2D Direct3d11 互操作 - 设备会丢失吗?

c++ - directx11 点光源问题。从原点平移的对象没有正确点亮

C++ 多定义符号

opengl - 除了抗锯齿之外,我可以使用多重采样缓冲区吗?