fix chat SDL surfaces being in wrong color format (didn't play well with copyToXY's new quick pixel copies)
authorsheepluva
Sun, 04 Dec 2016 02:02:18 +0100
changeset 12107 51596d30a724
parent 12106 2e70ef81e281
child 12108 22bd1099d51f
fix chat SDL surfaces being in wrong color format (didn't play well with copyToXY's new quick pixel copies)
hedgewars/SDLh.pas
hedgewars/uChat.pas
hedgewars/uRenderUtils.pas
--- a/hedgewars/SDLh.pas	Sun Dec 04 01:07:36 2016 +0100
+++ b/hedgewars/SDLh.pas	Sun Dec 04 02:02:18 2016 +0100
@@ -1052,7 +1052,7 @@
 procedure SDL_FreeSurface(Surface: PSDL_Surface); cdecl; external SDLLibName;
 function  SDL_SetColorKey(surface: PSDL_Surface; flag, key: LongWord): LongInt; cdecl; external SDLLibName;
 function  SDL_SetAlpha(surface: PSDL_Surface; flag, key: LongWord): LongInt; cdecl; external SDLLibName;
-function  SDL_ConvertSurface(src: PSDL_Surface; fmt: PSDL_PixelFormat; flags: LongInt): PSDL_Surface; cdecl; external SDLLibName;
+function  SDL_ConvertSurface(src: PSDL_Surface; fmt: PSDL_PixelFormat; flags: LongWord): PSDL_Surface; cdecl; external SDLLibName;
 
 function  SDL_UpperBlit(src: PSDL_Surface; srcrect: PSDL_Rect; dst: PSDL_Surface; dstrect: PSDL_Rect): LongInt; cdecl; external SDLLibName;
 function  SDL_FillRect(dst: PSDL_Surface; dstrect: PSDL_Rect; color: LongWord): LongInt; cdecl; external SDLLibName;
--- a/hedgewars/uChat.pas	Sun Dec 04 01:07:36 2016 +0100
+++ b/hedgewars/uChat.pas	Sun Dec 04 02:02:18 2016 +0100
@@ -161,7 +161,7 @@
  * It will use the color stored in cl and update width
  *)
 procedure RenderChatLineTex(var cl: TChatLine; var str: shortstring);
-var strSurface,
+var strSurface, tmpSurface,
     resSurface: PSDL_Surface;
     dstrect   : TSDL_Rect; // destination rectangle for blitting
     font      : THWFont;
@@ -194,10 +194,14 @@
 SDL_FillRect(resSurface, @dstrect, shadowint);
 
 // create and blit text
+tmpSurface:= nil;
 strSurface:= TTF_RenderUTF8_Blended(Fontz[font].Handle, Str2PChar(str), cl.color);
+// fix format
+if strSurface <> nil then tmpSurface:= SDL_ConvertSurface(strSurface, resSurface^.format, 0);
+SDL_FreeSurface(strSurface);
 //SDL_UpperBlit(strSurface, nil, resSurface, @dstrect);
-if strSurface <> nil then copyToXY(strSurface, resSurface, Padding, Padding);
-SDL_FreeSurface(strSurface);
+if tmpSurface <> nil then copyToXY(tmpSurface, resSurface, Padding, Padding);
+SDL_FreeSurface(tmpSurface);
 
 cl.Tex:= Surface2Tex(resSurface, false);
 
--- a/hedgewars/uRenderUtils.pas	Sun Dec 04 01:07:36 2016 +0100
+++ b/hedgewars/uRenderUtils.pas	Sun Dec 04 02:02:18 2016 +0100
@@ -210,7 +210,8 @@
         bT:= (bD * (255 - aT) + bT * aT) div 255;
         aT:= aD + ((255 - LongInt(aD)) * aT div 255);
 
-        destPixels^[dpi]:= SDL_MapRGBA(dest^.format, rT, gT, bT, aT);
+        destPixels^[dpi]:= SDL_MapRGBA(dest^.format, rT, gT, bT, Byte(aT));
+
         end;
 
     SDL_UnlockSurface(src);