Sign in to follow this  
JPSerna

MFC and DirectX help

Recommended Posts

JPSerna    122
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?

Share this post


Link to post
Share on other sites
stringa    100
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...

Share this post


Link to post
Share on other sites
MJP    19753
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]

Share this post


Link to post
Share on other sites
JPSerna    122
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this