如何编程支持立体声的图形卡以显示立体图像?

时间:2011-02-08 04:09:56

标签: stereoscopy

我想编写自己的立体图像查看器,因为我需要的某些功能与我的NVidia / EVGA GTX 580捆绑在一起所缺少。

我无法弄清楚如何对卡进行编程以进入“快门”模式,其中每隔一帧(120 HZ)左右交替。

我查看了OpenGL,Direct3D和XNA API以及NVIDIA的信息,但无法弄清楚如何开始使用。如何设置单独的左右图像,如何告诉屏幕显示它,以及如何告诉驱动程序激活快门眼镜发射器?

(另一个令人不安的事情是,每当我使用捆绑的软件在快门眼镜模式下观看立体图像和视频时,它都是全屏的,并且当进入该模式时屏幕闪烁 - 即使我在2D中以120Hz运行屏幕。有没有办法在窗口中创建一个3D表面,而不会破坏具有3D功能的NVidia“游戏玩家”卡的其余部分(570,580)?

2 个答案:

答案 0 :(得分:3)

我有点晚了,但我只是使用GTX 580和OpenGL来制作立体3D。无需Quadro卡或DirectX。

我有nVidia 3D Vision驱动程序和红外发射器,只需在nVidia控制面板中将发射器设置为“始终开启”。

在我的游戏引擎中,我切换到120Hz的全屏模式,并以略微平截头体偏移渲染场景两次(根据nVidia自己的文档PDF手册实现“2010_GTC2010.pdf”)。

不需要四重缓冲或任何其他技巧,效果很好。另外,我可以控制所有设置,例如收敛等。

答案 1 :(得分:2)

对于带有GEForce系列的NVidia 3Dvision,你需要在显示器宽度的两倍上写一个全屏directX表面,左边的图像在右边(右边)。左边。 然后你需要在NVision驱动程序拾取并打开眼镜的图像的左下角写一个魔术值,你不需要nvapi.dll

使用Nvidia pro眼镜和Quadra卡,您可以使用常规的OpenGL立体声API。

ps.I确实找到了一些示例代码,可以通过普通窗口来完成此操作 编辑 - 这是一个与xmitter交谈的低级USB代码,我永远无法构建,我认为它最终成为了http://sourceforge.net/projects/libnvstusb/

以下是使用NVision眼镜全屏的示例代码 我不是DirectX专家,因此其中一些可能不是最佳的 我的应用程序也基于Qt,代码中可能还有一些Qt位

-----------------------------------------------------------------
    // header
    void create3D();
    void set3D();
    IDirect3D9 *_d3d;
    IDirect3DDevice9 *_d3ddev;
    QSize _size; // full screen size 

    IDirect3DSurface9 *_imageBuf; //Source stereo image
    IDirect3DSurface9 *_backBuf;    


--------------------------------------------------------
   // the code     
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <strsafe.h>

#pragma comment (lib, "d3d9.lib")

#define NVSTEREO_IMAGE_SIGNATURE 0x4433564e //NV3D

typedef struct _Nv_Stereo_Image_Header
{
unsigned int dwSignature;
unsigned int dwWidth;
unsigned int dwHeight;
unsigned int dwBPP;
unsigned int dwFlags;
} NVSTEREOIMAGEHEADER, *LPNVSTEREOIMAGEHEADER;


// ORedflags in the dwFlagsfielsof the _Nv_Stereo_Image_Headerstructure above
#define SIH_SWAP_EYES 0x00000001
#define SIH_SCALE_TO_FIT 0x00000002

// call at start to set things up
void DisplayWidget::create3D()
{
        _size = QSize(1680,1050); //resolution of my Samsung 2233z

        _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 = FALSE;    // program fullscreen
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames
        d3dpp.hDeviceWindow = winId();    // set the window to be used by Direct3D
        d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;  // set the back buffer format to 32 bit // or D3DFMT_R8G8B8
        d3dpp.BackBufferWidth = _size.width();
        d3dpp.BackBufferHeight = _size.height();
        d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
        d3dpp.BackBufferCount = 1;

        // create a device class using this information and information from the d3dpp stuct
        _d3d->CreateDevice(D3DADAPTER_DEFAULT,
                          D3DDEVTYPE_HAL,
                          winId(),
                          D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                          &d3dpp,
                          &_d3ddev);


    //3D VISION uses a single surface 2x images wide and image high
    // create the surface 
    _d3ddev->CreateOffscreenPlainSurface(_size.width()*2, _size.height(), D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &_imageBuf, NULL);

    set3D();

}

// call to put 3d signature in image
void DisplayWidget::set3D()
{

    // Lock the stereo image
    D3DLOCKED_RECT lock;
    _imageBuf->LockRect(&lock,NULL,0);

    // write stereo signature in the last raw of the stereo image
    LPNVSTEREOIMAGEHEADER pSIH = (LPNVSTEREOIMAGEHEADER)(((unsigned char *) lock.pBits) + (lock.Pitch * (_size.height()-1)));

    // Update the signature header values
    pSIH->dwSignature = NVSTEREO_IMAGE_SIGNATURE;
    pSIH->dwBPP = 32;
    //pSIH->dwFlags = SIH_SWAP_EYES; // Src image has left on left and right on right, thats why this flag is not needed.
    pSIH->dwFlags = SIH_SCALE_TO_FIT;
    pSIH->dwWidth = _size.width() *2;
    pSIH->dwHeight = _size.height();

    // Unlock surface
    _imageBuf->UnlockRect();

}

// call in display loop
void DisplayWidget::paintEvent()
{
    // clear the window to a deep blue
    //_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);

    _d3ddev->BeginScene();    // begins the 3D scene

    // do 3D rendering on the back buffer here
    RECT destRect;
    destRect.left = 0;
    destRect.top = 0;
    destRect.bottom = _size.height();
    destRect.right = _size.width();

    // Get the Backbuffer then Stretch the Surface on it.
    _d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &_backBuf);
    _d3ddev->StretchRect(_imageBuf, NULL, _backBuf, &destRect, D3DTEXF_NONE); 
    _backBuf->Release();

    _d3ddev->EndScene();    // ends the 3D scene

    _d3ddev->Present(NULL, NULL, NULL, NULL);    // displays the created frame
}

// my images come from a camera
// _left and _right are QImages but it should be obvious what the functions do  
void DisplayWidget::getImages()
{
                RECT srcRect;
                srcRect.left = 0;
                srcRect.top = 0;
                srcRect.bottom = _size.height();
                srcRect.right = _size.width();

                RECT destRect;              
                destRect.top = 0;
                destRect.bottom = _size.height();

                if ( isOdd() ) {                    
                    destRect.left = _size.width();
                    destRect.right = _size.width()*2;
                    // get camera data for _left here, code not shown               
                    D3DXLoadSurfaceFromMemory(_imageBuf, NULL, &destRect,_right.bits(),D3DFMT_A8R8G8B8,_right.bytesPerLine(),NULL,&srcRect,D3DX_DEFAULT,0);         
                } else {
                    destRect.left = 0;
                    destRect.right = _size.width();
                    // get camera data for _right here, code not shown          
                    D3DXLoadSurfaceFromMemory(_imageBuf, NULL, &destRect,_left.bits(),D3DFMT_A8R8G8B8,_left.bytesPerLine(),NULL,&srcRect,D3DX_DEFAULT,0);           
                }


                set3D();    // add NVidia signature

}

DisplayWidget::~DisplayWidget()
{
    _d3ddev->Release();    // close and release the 3D device
    _d3d->Release();    // close and release Direct3D

}