summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 785fe3d)
raw | patch | inline | side by side (parent: 785fe3d)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Tue, 6 Feb 2018 20:11:55 +0000 (22:11 +0200) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Tue, 6 Feb 2018 20:42:26 +0000 (22:42 +0200) |
changing to fullscreen is not working right, 'cause we need to
recreate OpenGL context (and reupload all textures). without this,
fullscreen window is created with fucked size for some reason.
recreate OpenGL context (and reupload all textures). without this,
fullscreen window is created with fucked size for some reason.
src/game/g_game.pas | patch | blob | history | |
src/game/g_window.pas | patch | blob | history |
diff --git a/src/game/g_game.pas b/src/game/g_game.pas
index 8e7174f31b8fd4cceea472c5fa66695c498cd220..918a94714df9f810469a5204a8e83d817fac5074 100644 (file)
--- a/src/game/g_game.pas
+++ b/src/game/g_game.pas
e_WriteLog('Changing resolution', TMsgType.Notify);
g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
gResolutionChange := False;
+ g_ActiveWindow := nil;
end;
// Íóæíî ñìåíèòü ÿçûê:
g_PlayerModel_FreeData();
g_Texture_DeleteAll();
g_Frames_DeleteAll();
- g_Menu_Free();
+ //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
if NetInitDone then g_Net_Free;
diff --git a/src/game/g_window.pas b/src/game/g_window.pas
index 3dbd62055888d83b5162d569937f09c9e36d3ad0..a40441b492a7d6fee0db0eb2a6c206aafb031e3f 100644 (file)
--- a/src/game/g_window.pas
+++ b/src/game/g_window.pas
function SDLMain (): Integer;
function GetTimer (): Int64;
procedure ResetTimer ();
-function CreateGLWindow (Title: PChar): Boolean;
-procedure KillGLWindow ();
procedure PushExitEvent ();
function ProcessMessage (): Boolean;
procedure ReDrawWindow ();
{$ENDIF}
-procedure KillGLWindow ();
+procedure KillGLWindow (preserveGL: Boolean);
begin
- if (h_GL <> nil) then begin if (assigned(oglDeinitCB)) then oglDeinitCB(); end;
+ if (h_GL <> nil) and (not preserveGL) then begin if (assigned(oglDeinitCB)) then oglDeinitCB(); end;
if (h_Wnd <> nil) then SDL_DestroyWindow(h_Wnd);
- if (h_GL <> nil) then SDL_GL_DeleteContext(h_GL);
+ if (h_GL <> nil) and (not preserveGL) then SDL_GL_DeleteContext(h_GL);
h_Wnd := nil;
- h_GL := nil;
+ if (not preserveGL) then h_GL := nil;
end;
var
mode, cmode: TSDL_DisplayMode;
wFlags: LongWord = 0;
+ nw, nh: Integer;
{$ENDIF}
begin
{$IF not DEFINED(HEADLESS)}
e_WriteLog('Setting display mode...', TMsgType.Notify);
- 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;
-
- KillGLWindow();
+ wFlags := SDL_WINDOW_OPENGL; // or SDL_WINDOW_RESIZABLE;
+ if gFullscreen then wFlags := wFlags or SDL_WINDOW_FULLSCREEN or SDL_WINDOW_BORDERLESS else wFlags := wFlags or SDL_WINDOW_RESIZABLE;
+ //if gWinMaximized then wFlags := wFlags or SDL_WINDOW_MAXIMIZED;
if gFullscreen then
begin
mode.driverdata := nil;
if (SDL_GetClosestDisplayMode(0, @mode, @cmode) = nil) then
begin
+ e_WriteLog('SDL: cannot find display mode for '+IntToStr(gScreenWidth), TMsgType.Notify);
gScreenWidth := 800;
gScreenHeight := 600;
end
else
begin
+ e_WriteLog('SDL: found display mode for '+IntToStr(gScreenWidth)+'x'+IntToStr(gScreenHeight)+': '+IntToStr(cmode.w)+'x'+IntToStr(cmode.h), TMsgType.Notify);
gScreenWidth := cmode.w;
gScreenHeight := cmode.h;
end;
end;
+ KillGLWindow(preserveGL);
+
h_Wnd := SDL_CreateWindow(PChar(wTitle), gWinRealPosX, gWinRealPosY, gScreenWidth, gScreenHeight, wFlags);
if (h_Wnd = nil) then exit;
SDL_GL_MakeCurrent(h_Wnd, h_GL);
SDL_ShowCursor(SDL_DISABLE);
+ if (gFullscreen) then
+ begin
+ nw := 0;
+ nh := 0;
+ SDL_GetWindowSize(h_Wnd, @nw, @nh);
+ if (nw > 128) and (nh > 128) then
+ begin
+ e_WriteLog('SDL: fullscreen window got size '+IntToStr(nw)+'x'+IntToStr(nh)+': '+IntToStr(gScreenWidth)+'x'+IntToStr(gScreenHeight), TMsgType.Notify);
+ gScreenWidth := nw;
+ gScreenHeight := nh;
+ end
+ else
+ begin
+ e_WriteLog('SDL: fullscreen window got invalid size: '+IntToStr(nw)+'x'+IntToStr(nh), TMsgType.Notify);
+ end;
+ end;
fuiScrWdt := gScreenWidth;
fuiScrHgt := gScreenHeight;
- if (h_GL <> nil) then begin if (assigned(oglInitCB)) then oglInitCB(); end;
+ if (h_GL <> nil) and (not preserveGL) then begin if (assigned(oglInitCB)) then oglInitCB(); end;
{$ENDIF}
result := true;
if (gScreenWidth <> w) or (gScreenHeight <> h) then
begin
result := true;
+ preserve := true;
gScreenWidth := w;
gScreenHeight := h;
end;
if (gFullscreen <> fullscreen) then
begin
result := true;
+ preserve := true;
gFullscreen := fullscreen;
preserve := true;
end;
if not g_Window_SetDisplay() then
begin
- KillGLWindow();
+ KillGLWindow(false);
e_WriteLog('Window creation error (resolution not supported?)', TMsgType.Fatal);
exit;
end;
{$IF not DEFINED(HEADLESS)}
- h_Gl := SDL_GL_CreateContext(h_Wnd);
- if (h_Gl = nil) then exit;
+ h_GL := SDL_GL_CreateContext(h_Wnd);
+ if (h_GL = nil) then exit;
fuiScrWdt := gScreenWidth;
fuiScrHgt := gScreenHeight;
if (assigned(oglInitCB)) then oglInitCB();
while not ProcessMessage() do begin end;
Release();
- KillGLWindow();
+ KillGLWindow(false);
result := 0;
end;