Solution to the backbuffer problem of DirectDraw on WM Simulator

Source: Internet
Author: User

The program failed to run because ddscaps_backbuffer is not supported when the simulator ran to create a backup buffer, google found that some people on the M $ website and other forums have asked similar questions. The answer seems to be that the emlator cannot run ddraw or d3d programs. To test, only device is used, as a matter of fact, you only need to create a backup buffer and simulate flip with bits to run on the simulator. It is not because the simulator has not implemented ddraw at all, I just didn't implement hardware backup buffering, flip, and other operations (in fact, there should be no efficiency difference between the two methods on the current PC simulator ).

// *********************************** <Br //> // method: initddraw initialize ddraw <br/> // fullname: initddraw <br/> // access: Public <br/> // returns: bool <br/> // qualifier: <br/> // parameter: void <br/> //********************************* * ** <br/> bool initddraw (void) <br/>{< br/> ddsurfacedesc ddsd; <br/> hresult HRET; <br/> ddcaps ddhelcaps; <br/> // ddraw object <br/> HRET = directdrawcreate (Null, & g_pdd, null); <br/> If (HRET! = Dd_ OK) <br/>{< br/> initfail (g_hgamewnd, HRET, _ T ("ddraw failed to create! "); <Br/> return false; <br/>}< br/> // full-screen exclusive mode <br/> HRET = g_pdd-> setcooperativelevel (g_hgamewnd, ddscl_fullscreen); <br/> If (HRET! = Dd_ OK) <br/>{< br/> initfail (g_hgamewnd, HRET, _ T ("failed to set cooperative level! "); <Br/> return false; <br/>}< br/> // get ddraw availability <br/> g_pdd-> getcaps (& ddcaps, & ddhelcaps); <br/> // If (! (Ddcaps. ddscaps. dwcaps & ddscaps_backbuffer) |! (Ddcaps. ddscaps. dwcaps & ddscaps_flip) <br/>{< br/> // single buffer mode <br/> g_bsinglebuffer = true; <br/>}< br/> // Display Mode settings <br/> memset (& ddsd, 0, sizeof (ddsd); <br/> ddsd. dwsize = sizeof (ddsd); </P> <p> HRET = g_pdd-> getdisplaymode (& ddsd); </P> <p> If (HRET! = Dd_ OK) <br/>{< br/> initfail (g_hgamewnd, HRET, _ T ("getdisplaymode failed! "); <Br/> return false; <br/>}</P> <p> g_dwscreenx = ddsd. dwwidth; <br/> g_dwscreeny = ddsd. dwheight; <br/> g_dwscreenbpp = ddsd. ddpfpixelformat. dwrgbbitcount; </P> <p> // Color Key hardware capability <br/> g_dwtranstype = ddblt_keysrc; <br/> ddcaps. dwsize = sizeof (ddcaps); <br/> If (g_bsinglebuffer) <br/>{< br/> ddsd. dwflags = ddsd_caps; <br/> ddsd. ddscaps. dwcaps = ddscaps_primarysurface; <br/>}< br/> else <br/>{< br/> ddsd. d Wflags = ddsd_caps | ddsd_backbuffercount; <br/> ddsd. ddscaps. dwcaps = ddscaps_primarysurface | ddscaps_flip; <br/> ddsd. dwbackbuffercount = 1; <br/>}< br/> // primary buffer creation <br/> HRET = g_pdd-> createsurface (& ddsd, & g_pddsprimary, null ); </P> <p> If (HRET! = Dd_ OK) <br/>{< br/> If (HRET = dderr_nofliphw) <br/>{< br/> initfail (g_hgamewnd, HRET, _ T ("********* display driver doesn' t support flipping surfaces. * ******* "); <br/> return false; <br/>}< br/> initfail (g_hgamewnd, HRET, _ T ("createsurface frontbuffer failed! "); <Br/> return false; <br/>}</P> <p> If (g_bsinglebuffer) <br/>{< br/> ddsd. dwflags = ddsd_width | ddsd_height; <br/> ddsd. dwwidth = g_dwscreenx; <br/> ddsd. dwheight = g_dwscreeny; <br/> HRET = g_pdd-> createsurface (& ddsd, & g_pddsback, null); <br/> If (HRET! = Dd_ OK) <br/>{< br/> initfail (g_hgamewnd, HRET, _ T ("backbuffer failed to create! "); <Br/> return false; <br/>}< br/> else <br/> {<br/> // get a pointer to the back buffer <br/> HRET = g_pddsprimary -> enumattachedsurfaces (& g_pddsback, enumfunction); <br/> If (HRET! = Dd_ OK) <br/>{< br/> initfail (g_hgamewnd, HRET, _ T ("enumattachedsurfaces failed! "); <Br/> return false; <br/>}< br/> return true; <br/>}</P> <p>

In the drawing loop, handle flip as follows:

Hresult ddrval; <br/> rect SRC, DEST; </P> <p> SRC. left = 0; <br/> SRC. top = 0; <br/> SRC. right = g_dwscreenx; <br/> SRC. bottom = g_dwscreeny; </P> <p> DeST. left = 0; <br/> DeST. top = 0; <br/> DeST. right = g_dwscreenx; <br/> DeST. bottom = g_dwscreeny; </P> <p> // flip the surfaces <br/> while (1) <br/>{< br/> If (g_bsinglebuffer) <br/> {<br/> // copy back buffer to front. <br/> ddrval = g_pddsprimary-> BLT (& DEST, g_pdd Sback, & SRC, ddblt_waitnotbusy, null); <br/>}< br/> else <br/>{< br/> ddrval = g_pddsprimary-> flip (null, 0); <br/>}</P> <p> If (ddrval = dd_ OK) <br/>{< br/> break; <br/>}< br/> If (ddrval = dderr_surfacelost) <br/>{< br/> If (! Restoresurfaces () <br/>{< br/> return 0; <br/>}< br/> If (ddrval! = Dderr_wasstilldrawing) <br/>{< br/> break; <br/>}</P> <p>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.