MFC and DirectX help
I'm making a level editor for a student project using Visual Studio 2k5 and MFC.
The problem is that my Direct 3D device isn't being created right when I initialize the renderer class.
I pass in the window handle to the view class of the project, but I get the error D3DERR_INVALIDCALL.
If necessary, I'll post some source, but does anyone have any idea why this might be?
Unfortunately D3DERR_INVALIDCALL is pretty generic and doesn't tell us much. Most likely some of your parameters are wrong. I would try using the debug runtime, and see if that gives you some information.
I agree, probably something in your params. I use that same set up all the time with no problems... Go ahead and post your D3Ddevice code and lets have a look.
Mucho
How can I create a game loop with MFC ?
In win32, I would use PeekMessage over GetMessage and then Run a render() function right after it. How can I do that with MFC ?
Thanks...
In win32, I would use PeekMessage over GetMessage and then Run a render() function right after it. How can I do that with MFC ?
Thanks...
Quote:Original post by stringa
How can I create a game loop with MFC ?
In win32, I would use PeekMessage over GetMessage and then Run a render() function right after it. How can I do that with MFC ?
Thanks...
You should be able to overide OnIdle() and have that call your render() function. Or alternately you could have OnIdle() call InvalidateRect(), and put your render() function in OnPaint(). However I know very little of MFC and have never combined D3D with MFC, so if this doesn't work then it's not my fault. [smile]
And another way to do it is to use the CTimer class in your main dialog class and check for WM_ON_TIMER.
BOOL CLevelEditorMFCView::InitialzeDirect3D(HWND hWnd, int nScreenWidth, int nScreenHeight, bool bWindowed)
{
m_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
if(!m_pD3D)
return FALSE;
m_d3dpp.BackBufferWidth = nScreenWidth;
m_d3dpp.BackBufferHeight = nScreenHeight;
m_d3dpp.Windowed = bWindowed;
m_d3dpp.BackBufferFormat = bWindowed ? D3DFMT_UNKNOWN : D3DFMT_R5G6B5;
m_d3dpp.BackBufferCount = 1;
m_d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
m_d3dpp.MultiSampleQuality = 0;
m_d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
m_d3dpp.hDeviceWindow = m_hWnd;
m_d3dpp.EnableAutoDepthStencil = TRUE;
m_d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8/*D3DFMT_D16*/;
m_d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
m_d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
HRESULT hr = m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING, &m_d3dpp, &m_pDevice);
return TRUE;
}
That's the setup where the device is created.
Oh, and the hWnd variable is passed in from GetSafeHwnd.
And m_pDevice starts off null.
{
m_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
if(!m_pD3D)
return FALSE;
m_d3dpp.BackBufferWidth = nScreenWidth;
m_d3dpp.BackBufferHeight = nScreenHeight;
m_d3dpp.Windowed = bWindowed;
m_d3dpp.BackBufferFormat = bWindowed ? D3DFMT_UNKNOWN : D3DFMT_R5G6B5;
m_d3dpp.BackBufferCount = 1;
m_d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
m_d3dpp.MultiSampleQuality = 0;
m_d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
m_d3dpp.hDeviceWindow = m_hWnd;
m_d3dpp.EnableAutoDepthStencil = TRUE;
m_d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8/*D3DFMT_D16*/;
m_d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
m_d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
HRESULT hr = m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING, &m_d3dpp, &m_pDevice);
return TRUE;
}
That's the setup where the device is created.
Oh, and the hWnd variable is passed in from GetSafeHwnd.
And m_pDevice starts off null.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement