November 20, 2010

ProgrammerAtHeart3344 ProgrammerAt..
Lab Rat
44 posts

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.

  1. header:
  2.  
  3. #ifndef CD3D10_H
  4. #define CD3D10_H
  5.  
  6. #include <QWidget>
  7. #include <D3D10.h>
  8. #include <DXGI.h>
  9. #include <D3DX10.h>
  10.  
  11.  
  12.  
  13. #pragma comment(lib,"d3d10.lib")
  14. #pragma comment(lib,"d3dx10.lib")
  15.  
  16. class CD3D10 : public QWidget
  17. {
  18. public:
  19.  CD3D10(QWidget* parent = 0);
  20.  
  21.  ~CD3D10();
  22.  
  23. protected:
  24.  bool createD3D10();
  25.  void paintEvent(QPaintEvent *);
  26.  void resizeEvent(QResizeEvent *);
  27.  
  28. private:
  29.  ID3D10Device* m_pD3D10Dev;
  30.  IDXGISwapChain* m_pD3DSwapChain;
  31.  ID3D10RenderTargetView* m_pRenderView;
  32.  DXGI_SWAP_CHAIN_DESC m_pSwapChainDesc;
  33.  ID3D10Texture2D* m_pBackBuffer;
  34.  D3D10_VIEWPORT m_pViewport;
  35.  IDXGIAdapter*  m_pAdapter;
  36. };
  37.  
  38. #endif
  39.  
  40. source:
  41.  
  42. #include "CD3D10.h"
  43.  
  44. CD3D10::CD3D10(QWidget* parent /* = 0 */)
  45. : QWidget(parent)
  46. {
  47.  this->createD3D10();
  48. }
  49.  
  50. CD3D10::~CD3D10()
  51. {
  52.  this->m_pD3D10Dev->Release();
  53.  this->m_pD3DSwapChain->Release();
  54.  
  55. }
  56.  
  57. bool CD3D10::createD3D10()
  58. {
  59.  ZeroMemory(&this->m_pSwapChainDesc,sizeof(DXGI_SWAP_CHAIN_DESC));
  60.  
  61.  m_pSwapChainDesc.BufferCount = 1;
  62.  m_pSwapChainDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
  63.  m_pSwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
  64.  m_pSwapChainDesc.OutputWindow = this->winId();
  65.  m_pSwapChainDesc.SampleDesc.Count = 1;
  66.  m_pSwapChainDesc.SampleDesc.Quality = 0;
  67.  m_pSwapChainDesc.Windowed = true;
  68.  
  69. HRESULT hr = D3D10CreateDeviceAndSwapChain(NULL,
  70.   D3D10_DRIVER_TYPE_HARDWARE,
  71.   NULL,
  72.   0,D3D10_SDK_VERSION,
  73.   &this->m_pSwapChainDesc,
  74.   &m_pD3DSwapChain,
  75.   &m_pD3D10Dev
  76.   );
  77.  
  78. if(FAILED(hr))
  79. {
  80.  MessageBoxA(NULL,"Blah, Blah","",MB_OK);
  81.  return false;
  82. }
  83.  
  84.  
  85.  ID3D10Texture2D* buffer;
  86.  m_pD3DSwapChain->GetBuffer(0,__uuidof(ID3D10Texture2D),(LPVOID*)&buffer);
  87.  
  88.  
  89.  m_pD3D10Dev->CreateRenderTargetView(buffer,NULL,&this->m_pRenderView);
  90. buffer->Release();
  91.  m_pD3D10Dev->OMGetRenderTargets(1,&this->m_pRenderView,NULL);
  92.  
  93.  ZeroMemory(&m_pViewport,sizeof(D3D10_VIEWPORT));
  94.  
  95.  m_pViewport.TopLeftX = 0;
  96.  m_pViewport.TopLeftY = 0;
  97.  m_pViewport.Width    = 800;
  98.  m_pViewport.Height   = 600;
  99.  
  100.  m_pD3D10Dev->RSSetViewports(0,&this->m_pViewport);
  101.  
  102.  return true;
  103.  
  104. }
  105.  
  106. void CD3D10::paintEvent(QPaintEvent *paint)
  107. {
  108.  m_pD3D10Dev->ClearRenderTargetView(this->m_pRenderView,D3DXCOLOR(0.0f,0.0f,0.5f,0.3f));
  109.  
  110.  m_pD3DSwapChain->Present(0,0);
  111.  
  112. }
  113.  
  114. void CD3D10::resizeEvent(QResizeEvent *event)
  115. {
  116.  
  117. }

hopefully someone can help me

1 reply

December 6, 2010

Franzk Franzk
Lab Rat
837 posts

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

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

 
  ‹‹ How QML cycle sprites?      Detecting what is shown on the display ››

You must log in to post a reply. Not a member yet? Register here!