DEADSOFTWARE

fixed npot textures rendering
[d2df-sdl.git] / src / game / g_textures.pas
index 4e1cffad133903770bb6900a9e4e8bf699ff2a97..93d8c63d056e93ad0fc5fef015b1b637173b6ad6 100644 (file)
@@ -1,10 +1,25 @@
+(* Copyright (C)  DooM 2D:Forever Developers
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *)
 {$MODE DELPHI}
 unit g_textures;
 
 interface
 
 uses
-  e_graphics, BinEditor;
+  e_graphics, BinEditor, ImagingTypes, Imaging, ImagingUtility;
 
 Type
   TLevelTexture = record
@@ -75,6 +90,8 @@ function g_Texture_Get(TextureName: ShortString; var ID: DWORD): Boolean;
 procedure g_Texture_Delete(TextureName: ShortString);
 procedure g_Texture_DeleteAll();
 
+function g_CreateFramesImg (ia: TDynImageDataArray; ID: PDWORD; Name: ShortString; BackAnimation: Boolean = False): Boolean;
+
 function g_Frames_CreateWAD(ID: PDWORD; Name: ShortString; Resource: String;
                             FWidth, FHeight, FCount: Word; BackAnimation: Boolean = False): Boolean;
 function g_Frames_CreateFile(ID: PDWORD; Name: ShortString; FileName: String;
@@ -365,7 +382,7 @@ begin
     if not e_CreateTextureMemEx(pData, dataSize, FramesArray[find_id].TexturesID[a],
                                 a*FWidth, 0, FWidth, FHeight) then
     begin
-      FreeMem(pData);
+      //!!!FreeMem(pData);
       Exit;
     end;
 
@@ -385,6 +402,53 @@ begin
   Result := True;
 end;
 
+function g_CreateFramesImg (ia: TDynImageDataArray; ID: PDWORD; Name: ShortString; BackAnimation: Boolean = False): Boolean;
+var
+  find_id: DWORD;
+  a, FCount: Integer;
+begin
+  result := false;
+  find_id := FindFrame();
+
+  FCount := length(ia);
+
+  //e_WriteLog(Format('+++ creating %d frames [%s]', [FCount, Name]), MSG_NOTIFY);
+
+  if FCount < 1 then exit;
+  if FCount <= 2 then BackAnimation := False;
+  if BackAnimation then
+    SetLength(FramesArray[find_id].TexturesID, FCount+FCount-2)
+  else
+    SetLength(FramesArray[find_id].TexturesID, FCount);
+
+  //e_WriteLog(Format('+++ creating %d frames, %dx%d', [FCount, ia[0].width, ia[0].height]), MSG_NOTIFY);
+
+  for a := 0 to FCount-1 do
+  begin
+    if not e_CreateTextureImg(ia[a], FramesArray[find_id].TexturesID[a]) then exit;
+    //e_WriteLog(Format('+++   frame %d, %dx%d', [a, ia[a].width, ia[a].height]), MSG_NOTIFY);
+  end;
+
+  if BackAnimation then
+  begin
+    for a := 1 to FCount-2 do
+    begin
+      FramesArray[find_id].TexturesID[FCount+FCount-2-a] := FramesArray[find_id].TexturesID[a];
+    end;
+  end;
+
+  FramesArray[find_id].FrameWidth := ia[0].width;
+  FramesArray[find_id].FrameHeight := ia[0].height;
+  if Name <> '' then
+    FramesArray[find_id].Name := LowerCase(Name)
+  else
+    FramesArray[find_id].Name := '<noname>';
+
+  if ID <> nil then ID^ := find_id;
+
+  result := true;
+end;
+
 function g_Frames_CreateWAD(ID: PDWORD; Name: ShortString; Resource: string;
                             FWidth, FHeight, FCount: Word; BackAnimation: Boolean = False): Boolean;
 var