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的更多相关文章
随机推荐
- C# CacheHelper
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...
- C# 语言规范_版本5.0 (第20章 附录B_语法)
A. 语法 此附录是主文档中描述的词法和语法以及不安全代码的语法扩展的摘要.这里,各语法产生式是按它们在主文档中出现的顺序列出的. A.1 词法文法 input: input-sectionopt i ...
- LeetCode 392. Is Subsequence
Given a string s and a string t, check if s is subsequence of t. You may assume that there is only l ...
- Spring in Action --- 第二章 装配Bean
Spirng配置的可选方案 在XML中进行显示配置 在Java中进行显示配置 隐式的bean发现机制和自动装配 bean装配 1. 在希望被扫描到的类上加注解 @Component 2. 基于不同的配 ...
- Python将列表中的string元素进行类型转换
例如 将 a=['1','2.0','3L'] 转换为 a=[1,2.0,3L] 只需 map(eval,['1','2.0','3L']) 即可 eval(expression[, globals[ ...
- ORACLE AWR性能报告和ASH性能报告的解读
数据库的性能分析可分为会话级和系统级:如果确定某个会话存在性能问题,最常见的分析方式是对这个会话做一个SQL_TRACE或者10046事件,通过分析trace文件来定位问题所在.如果无法确定哪个会话性 ...
- IntelliJ IDEA “Finds duplicated code”提示如何关闭
发现重复的代码这个提示真的很烦啊,我们怎么关闭他呢. 设置在这里: Settings -> Editor -> Inspections -> General -> Duplic ...
- xaml中的依赖属性
wpf使用依赖属性完成数据绑定.动画.属性变更通知.样式化等.对于数据绑定.绑定到.NET属性源上的UI元素的属性必须是依赖属性 .net的一般属性定义如下 private int val; ...
- [河南省ACM省赛-第三届] AMAZING AUCTION (nyoj 251)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=251 规则: 1.若某竞标价唯一,则胜出 2.若不存在唯一竞标价,则投标次数最少竞标价中标 ...
- Java基础第3章