4

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

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

我查看了 OpenGL、Direct3D 和 XNA API,以及来自 NVIDIA 的信息,但不知道如何开始。如何设置单独的左右图像,如何告诉屏幕显示它,以及如何告诉驱动程序激活快门发射器?

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

4

2 回答 2

3

我对此有点晚了,但我只是使用 GTX 580 和 OpenGL 让立体 3D 工作。无需 quadro 卡或 DirectX。

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

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

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

于 2012-11-21T01:15:42.510 回答
2

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

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

ps.我确实找到了一些示例代码,可以用普通窗口来做到这一点。
编辑 - 这是一个低级 USB 代码与我永远无法构建的 xmitter 对话,我认为它最终变成了这个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

}
于 2011-02-08T04:41:42.760 回答