Reputation: 91
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);
}
Upvotes: 2
Views: 1319
Reputation: 91
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
Upvotes: 0
Reputation: 6871
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().
Upvotes: 0
Reputation: 5823
I think you should try;
viewPort.Height = lineOffset;
instead of
viewPort.Height = WINDOW_HEIGHT;
Upvotes: 1