我目前正在开展一个项目,我需要使用Bumblebee2 3D Camera拍摄的图像显示3D图像。我正在使用MSI AE2420计算机,它具有支持3D的AMD HD 5730.I还有快门眼镜以立体声模式观看图像。
我正在使用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);
}
答案 0 :(得分:1)
我想你应该试试;
viewPort.Height = lineOffset;
而不是
viewPort.Height = WINDOW_HEIGHT;
答案 1 :(得分:0)
你应该在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在StretchRect调用BackBuffer中设置正确的目标矩形。这可能无需更改视口即可。
您应检查该驱动程序是否为lineOffset返回了正确的值(稍大于后备缓冲区高度)和从SendStereoCommand()返回的HRESULT。
答案 2 :(得分:0)
我使用与AMD文档完全不同的方法解决了这个问题。我认为他们SDK中的功能无法正常工作。试图在文档中遵循这些步骤对我来说完全是浪费时间。
这是该项目的链接。