Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

how to build a engine that uses QT4.5+dx10+vs2008

Started by guqun Dec 26, 2009 at 5:42 AM 2 replies 1.3k views
Original Post
guqun
guqun
HI, i have built a engine that uses QT4.5+DX10+vs2008.my code is right for compiling ,but the result is error.i just set the background's color and not render others.when run it,i can see the background's color,however,the color flicker.i could not find the way for solving this problem. my code : D3D cpp: D3DInital::D3DInital(HWND hWnd,QWidget* widget) { wigetRender=hWnd; widgetR=widget; } D3DInital::~D3DInital() { } bool D3DInital::intial() { initalDevice(); return true; } void D3DInital::onResize() { } void D3DInital::render() { float ClearColor[4] = { 1.0f, 0.125f, 0.3f, 1.0f }; //red,green,blue,alpha g_pd3dDevice->ClearRenderTargetView( g_pRenderTargetView, ClearColor ); g_pd3dDevice->ClearDepthStencilView(mDepthStencilView, D3D10_CLEAR_DEPTH|D3D10_CLEAR_STENCIL, 1.0f, 0); g_pSwapChain->Present(0,0); } HRESULT D3DInital::initalDevice() { HRESULT hr = S_OK;; UINT width = widgetR->width(); UINT height =widgetR->height(); UINT createDeviceFlags = 0; #ifdef _DEBUG createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG; #endif g_driverType=D3D10_DRIVER_TYPE_HARDWARE; DXGI_SWAP_CHAIN_DESC sd; ZeroMemory( &sd, sizeof( sd ) ); sd.BufferCount = 1; sd.BufferDesc.Width = width; sd.BufferDesc.Height = height; sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1; sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.OutputWindow = wigetRender; sd.SampleDesc.Count = 1; sd.SampleDesc.Quality = 0; sd.Windowed = TRUE; hr = D3D10CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags, D3D10_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice ); if( FAILED( hr ) ) return hr; // Create a render target view ID3D10Texture2D* pBackBuffer; hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D10Texture2D ), ( LPVOID* )&pBackBuffer ); if( FAILED( hr ) ) return hr; hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView ); pBackBuffer->Release(); if( FAILED( hr ) ) return hr; g_pd3dDevice->OMSetRenderTargets( 1, &g_pRenderTargetView, NULL ); D3D10_TEXTURE2D_DESC depthStencilDesc; depthStencilDesc.Width = width; depthStencilDesc.Height = height; depthStencilDesc.MipLevels = 1; depthStencilDesc.ArraySize = 1; depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; depthStencilDesc.SampleDesc.Count = 1; // multisampling must match depthStencilDesc.SampleDesc.Quality = 0; // swap chain values. depthStencilDesc.Usage = D3D10_USAGE_DEFAULT; depthStencilDesc.BindFlags = D3D10_BIND_DEPTH_STENCIL; depthStencilDesc.CPUAccessFlags = 0; depthStencilDesc.MiscFlags = 0; HR(g_pd3dDevice->CreateTexture2D(&depthStencilDesc, 0, &mDepthStencilBuffer)); HR(g_pd3dDevice->CreateDepthStencilView(mDepthStencilBuffer, 0, &mDepthStencilView)); // Bind the render target view and depth/stencil view to the pipeline. g_pd3dDevice->OMSetRenderTargets(1, &g_pRenderTargetView, mDepthStencilView); // Setup the viewport D3D10_VIEWPORT vp; vp.Width = width; vp.Height = height; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; vp.TopLeftX = 0; vp.TopLeftY = 0; g_pd3dDevice->RSSetViewports( 1, &vp ); return S_OK; } qt cpp: WidgetDX::WidgetDX(QWidget* widget):QWidget(widget) { setAttribute(Qt::WA_PaintOnScreen, true); initializeD3D(); } WidgetDX::~WidgetDX() { } void WidgetDX::d3dDraw() { d3dInital->render(); } void WidgetDX::paintEvent(QPaintEvent*) { if(updatesEnabled()) d3dDraw(); } void WidgetDX::initializeD3D() { d3dInital=new D3DInital(winId(),this); d3dInital->intial(); } void WidgetDX::showEvent(QShowEvent *event) { startTimer(20); } void WidgetDX::timerEvent(QTimerEvent *event) { update(); }
Tordin
Tordin
i belive it is becus of your "Render" function, you wont be able to render anything att al, except your background, the Clear functions clears the screen in that color and the Present function is supposed to be calld after every thing is renderd.
"There will be major features. none to be thought of yet"
Freestyler
Freestyler
Did you add -direct3d support when compiling the libraries using configure from the MSVC console?

If so, are you using either "setAttribute(Qt::WA_MSWindowsUseDirect3D, true);" or running your .exe file also with the -direct3d switch, eg myfile.exe -direct3d

These are both required to stop the "flickering associated" as your paintEvent seems fine.
guqun
guqun
thanks very much.i have resolved the problem by using Qt::WA_MSWindowsUseDirect3D.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.