A few days ago, a DrawDib video correspondence library, although the picture is displayed very fast, but it is difficult to meet some interactive real-time display. And when zoomed out, it is impossible to set the anti-aliasing function (Antialias). I didn't want to With DirectX, it seems that now still flee. I hate something that is often changed in the interface, which hates Dongdong that needs to support dynamic link library. DirectX is like this, Direct1 to DirectX9, every new interface will Change, of course, the old interface is still available, but there is no calling method for the old interface. No way, Down has a DirectX9 hard scalp.
I have studied another SDK documentation in the afternoon, and there is almost the framework of the mind, which is approximately as follows:
Class MMD3DRENDER
{
protected:
IDirect3d9 * m_pd3d;
IDirect3ddevice9 * m_pdev;
IDirect3dsurface9 * m_psuf;
......
// make some Direct3D9 initialization work
BOOL INIT (HWND);
// Send the things in the buffer to Surface (M_PSUF)
Void Draw (Byte * PBuffer, Int ISTEP, LPRECT LPRC);
// WM_PAINT message processing
Void paint ();
/ / Release the resource, and exit after the work
Void destroy ();
}
Calling this render is very simple, as long as it is called in a WM_CREATE message response function of a Window object
Init (pwnd-> getsafehwnd ())
Then add its WM_Paint function plus
ValidateRect (null);
Render.paint ();
OK is OK.
So I built an MFC single view structure (there is no document (cdocument), inserted into the CChildView insert
Added the oncreate, the onpaint message handler, and inserted the code above, but it is not successful, it is init.
BOOL MMD3DRENDER :: Init (hwnd hwnd)
{
Assert (:: iswindow (hwnd));
m_pd3d = Direct3dcreate9 (D3D_SDK_VERSION);
IF (! m_pd3d)
Return False;
D3DPresent_Parameters D3DPP;
ZeromeMory (& D3DPP, SIZEOF (D3DPP));
D3DPP.Windowed = true;
D3dpp.swapeffect = D3DSWAPEFFECT_DISCARD;
D3dpp.backbufferformat = D3DFMT_UNKNOWN;
D3DPP.HDEVICEWINDOW = HWND;
HRESULT HR;
IF (FAILED (HR = M_PD3D-> CreateDevice (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, HWND, D3DCREATE_HARDWARE_VERTEXPROCESSING, & D3DP, & M_PDEV)))))
{
SAFE_RELEASE (M_PD3D);
AFXMessageBox (DxGetersRRORDESCRIPTION9 (HR));
Return False;
}
Return True;
}
The above code is almost exactly the same as the Tutorial in the SDK document, but my program is lost every time you go to CreateDevice. Depressed for a long time, you can't find the reason, run the example program in the SDK is good, then look at the SDK. to such a sentence:.. This method should not be run during the handling of WM_CREATE An application should never pass a window handle to Direct3D while handling WM_CREATE Any call to create, release, or reset the device must be done using the same thread as The window procedure of the focus window.
test! I am fainting, and there is such a restriction, I move the init code to the oncreate function of the VIEW's parent window CMAINFRAME, and then create a view immediately after IIT.
IF (! m_wndview.create (...))
...
g_render.init (m_wnd.getsafehwnd ());
This is the head, the test, it is still wrong after running! I changed it over again.
g_render.init (this-> getsafehwnd ());
Just incorporate the handle of CMAINFRAME, the result is successful, the entire window is painted in black, but it is only a piece of the tool bar, huh, huh.
I have thought about half a day, I don't know why, why cmainframe can, and in the WM_CREATE handler, this is still disabled by SDK. Will it be related to the initial size of the window? I noticed that the creation of M_WndView is set to CRECT (0, 0, 0, 0), and change it to:
IF (! m_wndview.create (null, null, afx_ws_default_view, crect (0, 0, 100, 100), this, afx_idw_pane_first, null)
FT, one running actually OK ~ put the init in the oncreate processing function of the View, and run it smoothly.
It seems that the Dongdong written in the SDK can not always believe, it should be changed:
Direct3D9 Creating a Window Related to DEVICE The initial size cannot be 0