1. #ifndef MY_FRAME__HH__
  2. #define MY_FRAME__HH__
  3. #include <QtGui/QWidget>
  4.  
  5. struct IDirect3D9;
  6. struct IDirect3DDevice9;
  7.  
  8. class QD3DWidget : public QWidget
  9. {
  10. Q_OBJECT
  11.  
  12. public:
  13. QD3DWidget( QWidget* pParent = NULL);
  14.  
  15. ~QD3DWidget();
  16.  
  17. QSizePolicy sizePolicy() const { return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); }
  18. QPaintEngine *paintEngine() const { return NULL; }
  19.  
  20. protected:
  21. void Setup();
  22.  
  23. void Close();
  24.  
  25. void paintEvent( QPaintEvent* pEvent);
  26.  
  27. private:
  28. IDirect3D9* mD3D;
  29. IDirect3DDevice9* mDevice;
  30. };
  31. #endif
  1. #include <QMessageBox>
  2. #define WIN32_LEAN_AND_MEAN
  3. #include <d3d9.h>
  4. #include <d3dx9.h>
  5. #include "MyFrame.h"
  6. #pragma comment(lib, "d3dx9d.lib")
  7. #pragma comment(lib, "d3d9.lib")
  8. QD3DWidget::QD3DWidget( QWidget* pParent)
  9. : QWidget( pParent)
  10. {
  11.  
  12. mD3D = NULL;
  13. mDevice = NULL;
  14.  
  15. setMinimumSize( , );
  16. setAttribute( Qt::WA_OpaquePaintEvent, true);
  17. setAttribute( Qt::WA_PaintOnScreen, true);
  18.  
  19. Setup();
  20. }
  21.  
  22. QD3DWidget::~QD3DWidget()
  23. {
  24. Close();
  25. }
  26.  
  27. void QD3DWidget::Setup()
  28. {
  29. HWND windowHandle = winId();
  30.  
  31. mD3D = Direct3DCreate9( D3D_SDK_VERSION);
  32. if( NULL == mD3D)
  33. QMessageBox::critical(this,
  34. "ERROR",
  35. "Failed to create D3D object",
  36. QMessageBox::Ok);
  37.  
  38. D3DPRESENT_PARAMETERS d3dpp;
  39.  
  40. ZeroMemory(&d3dpp, sizeof(d3dpp));
  41. d3dpp.Windowed = TRUE;
  42. d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
  43. d3dpp.hDeviceWindow = windowHandle;
  44.  
  45. HRESULT hr = mD3D->CreateDevice(D3DADAPTER_DEFAULT,
  46. D3DDEVTYPE_HAL,
  47. windowHandle,
  48. D3DCREATE_SOFTWARE_VERTEXPROCESSING,
  49. &d3dpp,
  50. &mDevice);
  51.  
  52. if( FAILED( hr))
  53. QMessageBox::critical(this,
  54. "ERROR",
  55. "Failed to create D3D device",
  56. QMessageBox::Ok);
  57. }
  58.  
  59. void QD3DWidget::Close()
  60. {
  61. if( mDevice)
  62. mDevice->Release();
  63. if( mD3D)
  64. mD3D->Release();
  65. }
  66.  
  67. void QD3DWidget::paintEvent( QPaintEvent* pEvent)
  68. {
  69. HRESULT hr = mDevice->Clear(, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(, , ), 1.0f, );
  70. if( FAILED( hr))
  71. QMessageBox::critical(this,
  72. "ERROR",
  73. "Failed to clear backbuffer.",
  74. QMessageBox::Ok);
  75.  
  76. mDevice->BeginScene();
  77.  
  78. mDevice->EndScene();
  79.  
  80. hr = mDevice->Present(NULL, NULL, NULL, NULL);
  81. if( FAILED( hr))
  82. QMessageBox::critical(this,
  83. "ERROR",
  84. "Failed to Present().",
  85. QMessageBox::Ok);
  86.  
  87. update();
  88. }

Qt_DX的更多相关文章

随机推荐

  1. sublime text3 用法

    1. 使用lint进行语法及风格校验 jshint可以统一编码风格. 安装jshint的步骤: 1)ctrl+shift+p打开命令模式--->输入pcip回车--->输入sublimel ...

  2. 在Freeplane中显示与隐藏层级图标

    如下图所示,当选择了Edit → Icons → Show icons hierarchically时,给子节点Subsection 1.2.1添加的图标也同样会显示在其所有的父节点上,并且,它们并不 ...

  3. 嗯,这个BLOG其实是个更新服务器

    2333 软件:http://dwz.cn/NKSGUI

  4. MATLAB初体验

    好激动 要入MATLAB的大坑了 恩 很遗憾第一个程序并不是hello world 好 插入代码里并没有MATLAB这个选项 这是一种歧视 x=[:pi/:*pi]; y=sin(x); plot(x ...

  5. 在tableview的headerView中添加webView,webView自适应高度

    最近在项目中需要添加一个webView加载的页面,下面显示的是对这个webView所显示的内容的一个评论列表 ,列表要根据后台加载过来的HTML自适应的变化高度,tableview的cell在webV ...

  6. 多表查询 INNER JOIN ON WHERE

    SELECT *FROM STUDENT_INFO siINNER JOIN CLASS_INFO ci on si.CLASS_INFO_ID = ci.ID INNER JOIN TEACHER_ ...

  7. jenkins 杀死衍生进程

    解决方法-1: 在execute shell输入框中加入BUILD_ID=DONTKILLME,即可防止jenkins衍生进程 解决方法-2: 修改/etc/sysconfig/jenkins配置,在 ...

  8. 跑github上的Symfony项目遇到的问题2

    最近学习symfony框架,下载了大量的github上的别人的项目,要想跑起别人的项目,总结了以下几个步骤: 第一, 克隆一份代码; 第二,安装依赖,前提是安装了composer, 1:在你下载的项目 ...

  9. css-ie6下实现最小,最大宽度

    _width: expression((document.documentElement.clientWidth||document.body.clientWidth)<1040?"1 ...

  10. [SOJ] can I post the letter?

    1155. Can I Post the letter Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description I am a t ...