Qt_DX
- #ifndef MY_FRAME__HH__
- #define MY_FRAME__HH__
- #include <QtGui/QWidget>
- struct IDirect3D9;
- struct IDirect3DDevice9;
- class QD3DWidget : public QWidget
- {
- Q_OBJECT
- public:
- QD3DWidget( QWidget* pParent = NULL);
- ~QD3DWidget();
- QSizePolicy sizePolicy() const { return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); }
- QPaintEngine *paintEngine() const { return NULL; }
- protected:
- void Setup();
- void Close();
- void paintEvent( QPaintEvent* pEvent);
- private:
- IDirect3D9* mD3D;
- IDirect3DDevice9* mDevice;
- };
- #endif
- #include <QMessageBox>
- #define WIN32_LEAN_AND_MEAN
- #include <d3d9.h>
- #include <d3dx9.h>
- #include "MyFrame.h"
- #pragma comment(lib, "d3dx9d.lib")
- #pragma comment(lib, "d3d9.lib")
- QD3DWidget::QD3DWidget( QWidget* pParent)
- : QWidget( pParent)
- {
- mD3D = NULL;
- mDevice = NULL;
- setMinimumSize( , );
- setAttribute( Qt::WA_OpaquePaintEvent, true);
- setAttribute( Qt::WA_PaintOnScreen, true);
- Setup();
- }
- QD3DWidget::~QD3DWidget()
- {
- Close();
- }
- void QD3DWidget::Setup()
- {
- HWND windowHandle = winId();
- mD3D = Direct3DCreate9( D3D_SDK_VERSION);
- if( NULL == mD3D)
- QMessageBox::critical(this,
- "ERROR",
- "Failed to create D3D object",
- QMessageBox::Ok);
- D3DPRESENT_PARAMETERS d3dpp;
- ZeroMemory(&d3dpp, sizeof(d3dpp));
- d3dpp.Windowed = TRUE;
- d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
- d3dpp.hDeviceWindow = windowHandle;
- HRESULT hr = mD3D->CreateDevice(D3DADAPTER_DEFAULT,
- D3DDEVTYPE_HAL,
- windowHandle,
- D3DCREATE_SOFTWARE_VERTEXPROCESSING,
- &d3dpp,
- &mDevice);
- if( FAILED( hr))
- QMessageBox::critical(this,
- "ERROR",
- "Failed to create D3D device",
- QMessageBox::Ok);
- }
- void QD3DWidget::Close()
- {
- if( mDevice)
- mDevice->Release();
- if( mD3D)
- mD3D->Release();
- }
- void QD3DWidget::paintEvent( QPaintEvent* pEvent)
- {
- HRESULT hr = mDevice->Clear(, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(, , ), 1.0f, );
- if( FAILED( hr))
- QMessageBox::critical(this,
- "ERROR",
- "Failed to clear backbuffer.",
- QMessageBox::Ok);
- mDevice->BeginScene();
- mDevice->EndScene();
- hr = mDevice->Present(NULL, NULL, NULL, NULL);
- if( FAILED( hr))
- QMessageBox::critical(this,
- "ERROR",
- "Failed to Present().",
- QMessageBox::Ok);
- update();
- }
Qt_DX的更多相关文章
随机推荐
- sublime text3 用法
1. 使用lint进行语法及风格校验 jshint可以统一编码风格. 安装jshint的步骤: 1)ctrl+shift+p打开命令模式--->输入pcip回车--->输入sublimel ...
- 在Freeplane中显示与隐藏层级图标
如下图所示,当选择了Edit → Icons → Show icons hierarchically时,给子节点Subsection 1.2.1添加的图标也同样会显示在其所有的父节点上,并且,它们并不 ...
- 嗯,这个BLOG其实是个更新服务器
2333 软件:http://dwz.cn/NKSGUI
- MATLAB初体验
好激动 要入MATLAB的大坑了 恩 很遗憾第一个程序并不是hello world 好 插入代码里并没有MATLAB这个选项 这是一种歧视 x=[:pi/:*pi]; y=sin(x); plot(x ...
- 在tableview的headerView中添加webView,webView自适应高度
最近在项目中需要添加一个webView加载的页面,下面显示的是对这个webView所显示的内容的一个评论列表 ,列表要根据后台加载过来的HTML自适应的变化高度,tableview的cell在webV ...
- 多表查询 INNER JOIN ON WHERE
SELECT *FROM STUDENT_INFO siINNER JOIN CLASS_INFO ci on si.CLASS_INFO_ID = ci.ID INNER JOIN TEACHER_ ...
- jenkins 杀死衍生进程
解决方法-1: 在execute shell输入框中加入BUILD_ID=DONTKILLME,即可防止jenkins衍生进程 解决方法-2: 修改/etc/sysconfig/jenkins配置,在 ...
- 跑github上的Symfony项目遇到的问题2
最近学习symfony框架,下载了大量的github上的别人的项目,要想跑起别人的项目,总结了以下几个步骤: 第一, 克隆一份代码; 第二,安装依赖,前提是安装了composer, 1:在你下载的项目 ...
- css-ie6下实现最小,最大宽度
_width: expression((document.documentElement.clientWidth||document.body.clientWidth)<1040?"1 ...
- [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 ...