Updatesurface is a function in directd3d9.0. When I learn to draw an image to the window today, there is always a problem.
I have solved the problem later, and I will summarize it here.
What you want to do is to load an image (mmimage) and display it.
Steps:
1. Create DX objects
2. Load the image to the memory.
D3dximage_info imageinfo; <br/> hR = d3dxgetimageinfofromfile (l "d: // mm // 1.jpg", & imageinfo); <br/> If (failed (HR )) <br/>{< br/> return false; <br/>}< br/> hR = device-> createoffscreenplainsurface (imageinfo. width, <br/> imageinfo. height, <br/> d3dfmt_a8r8g8b8, <br/> d3dpool_systemmem, <br/> & g_psurface, <br/> null); <br/> If (failed (HR )) <br/>{< br/> return false; <br/>}< br/> hR = d3dxloadsurfacefromfile (g_psurface, <br/> null, <br/> null, <br/> L "d: // mm // 1.jpg", <br/> null, <br/> d3dx_filter_none, <br/> 0, <br/> null ); <br/> If (failed (HR) <br/>{< br/> return false; <br/>}
3. Copy the image surface content to backbuffer.
Hresult hR = device-> getbackbuffer (null, 0, d3dbackbuffer_type_mono, & pbackbuffer); <br/> If (failed (HR )) <br/>{< br/> return false; <br/>}< br/> hR = device-> updatesurface (g_psurface, null, pbackbuffer, null ); <br/> If (failed (HR) <br/>{< br/> return false; <br/>}
If the result cannot be drawn, I will go to msdn and find the prompt in msdn:
This function has the following restrictions.
- The source surface must have been created with d3dpool_systemmem.
- The destination surface must have been created with d3dpool_default.
- Neither surface can be locked or holding an outstanding device context.
- Neither surface can be created with multisampling. the only valid flag for both surfaces is d3dmultisample_none.
- The surface format cannot be a depth stencel format.
- The source and DEST rects must fit within the surface.
- No stretching or shrinking is allowed (the rects must be the same size ).
- The source format must match the Dest format.
In short, the requirements are very strict ..
After the check, the following two items are not met.
- No stretching or shrinking is allowed (the rects must be the same size ).
- The source format must match the Dest format.
The first requirement is that the target surface has enough space to "accommodate" The rect submitted by the source surface.
Updatesurface has four parameters, two of which are source and target surface pointers. The other two are source rectangles of the source surface (marked as rectsrc ),
The other is the starting point for drawing the target surface (in the upper left corner). The original size rectangle of This vertex and the target surface forms a rectangle (marked as rectdes ).
In this way, we have two rectangles, rectsrc and rectdes, as long as the width and height of rectsrc are smaller than rectdes. In fact, it is to ensure that the target rectangle can draw the source rectangle.
Second, set the source surface format to the target surface format.
Beautiful pictures can be displayed.
PP: