使用 AMD 四缓冲区 SDK 查看 3D 图像 - DirectX 9

发布于 2024-12-19 18:44:07 字数 3289 浏览 3 评论 0原文

我目前正在开发一个项目,我需要使用使用 Bumblebee2 3D 相机拍摄的图像来显示 3D 图像。我正在使用 MSI AE2420 计算机,它具有支持 3D 的 AMD HD 5730。我还有快门眼镜以立体模式查看图像。

我正在使用 DirectX 9 库( d3dx9.h )。IDE 是 VS 2008 Express Edition。

我有示例图像(左和右),我用以下线条将它们连续导入到程序中;

pDevice->CreateOffscreenPlainSurface(IMAGE_WIDTH,IMAGE_HEIGHT,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&leftImageBuffer,NULL);
pDevice->CreateOffscreenPlainSurface(IMAGE_WIDTH,IMAGE_HEIGHT,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&rightImageBuffer,NULL);

D3DXLoadSurfaceFromFile(leftImageBuffer,NULL,NULL,"left0000.bmp",NULL,D3DX_FILTER_NONE,0,NULL)
D3DXLoadSurfaceFromFile(rightImageBuffer,NULL,NULL,"right0000.bmp",NULL,D3DX_FILTER_NONE,0,NULL)

经过一番研究,我发现Direct3D9不允许主动Quad Buffer立体声。所以我不能使用四个缓冲区(左前,左后,右前,右后)。这就是AMD的Quad Buffer SDK涉及的地方。他们表明DirectX 9也不允许有源立体声,我需要使用SDK的功能。我使用的是“AtiDx9Stereo.h”,它是 SDK 中的六个头文件之一(其他五个用于 DirectX 11 和 DirectX10)。

然而,经过大量的编码和测试,我终于成功启用了立体声,现在我可以在快门玻璃的左侧看到左图像,但在玻璃的右侧我什么也看不到。当我关闭我的相机时右边的我,我只能看到左边的图像。当我闭上左眼时,我只看到黑色页面(或将渲染目标清理为蓝色或其他颜色后的蓝色)。这是我的渲染代码和指针的初始化。如果有人曾在这些环境中工作过,很高兴分享一些知识。

初始化语句

pD3D=Direct3DCreate9(D3D_SDK_VERSION);
pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWindow,64,&d3pp,&pDevice);
pDevice->CreateOffscreenPlainSurface(10,10,(D3DFORMAT)FOURCC_AQBS,D3DPOOL_DEFAULT,&driverCommSurface,NULL);
SendStereoCommand(ATI_STEREO_ENABLESTEREO, NULL, 0, 0, 0);
SendStereoCommand(ATI_STEREO_GETLINEOFFSET, (BYTE *)(&lineOffset), sizeof(DWORD), 0, 0);

在这些语句之后,我的 render() 函数是这样的;

D3DVIEWPORT9 viewPort;

    memset(&viewPort,0,sizeof(viewPort));
    pDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&backBuffer);
    viewPort.X = 0;
    viewPort.Width = WINDOW_WIDTH;
    viewPort.Height = WINDOW_HEIGHT;

    if(SUCCEEDED(pDevice->BeginScene()))        //Start the device .
    {
        pDevice->SetRenderTarget(0, backBuffer);

        // Draw Right Eye Scene

        viewPort.Y = lineOffset;
        pDevice->SetViewport(&viewPort);
        pDevice->StretchRect(rightImageBuffer,NULL,backBuffer,NULL,D3DTEXF_LINEAR);




        // Draw Left Eye Scene

        viewPort.Y = 0;
        pDevice->SetViewport(&viewPort);
        pDevice->StretchRect(leftImageBuffer,NULL,backBuffer,NULL,D3DTEXF_LINEAR);

        backBuffer->Release();
        pDevice->EndScene();
        // Present both left and right buffers to the driver which will continuously
        // alternate between them until the next present

        pDevice->Present(NULL, NULL, NULL, NULL);





        return S_OK;
    }
    return E_FAIL;

在 WINMAIN 中,我用这些语句调用 render;

MSG msg;                                                    

    while(GetMessage(&msg,NULL,0,0))
    {

        if(str.isReady)                     //If rendering fails,an error-message is shown.
        {
            str.SwitchToRightEye();
            str.pDevice->Clear(0,NULL,D3DCLEAR_TARGET,0x000000ff, 1.0f, 0.0f); 
            str.UpdateRightQuadBuffer();
            str.render();

        }

        TranslateMessage(&msg);                     //Translate and dispatch the messages for the getMessage loop.
        DispatchMessage(&msg);
    }

