Jump to content
  • Advertisement
Sign in to follow this  
JPSerna

MFC and DirectX help

This topic is 3795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!