Hi,
I'm working under creation a simple game. Coding in c++ MSVS2008. I use IDirectDraw interface to render graphics. The concept is simple: initialize IDirectDraw interface, set cooperation level (full screen), set resolution (1024x768), create primary and secondary surfaces (with flip capability) and create sprite surface, which contain frames. Everything works fine, but the sprite surface. When i create sprite surface and try Lock() it, the method returns DDERR_INVALIDPARAMS; when i try calling BltFast() for sprite surface, it returns DDERR_SURFACEBUSY error, like it is blocked by another thread (but all operations are carried in single thread). Probably, i passed wrong parameters when created sprite surface. Here is the code of creation primary, secondary, sprite surface and blit operation:
| BOOL CDirectDraw::CreatePrimarySurf() |
| { |
| strsurf.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; |
| strsurf.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; |
| strsurf.dwBackBufferCount = 1; |
| rezult = lpDD->CreateSurface(&strsurf,&PrimarySurf,NULL); |
| if (rezult != DD_OK) |
| { |
| return rezult; |
| } |
| return TRUE; |
| } |
| //CREATE SECODARY SURFACE |
| BOOL CDirectDraw::GetSecondarySurf() |
| { |
| strsurfsec.dwCaps = DDSCAPS_BACKBUFFER; |
| if (PrimarySurf->GetAttachedSurface(&strsurfsec,&SecondarySurf)!= DD_OK) return FALSE; |
| return TRUE; |
| } |
| |
| BOOL CDirectDraw::Flips() |
| { |
| if (PrimarySurf->Flip(NULL,DDFLIP_WAIT) != DD_OK) return FALSE; |
| return TRUE; |
}
| //CREATE OFF-SCREEN SURFACE |
| LPDIRECTDRAWSURFACE* CDirectDraw::CreateSurface(int width, int height) |
| { |
| DDSURFACEDESC srfdesc; |
| memset(&srfdesc, 0, sizeof(DDSURFACEDESC)); |
| srfdesc.dwSize = sizeof(DDSURFACEDESC); |
| srfdesc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH; |
| srfdesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN ; |
| srfdesc.dwHeight = 100; |
| srfdesc.dwWidth = 100; |
| rezult = lpDD->CreateSurface(&srfdesc, &spriteSurf, NULL) ; |
| DDSURFACEDESC desc; |
| //rezult = spriteSurf->Lock(NULL, &desc, DDLOCK_WAIT, 0); |
| //assert(rezult!=DDERR_INVALIDPARAMS); THIS COMMENTED CODE RESULTS IN ERROR! |
| //spriteSurf->Unlock(0); |
| if(rezult!=DD_OK) return NULL; |
| return &spriteSurf; |
}
//RENDERING SPRITE SURFACE AREA TO SECONDARY SURFACE
| BOOL CDirectDraw::CopySurface(LPDIRECTDRAWSURFACE SurfSource,LPRECT lpRect, LPDIRECTDRAWSURFACE SurfDest, int x, int y) |
| { |
| HRESULT hresult; |
| hresult = SurfDest->BltFast(x, y, SurfSource, lpRect, DDBLTFAST_NOCOLORKEY + DDBLTFAST_WAIT); |
| assert(hresult!=DDERR_SURFACEBUSY); |
| if (hresult!=DD_OK) |
| { |
| return FALSE; |
| } |
| return TRUE; |
| } |
|
|
What may cause error?
P.S. i was sent here from msdn forum. They told i may get proper answer here