I am currently working on a project and I need to display 3D image using the images that had been taken with Bumblebee2 3D Camera.I am working on a MSI AE2420 computer and it has AMD HD 5730 with 3D support.I also have a shutter glass to see the images in stereo mode.

I am using DirectX 9 libraries( d3dx9.h ).IDE is VS 2008 Express Edition.

I have sample images(left and right) and I imported them to the program succesively with the lines;

pDevice->CreateOffscreenPlainSurface(IMAGE_WIDTH,IMAGE_HEIGHT,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&leftImageBuffer,NULL);
pDevice->CreateOffscreenPlainSurface(IMAGE_WIDTH,IMAGE_HEIGHT,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&rightImageBuffer,NULL);

D3DXLoadSurfaceFromFile(leftImageBuffer,NULL,NULL,"left0000.bmp",NULL,D3DX_FILTER_NONE,0,NULL)
D3DXLoadSurfaceFromFile(rightImageBuffer,NULL,NULL,"right0000.bmp",NULL,D3DX_FILTER_NONE,0,NULL)

After some research,I found that Direct3D9 does not allow active Quad Buffer stereo.So I cannot use four buffers(left front,left back , right front,right back).That's where AMD's Quad Buffer SDK involves in.They indicate that DirectX 9 do not allow active stereo as well and I need to use the functions of the SDK. I'm using "AtiDx9Stereo.h" which is one of six header files in SDK(other five are for DirectX 11 and DirectX10).

However,after a lot of coding and testing ,I finally managed to enable stereo and now I can see the left image on the left side of the shutter glass,but in the right side of the glass I can see nothing.When I close my right I,I can see only left image.When I close my left eye,I see only a black page(or blue after cleaning the render target to blue or another color).Here is my render code and initialization of the pointers.If someone had been worked with these environment,that could be great to share some knowledge.

Initialization Statements

pD3D=Direct3DCreate9(D3D_SDK_VERSION);
pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWindow,64,&d3pp,&pDevice);
pDevice->CreateOffscreenPlainSurface(10,10,(D3DFORMAT)FOURCC_AQBS,D3DPOOL_DEFAULT,&driverCommSurface,NULL);
SendStereoCommand(ATI_STEREO_ENABLESTEREO, NULL, 0, 0, 0);
SendStereoCommand(ATI_STEREO_GETLINEOFFSET, (BYTE *)(&lineOffset), sizeof(DWORD), 0, 0);

After these statements, my render() function is is something like this;

D3DVIEWPORT9 viewPort;

    memset(&viewPort,0,sizeof(viewPort));
    pDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&backBuffer);
    viewPort.X = 0;
    viewPort.Width = WINDOW_WIDTH;
    viewPort.Height = WINDOW_HEIGHT;

    if(SUCCEEDED(pDevice->BeginScene()))        //Start the device .
    {
        pDevice->SetRenderTarget(0, backBuffer);

        // Draw Right Eye Scene

        viewPort.Y = lineOffset;
        pDevice->SetViewport(&viewPort);
        pDevice->StretchRect(rightImageBuffer,NULL,backBuffer,NULL,D3DTEXF_LINEAR);




        // Draw Left Eye Scene

        viewPort.Y = 0;
        pDevice->SetViewport(&viewPort);
        pDevice->StretchRect(leftImageBuffer,NULL,backBuffer,NULL,D3DTEXF_LINEAR);

        backBuffer->Release();
        pDevice->EndScene();
        // Present both left and right buffers to the driver which will continuously
        // alternate between them until the next present

        pDevice->Present(NULL, NULL, NULL, NULL);





        return S_OK;
    }
    return E_FAIL;

And in WINMAIN, I call render with these statements;

