| 41 | #define DDCHECK(x) { if ( !(x) ) BWAPIError(GetLastError(), "\"" #x "\" failed on %s:%u.", __FILE__, __LINE__); } |
| 42 | |
| 43 | void DDrawInitialize(int width, int height) |
| 44 | { |
| 45 | #ifndef SHADOW_BROODWAR |
| 46 | if ( !ghMainWnd || wmode ) |
| 47 | return; |
| 48 | |
| 49 | // Initialize module |
| 50 | ShowWindow(ghMainWnd, SW_NORMAL); |
| 51 | if ( !ddLib ) |
| 52 | { |
| 53 | ddLib = LoadLibraryA("ddraw.dll"); |
| 54 | DDCHECK(ddLib); |
| 55 | } |
| 56 | |
| 57 | // Obtain function DirectDrawCreate |
| 58 | HRESULT (WINAPI *_DirectDrawCreate)(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnknown FAR* pUnkOuter); |
| 59 | (FARPROC&)_DirectDrawCreate = GetProcAddress(ddLib, "DirectDrawCreate"); |
| 60 | DDCHECK(_DirectDrawCreate); |
| 61 | |
| 62 | // Create and initialize DirectDrawInterface |
| 63 | DDCHECK( _DirectDrawCreate(NULL, &BW::BWDATA::DDInterface, NULL) == DD_OK ); |
| 64 | DDCHECK( BW::BWDATA::DDInterface->SetCooperativeLevel(ghMainWnd, DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE) == DD_OK ); |
| 65 | if ( BW::BWDATA::DDInterface->SetDisplayMode(width, height, 32) != DD_OK ) |
| 66 | DDCHECK( BW::BWDATA::DDInterface->SetDisplayMode(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), 32) == DD_OK ); |
| 67 | |
| 68 | // Create DirectDrawPalette |
| 69 | DDCHECK( BW::BWDATA::DDInterface->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256, BW::BWDATA::GamePalette.data(), &BW::BWDATA::PrimaryPalette, NULL) == DD_OK ); |
| 70 | |
| 71 | DDSURFACEDESC surfaceDesc = { 0 }; |
| 72 | surfaceDesc.dwSize = sizeof(DDSURFACEDESC); |
| 73 | surfaceDesc.dwFlags = DDSD_CAPS; |
| 74 | surfaceDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; |
| 75 | |
| 76 | DDCHECK( BW::BWDATA::DDInterface->CreateSurface(&surfaceDesc, &BW::BWDATA::PrimarySurface, NULL) == DD_OK ); |
| 77 | DDCHECK( BW::BWDATA::PrimarySurface->SetPalette(BW::BWDATA::PrimaryPalette) == DD_OK ); |
| 78 | if ( BW::BWDATA::PrimarySurface->Lock(NULL, &surfaceDesc, DDLOCK_WAIT, NULL) != DD_OK ) |
| 79 | { |
| 80 | memset(&surfaceDesc, 0, sizeof(DDSURFACEDESC)); |
| 81 | surfaceDesc.dwSize = sizeof(DDSURFACEDESC); |
| 82 | surfaceDesc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; |
| 83 | surfaceDesc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN; |
| 84 | surfaceDesc.dwWidth = width; |
| 85 | surfaceDesc.dwHeight = height; |
| 86 | |
| 87 | DDCHECK( BW::BWDATA::DDInterface->CreateSurface(&surfaceDesc, &BW::BWDATA::BackSurface, NULL) == DD_OK ); |
| 88 | } |
| 89 | else |
| 90 | { |
| 91 | BW::BWDATA::PrimarySurface->Unlock(&surfaceDesc); |
| 92 | } |
| 93 | SDrawManualInitialize(ghMainWnd, BW::BWDATA::DDInterface, BW::BWDATA::PrimarySurface, NULL, NULL, BW::BWDATA::BackSurface, BW::BWDATA::PrimaryPalette, NULL); |
| 94 | #endif |
| 95 | } |
| 96 | #undef DDCHECK |