Problems with trying to get D3DX9/10 to work in Qt



  • I'm trying to get D3D9/10/10.....ect to work in Qt4 but it wont create the window at all, it gives an access violation when runned the device must not b e getti ng cvreated....:-( here's my code.

    @

    header:

    #ifndef CD3D10_H
    #define CD3D10_H

    #include <QWidget>
    #include <D3D10.h>
    #include <DXGI.h>
    #include <D3DX10.h>

    #pragma comment(lib,"d3d10.lib")
    #pragma comment(lib,"d3dx10.lib")

    class CD3D10 : public QWidget
    {
    public:
    CD3D10(QWidget* parent = 0);

    ~CD3D10();

    protected:
    bool createD3D10();
    void paintEvent(QPaintEvent *);
    void resizeEvent(QResizeEvent *);

    private:
    ID3D10Device* m_pD3D10Dev;
    IDXGISwapChain* m_pD3DSwapChain;
    ID3D10RenderTargetView* m_pRenderView;
    DXGI_SWAP_CHAIN_DESC m_pSwapChainDesc;
    ID3D10Texture2D* m_pBackBuffer;
    D3D10_VIEWPORT m_pViewport;
    IDXGIAdapter* m_pAdapter;
    };

    #endif

    source:

    #include "CD3D10.h"

    CD3D10::CD3D10(QWidget* parent /* = 0 */)
    : QWidget(parent)
    {
    this->createD3D10();
    }

    CD3D10::~CD3D10()
    {
    this->m_pD3D10Dev->Release();
    this->m_pD3DSwapChain->Release();

    }

    bool CD3D10::createD3D10()
    {
    ZeroMemory(&this->m_pSwapChainDesc,sizeof(DXGI_SWAP_CHAIN_DESC));

    m_pSwapChainDesc.BufferCount = 1;
    m_pSwapChainDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
    m_pSwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    m_pSwapChainDesc.OutputWindow = this->winId();
    m_pSwapChainDesc.SampleDesc.Count = 1;
    m_pSwapChainDesc.SampleDesc.Quality = 0;
    m_pSwapChainDesc.Windowed = true;

    HRESULT hr = D3D10CreateDeviceAndSwapChain(NULL,
    D3D10_DRIVER_TYPE_HARDWARE,
    NULL,
    0,D3D10_SDK_VERSION,
    &this->m_pSwapChainDesc,
    &m_pD3DSwapChain,
    &m_pD3D10Dev
    );

    if(FAILED(hr))
    {
    MessageBoxA(NULL,"Blah, Blah","",MB_OK);
    return false;
    }

    ID3D10Texture2D* buffer;
    m_pD3DSwapChain->GetBuffer(0,__uuidof(ID3D10Texture2D),(LPVOID*)&buffer);

    m_pD3D10Dev->CreateRenderTargetView(buffer,NULL,&this->m_pRenderView);
    buffer->Release();
    m_pD3D10Dev->OMGetRenderTargets(1,&this->m_pRenderView,NULL);

    ZeroMemory(&m_pViewport,sizeof(D3D10_VIEWPORT));

    m_pViewport.TopLeftX = 0;
    m_pViewport.TopLeftY = 0;
    m_pViewport.Width = 800;
    m_pViewport.Height = 600;

    m_pD3D10Dev->RSSetViewports(0,&this->m_pViewport);

    return true;

    }

    void CD3D10::paintEvent(QPaintEvent *paint)
    {
    m_pD3D10Dev->ClearRenderTargetView(this->m_pRenderView,D3DXCOLOR(0.0f,0.0f,0.5f,0.3f));

    m_pD3DSwapChain->Present(0,0);

    }

    void CD3D10::resizeEvent(QResizeEvent *event)
    {

    }

    @
    hopefully someone can help me



  • As far as I know, you should override the paint event to a null function and do your rendering from another function.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.