MSG msg;                                                    

    while(GetMessage(&msg,NULL,0,0))
    {

        if(str.isReady)                     //If rendering fails,an error-message is shown.
        {
            str.SwitchToRightEye();
            str.pDevice->Clear(0,NULL,D3DCLEAR_TARGET,0x000000ff, 1.0f, 0.0f); 
            str.UpdateRightQuadBuffer();
            str.render();

        }

        TranslateMessage(&msg);                     //Translate and dispatch the messages for the getMessage loop.
        DispatchMessage(&msg);
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

桃气十足 2024-12-26 18:44:07

我认为你应该尝试一下;

viewPort.Height = lineOffset;

而不是

viewPort.Height = WINDOW_HEIGHT;

I think you should try;

viewPort.Height = lineOffset;

instead of

viewPort.Height = WINDOW_HEIGHT;
断肠人 2024-12-26 18:44:07

您应该在 StretchRect 调用 rightImageBuffer 之前和之后调用 SendStereoCommand(ATI_STEREO_SETDSTEYE,..)。

像这样:

RECT destRect;

// Draw Right Eye Scene
destRect.top = lineOffset;
destRect.bottom = lineOffset + height;
viewPort.Y = lineOffset;

pDevice->SetViewport(&viewPort);

DWORD dwEye = ATI_STEREO_RIGHTEYE;
SendStereoCommand(ATI_STEREO_SETDSTEYE, NULL, 0, (BYTE *)&dwEye, sizeof(dwEye));

pDevice->StretchRect(rightImageBuffer,NULL,backBuffer,&destRect,D3DTEXF_LINEAR);    

// restore the destination
dwEye = ATI_STEREO_LEFTEYE;
SendStereoCommand(ATI_STEREO_SETDSTEYE, NULL, 0, (BYTE *)&dwEye, sizeof(dwEye)); 

// Draw Left Eye Scene
destRect.top = 0;
destRect.bottom = height;
viewPort.Y = 0;
pDevice->SetViewport(&viewPort);
pDevice->StretchRect(leftImageBuffer,NULL,backBuffer,&destRect,D3DTEXF_LINEAR);

...

并从 WINMAIN 中删除此代码:

str.SwitchToRightEye();
str.pDevice->Clear(0,NULL,D3DCLEAR_TARGET,0x000000ff, 1.0f, 0.0f); 
str.UpdateRightQuadBuffer();

更新:

我检查了 iZ3D 驱动程序中的代码,我认为您还应该根据 lineOffset 在 BackBuffer 的 StretchRect 调用中设置正确的目标矩形。这可能可以在不改变视口的情况下工作。

您应该检查驱动程序是否返回正确的 lineOffset 值(略大于后备缓冲区高度)以及从 SendStereoCommand() 返回的 HRESULT。

You should call SendStereoCommand(ATI_STEREO_SETDSTEYE,..) before and after StretchRect call for rightImageBuffer.

Something like that:

RECT destRect;

// Draw Right Eye Scene
destRect.top = lineOffset;
destRect.bottom = lineOffset + height;
viewPort.Y = lineOffset;

pDevice->SetViewport(&viewPort);

DWORD dwEye = ATI_STEREO_RIGHTEYE;
SendStereoCommand(ATI_STEREO_SETDSTEYE, NULL, 0, (BYTE *)&dwEye, sizeof(dwEye));

pDevice->StretchRect(rightImageBuffer,NULL,backBuffer,&destRect,D3DTEXF_LINEAR);    

// restore the destination
dwEye = ATI_STEREO_LEFTEYE;
SendStereoCommand(ATI_STEREO_SETDSTEYE, NULL, 0, (BYTE *)&dwEye, sizeof(dwEye)); 

// Draw Left Eye Scene
destRect.top = 0;
destRect.bottom = height;
viewPort.Y = 0;
pDevice->SetViewport(&viewPort);
pDevice->StretchRect(leftImageBuffer,NULL,backBuffer,&destRect,D3DTEXF_LINEAR);

...

and remove this code from WINMAIN:

str.SwitchToRightEye();
str.pDevice->Clear(0,NULL,D3DCLEAR_TARGET,0x000000ff, 1.0f, 0.0f); 
str.UpdateRightQuadBuffer();

Update:

I checked the code in our iZ3D Driver and I think you should, also, set correct destination rectangle in StretchRect calls for BackBuffer in accordance with lineOffset. This probably could work without changing viewport at all.

You should check that driver return you correct value for lineOffset (slightly bigger that backbuffer height) and HRESULT returned from SendStereoCommand().

绝影如岚 2024-12-26 18:44:07

我使用与AMD文档完全不同的方法解决了这个问题。而且我认为他们的SDK中的功能无法正常工作。对我来说尝试遵循文档中的步骤完全是浪费时间。

这是该项目的链接。

http://code.google.com/p/3d-viewer-buffer

I solved the problem using a totally different method from AMD's documentation.And I think the functions in their SDK do not work properly. It was totally a waste of time for me to trying to follow that steps in documentation.

Here is the link for the project.

http://code.google.com/p/3d-viewer-buffer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文