Whoops - seems that I teared the source .... one more try ...
Hello,
I''m just trying to get into directx programming and I ''ve a problem width initalizing the PrimarySurface under Windows 2000.
There are no compile errors but I can''t clear the PrimarySurface (trying to make it black).
Here''s the code I use to create a complex surface (PrimarySurface with one BackSurface) :
int InitDirectX() { HRESULT ddrval; // Rückgabewert ddrval = DirectDrawCreateEx(NULL, (LPVOID *)&lpDD, IID_IDirectDraw7, NULL); if (ddrval != DD_OK) { MessageBox(hWnd, "DDraw Fehler: DirectDrawCreateEx()", "DDRAW ERROR", MB_OK); return(-1); } ddrval = lpDD->SetCooperativeLevel(hWnd, DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT ); if (ddrval != DD_OK) { MessageBox(hWnd, "DDraw Fehler: SetCooperativeLevel()", "DDRAW ERROR", MB_OK); return(-1); } ddrval = lpDD->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, 0, 0); if (ddrval != DD_OK) return(-1); // create Complex Surface ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; ddrval = lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL); if (ddrval != DD_OK) { MessageBox(hWnd, "DDraw Error: CreateSurface()", "DDRAW ERROR", MB_OK); return(-1); } ZeroMemory(&ddscaps, sizeof(ddscaps)); ddscaps.dwCaps = DDSCAPS_BACKBUFFER; ddrval = lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack); if (ddrval != DD_OK) { MessageBox(hWnd, "DDraw Error: GetAttachedSurface()", "DDRAW ERROR", MB_OK); return(-1); } return(1);}
And here is my routine to clean the surfaces:
bool ClearSurface(LPDIRECTDRAWSURFACE7 lpDDSurf, UCHAR Farbe) { HRESULT ddrval; DDBLTFX ddBltFx; ZeroMemory(&ddBltFx, sizeof(DDBLTFX)); ddBltFx.dwSize = sizeof(DDBLTFX); ddBltFx.dwFillColor = Farbe; ddrval = lpDDSurf->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddBltFx); if (ddrval != DD_OK) { MessageBox(hWnd, "DDraw Error: ClearSurface()","DDRAW ERROR", MB_OK); return(false); } return(true);}
The Back Surface I can clear an set to black color by using ClearSurface(lpDDSBack, 0) - but that''s not working with the Primary Surface.
Under Windows 98 it works fine. I only have problem under Windows 2000.
What can I do to fix this ???