From: FGSFDSFGS Date: Wed, 6 Apr 2016 18:40:20 +0000 (+0300) Subject: fixed some bugs X-Git-Url: http://deadsoftware.ru/gitweb?p=d2df-sdl.git;a=commitdiff_plain;h=a2e293a0411a842370664272697718994adbf3df fixed some bugs --- diff --git a/src/game/g_window.pas b/src/game/g_window.pas index d4cd928..a41c9f4 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -68,14 +68,13 @@ begin end; function g_Window_SetDisplay(PreserveGL: Boolean = False): Boolean; +var + mode, cmode: TSDL_DisplayMode; begin Result := False; e_WriteLog('Setting display mode...', MSG_NOTIFY); - // if wWindowCreated and PreserveGL then - // e_SaveGLContext(); // we need this and restore because of a bug in SDL1.2, apparently - wFlags := SDL_WINDOW_OPENGL or SDL_WINDOW_RESIZABLE; if gFullscreen then wFlags := wFlags or SDL_WINDOW_FULLSCREEN; if gWinMaximized then wFlags := wFlags or SDL_WINDOW_MAXIMIZED; @@ -85,6 +84,25 @@ begin SDL_DestroyWindow(h_Wnd); h_Wnd := nil; end; + + if gFullscreen then + begin + mode.w := gScreenWidth; + mode.h := gScreenHeight; + mode.format := 0; + mode.refresh_rate := 0; + mode.driverdata := nil; + if SDL_GetClosestDisplayMode(0, @mode, @cmode) = nil then + begin + gScreenWidth := 800; + gScreenHeight := 600; + end + else + begin + gScreenWidth := cmode.w; + gScreenHeight := cmode.h; + end; + end; h_Wnd := SDL_CreateWindow(PChar(wTitle), gWinRealPosX, gWinRealPosY, gScreenWidth, gScreenHeight, wFlags); if h_Wnd = nil then Exit; @@ -92,9 +110,6 @@ begin SDL_GL_MakeCurrent(h_Wnd, h_GL); SDL_ShowCursor(SDL_DISABLE); - // if wWindowCreated and PreserveGL then - // e_RestoreGLContext(); - Result := True; end; @@ -106,20 +121,25 @@ end; function GetDisplayModes(dBPP: DWORD; var SelRes: DWORD): SArray; var mode: TSDL_DisplayMode; - res, i, k: Integer; + res, i, k, n, pw, ph: Integer; begin SetLength(Result, 0); - k := 0; - for i := 0 to SDL_GetNumDisplayModes(0) do + k := 0; SelRes := 0; + n := SDL_GetNumDisplayModes(0); + pw := 0; ph := 0; + for i := 0 to n do begin res := SDL_GetDisplayMode(0, i, @mode); if res < 0 then continue; + if SDL_BITSPERPIXEL(mode.format) = gBPP then continue; + if (mode.w = pw) and (mode.h = ph) then continue; if (mode.w = gScreenWidth) and (mode.h = gScreenHeight) then SelRes := k; Inc(k); SetLength(Result, k); Result[k-1] := IntToStr(mode.w) + 'x' + IntToStr(mode.h); + pw := mode.w; ph := mode.h end; e_WriteLog('SDL: Got ' + IntToStr(k) + ' resolutions.', MSG_NOTIFY); diff --git a/src/lib/sdl2/sdl2.pas b/src/lib/sdl2/sdl2.pas index 92f71d9..4f1dfca 100644 --- a/src/lib/sdl2/sdl2.pas +++ b/src/lib/sdl2/sdl2.pas @@ -341,29 +341,29 @@ end; //from "sdl_pixels.h" -function SDL_PIXELFLAG(X: Cardinal): Boolean; +function SDL_PIXELFLAG(X: Cardinal): Cardinal; begin - Result := (X shr 28) = $0F; + Result := (X shr 28) and $0F; end; -function SDL_PIXELTYPE(X: Cardinal): Boolean; +function SDL_PIXELTYPE(X: Cardinal): Cardinal; begin - Result := (X shr 24) = $0F; + Result := (X shr 24) and $0F; end; -function SDL_PIXELORDER(X: Cardinal): Boolean; +function SDL_PIXELORDER(X: Cardinal): Cardinal; begin - Result := (X shr 20) = $0F; + Result := (X shr 20) and $0F; end; -function SDL_PIXELLAYOUT(X: Cardinal): Boolean; +function SDL_PIXELLAYOUT(X: Cardinal): Cardinal; begin - Result := (X shr 16) = $0F; + Result := (X shr 16) and $0F; end; -function SDL_BITSPERPIXEL(X: Cardinal): Boolean; +function SDL_BITSPERPIXEL(X: Cardinal): Cardinal; begin - Result := (X shr 8) = $FF; + Result := (X shr 8) and $FF; end; function SDL_IsPixelFormat_FOURCC(format: Variant): Boolean; diff --git a/src/lib/sdl2/sdlpixels.inc b/src/lib/sdl2/sdlpixels.inc index fc6aad3..d97f165 100644 --- a/src/lib/sdl2/sdlpixels.inc +++ b/src/lib/sdl2/sdlpixels.inc @@ -72,11 +72,11 @@ function SDL_DEFINE_PIXELFOURCC(A,B,C,D: Variant): Variant; ((bits) << 8) | ((bytes) << 0)) } -function SDL_PIXELFLAG(X: Cardinal): Boolean; -function SDL_PIXELTYPE(X: Cardinal): Boolean; -function SDL_PIXELORDER(X: Cardinal): Boolean; -function SDL_PIXELLAYOUT(X: Cardinal): Boolean; -function SDL_BITSPERPIXEL(X: Cardinal): Boolean; +function SDL_PIXELFLAG(X: Cardinal): Cardinal; +function SDL_PIXELTYPE(X: Cardinal): Cardinal; +function SDL_PIXELORDER(X: Cardinal): Cardinal; +function SDL_PIXELLAYOUT(X: Cardinal): Cardinal; +function SDL_BITSPERPIXEL(X: Cardinal): Cardinal; { #define SDL_BYTESPERPIXEL(X) \ (SDL_ISPIXELFORMAT_FOURCC(X) ? \