Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int Init_DDraw(HWND hWnd)
- {
- int Rend;
- HRESULT rval;
- DDSURFACEDESC2 ddsd;
- int oldBits32 = Bits32;
- End_DDraw();
- if (Full_Screen) Rend = Render_FS;
- else Rend = Render_W;
- if (FAILED(DirectDrawCreate(NULL, &lpDD_Init, NULL)))
- return Init_Fail(hWnd, "Error with DirectDrawCreate !");
- if (FAILED(lpDD_Init->QueryInterface(IID_IDirectDraw4, (LPVOID *) &lpDD)))
- return Init_Fail(hWnd, "Error with QueryInterface !\nUpgrade your DirectX version.");
- lpDD_Init->Release();
- lpDD_Init = NULL;
- if (!(Mode_555 & 2))
- {
- memset(&ddsd, 0, sizeof(ddsd));
- ddsd.dwSize = sizeof(ddsd);
- lpDD->GetDisplayMode(&ddsd);
- if (ddsd.ddpfPixelFormat.dwGBitMask == 0x03E0) Mode_555 = 1;
- else Mode_555 = 0;
- Recalculate_Palettes();
- }
- #ifdef DISABLE_EXCLUSIVE_FULLSCREEN_LOCK
- FS_VSync = 0;
- rval = lpDD->SetCooperativeLevel(hWnd, DDSCL_NORMAL);
- #else
- if (Full_Screen)
- rval = lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
- else
- rval = lpDD->SetCooperativeLevel(hWnd, DDSCL_NORMAL);
- #endif
- if (FAILED(rval))
- return Init_Fail(hWnd, "Error with lpDD->SetCooperativeLevel !");
- if (Res_X < (320 << (int) (Render_FS > 0))) Res_X = 320 << (int) (Render_FS > 0); //Upth-Add - Set a floor for the resolution
- if (Res_Y < (240 << (int) (Render_FS > 0))) Res_Y = 240 << (int) (Render_FS > 0); //Upth-Add - 320x240 for single, 640x480 for double and other
- //if (Full_Screen && Render_FS >= 2) //Upth-Modif - Since software blits don't stretch right, we'll use 640x480 for those render modes
- // Modif N. removed the forced 640x480 case because it caused "windowed fullscreen mode" to be ignored and because I fixed the fullscreen software blit stretching
- if (Full_Screen && !(FS_No_Res_Change))
- {
- if (FAILED(lpDD->SetDisplayMode(Res_X, Res_Y, 16, 0, 0)))
- return Init_Fail(hWnd, "Error with lpDD->SetDisplayMode !");
- }
- memset(&ddsd, 0, sizeof(ddsd));
- ddsd.dwSize = sizeof(ddsd);
- if ((Full_Screen) && (FS_VSync))
- {
- ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
- ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
- ddsd.dwBackBufferCount = 2;
- }
- else
- {
- ddsd.dwFlags = DDSD_CAPS;
- ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
- }
- if (FAILED(lpDD->CreateSurface(&ddsd, &lpDDS_Primary, NULL )))
- return Init_Fail(hWnd, "Error with lpDD->CreateSurface !");
- if (Full_Screen)
- {
- if (FS_VSync)
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
- if (FAILED(lpDDS_Primary->GetAttachedSurface(&ddsd.ddsCaps, &lpDDS_Flip)))
- return Init_Fail(hWnd, "Error with lpDDPrimary->GetAttachedSurface !");
- lpDDS_Blit = lpDDS_Flip;
- }
- else lpDDS_Blit = lpDDS_Primary;
- }
- else
- {
- if (FAILED(lpDD->CreateClipper(0, &lpDDC_Clipper, NULL )))
- return Init_Fail(hWnd, "Error with lpDD->CreateClipper !");
- if (FAILED(lpDDC_Clipper->SetHWnd(0, hWnd)))
- return Init_Fail(hWnd, "Error with lpDDC_Clipper->SetHWnd !");
- if (FAILED(lpDDS_Primary->SetClipper(lpDDC_Clipper)))
- return Init_Fail(hWnd, "Error with lpDDS_Primary->SetClipper !");
- }
- memset(&ddsd, 0, sizeof(ddsd));
- ddsd.dwSize = sizeof(ddsd);
- ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
- if (Rend < 2)
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
- ddsd.dwWidth = 336;
- ddsd.dwHeight = 240;
- }
- else
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
- ddsd.dwWidth = 672; //Upth-Modif - was 640, but for single mode the value was 336, not 320.
- ddsd.dwHeight = 480;
- }
- if (FAILED(lpDD->CreateSurface(&ddsd, &lpDDS_Back, NULL)))
- return Init_Fail(hWnd, "Error with lpDD->CreateSurface !");
- if (!Full_Screen || (Rend >= 2 && (FS_No_Res_Change || Res_X != 640 || Res_Y != 480)))
- lpDDS_Blit = lpDDS_Back;
- if (Rend < 2)
- {
- memset(&ddsd, 0, sizeof(ddsd));
- ddsd.dwSize = sizeof(ddsd);
- if (FAILED(lpDDS_Back->GetSurfaceDesc(&ddsd)))
- return Init_Fail(hWnd, "Error with lpDD_Back->GetSurfaceDesc !");
- ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH | DDSD_LPSURFACE | DDSD_PIXELFORMAT;
- ddsd.dwWidth = 336;
- ddsd.dwHeight = 240;
- if (ddsd.ddpfPixelFormat.dwRGBBitCount > 16)
- {
- ddsd.lpSurface = &MD_Screen32[0];
- ddsd.lPitch = 336 * 4;
- }
- else
- {
- ddsd.lpSurface = &MD_Screen[0];
- ddsd.lPitch = 336 * 2;
- }
- if (FAILED(lpDDS_Back->SetSurfaceDesc(&ddsd, 0)))
- return Init_Fail(hWnd, "Error with lpDD_Back->SetSurfaceDesc !");
- }
- // make sure Bits32 is correct (which it could easily not be at this point)
- {
- memset(&ddsd, 0, sizeof(ddsd));
- ddsd.dwSize = sizeof(ddsd);
- if (FAILED(lpDDS_Blit->GetSurfaceDesc(&ddsd)))
- return Init_Fail(hWnd, "Error with lpDDS_Blit->GetSurfaceDesc !");
- Bits32 = (ddsd.ddpfPixelFormat.dwRGBBitCount > 16) ? 1 : 0;
- // also prevent the colors from sometimes being messed up for 1 frame if we changed color depth
- if(Bits32 && !oldBits32)
- for(int i = 0 ; i < 336 * 240 ; i++)
- MD_Screen32[i] = DrawUtil::Pix16To32(MD_Screen[i]);
- if(!Bits32 && oldBits32)
- for(int i = 0 ; i < 336 * 240 ; i++)
- MD_Screen[i] = DrawUtil::Pix32To16(MD_Screen32[i]);
- }
- // make sure the render mode is still valid (changing options in a certain order can make it invalid at this point)
- Set_Render(hWnd, Full_Screen, -1, false);
- // make sure the menu reflects the current mode (which it generally won't yet if we changed to/from 32-bit mode in this function)
- Build_Main_Menu();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement