DEADSOFTWARE

sdl1/2: fix invalid window title
[d2df-sdl.git] / src / game / sdl / g_system.pas
index bba2caea3efb5b0c8fba366594002bec6f6057ed..0df28dc724dc5b391f37dc85b7a8373a12070727 100644 (file)
@@ -70,6 +70,28 @@ implementation
 
   (* --------- Graphics --------- *)
 
+  function LoadGL: Boolean;
+  begin
+    result := true;
+    {$IFDEF NOGL_INIT}
+    nogl_Init;
+    if glRenderToFBO and (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) then
+    {$ELSE}
+    if glRenderToFBO and (not Load_GL_ARB_framebuffer_object) then
+    {$ENDIF}
+    begin
+      e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
+      glRenderToFBO := false;
+    end;
+  end;
+
+  procedure FreeGL;
+  begin
+    {$IFDEF NOGL_INIT}
+    nogl_Quit();
+    {$ENDIF}
+  end;
+
   procedure UpdateSize (w, h: Integer);
   begin
     gWinSizeX := w;
@@ -81,7 +103,13 @@ implementation
       // store real window size in gWinSize, downscale resolution now
       w := round(w / r_pixel_scale);
       h := round(h / r_pixel_scale);
-      e_ResizeFramebuffer(w, h);
+      if not e_ResizeFramebuffer(w, h) then
+      begin
+        e_LogWriteln('GL: could not create framebuffer, falling back to --no-fbo');
+        glRenderToFBO := False;
+        w := gWinSizeX;
+        h := gWinSizeY;
+      end;
     end;
     gScreenWidth := w;
     gScreenHeight := h;
@@ -96,17 +124,17 @@ implementation
     g_Game_ClearLoading;
   end;
 
-  function GetTitle (): PChar;
+  function GetTitle (): AnsiString;
     var info: AnsiString;
   begin
     info := g_GetBuildHash(false);
     if info = 'custom build' then
       info := info + ' by ' + g_GetBuilderName() + ' ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME;
-    result := PChar(Format(GameTitle, [info]))
+    result := Format(GameTitle, [info]);
   end;
 
   function InitWindow (w, h, bpp: Integer; fullScreen: Boolean): Boolean;
-    var flags: Uint32;
+    var flags: Uint32; title: AnsiString;
   begin
     e_LogWritefln('InitWindow %s %s %s %s', [w, h, bpp, fullScreen]);
     result := false;
@@ -125,17 +153,13 @@ implementation
       screen := SDL_SetVideoMode(w, h, bpp, flags);
       if screen <> nil then
       begin
-        {$IFDEF NOGL_INIT}
-        nogl_Init;
-        if glRenderToFBO and (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) then
-        {$ELSE}
-        if glRenderToFBO and (not Load_GL_ARB_framebuffer_object()) then
-        {$ENDIF}
+        if not LoadGL then
         begin
-          e_LogWriteln('SDL: no framebuffer object support detected');
-          glRenderToFBO := False
+          e_LogWriteln('GL: unable to load OpenGL functions', TMsgType.Fatal);
+          exit;
         end;
-        SDL_WM_SetCaption(GetTitle(), nil);
+        title := GetTitle();
+        SDL_WM_SetCaption(PChar(title), nil);
         gFullScreen := fullscreen;
         gRC_FullScreen := fullscreen;
         UpdateSize(w, h);
@@ -150,8 +174,6 @@ implementation
 
   procedure sys_Repaint;
   begin
-    if glRenderToFBO then
-      e_BlitFramebuffer(gWinSizeX, gWinSizeY);
     SDL_GL_SwapBuffers
   end;
 
@@ -163,7 +185,7 @@ implementation
   function sys_GetDisplayModes (bpp: Integer): SSArray;
     var m: PPSDL_Rect; f: TSDL_PixelFormat; i, count: Integer;
   begin
-    SetLength(result, 0);
+    result := nil;
     FillChar(f, sizeof(f), 0);
     f.palette := nil;
     f.BitsPerPixel := bpp;
@@ -428,9 +450,9 @@ implementation
       e_KeyUpDown(key, down);
       g_Console_ProcessBind(key, down);
     end
-    else if gConsoleShow or gChatShow or (g_ActiveWindow <> nil) then
+    else
     begin
-      KeyPress(key) // key repeat in menus and shit
+      g_Console_ProcessBindRepeat(key)
     end;
     if down and IsValid1251(ev.keysym.unicode) and IsPrintable1251(ch) then
       CharPress(ch)
@@ -497,9 +519,7 @@ implementation
       RemoveJoystick(i);
     if screen <> nil then
     begin
-      {$IFDEF NOGL_INIT}
-        nogl_Quit;
-      {$ENDIF}
+      FreeGL;
       SDL_FreeSurface(screen)
     end;
     SDL_Quit