index dcc91b7dda3e9b1a633a57890c3e36ba7f6c0890..12072bb52944ea015b546f50fc605011be3b9cf1 100644 (file)
--- a/src/game/g_textures.pas
+++ b/src/game/g_textures.pas
+(* 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/>.
+ *)
+{$INCLUDE ../shared/a_modes.inc}
unit g_textures;
interface
uses
- e_graphics, BinEditor;
+ e_graphics, BinEditor, ImagingTypes, Imaging, ImagingUtility;
Type
TLevelTexture = record
FWidth: Word;
FMinLength: Byte; // Îæèäàíèå ïîñëå ïðîèãðûâàíèÿ
FRevert: Boolean; // Ñìåíà êàäðîâ îáðàòíàÿ?
-
+
public
constructor Create(FramesID: DWORD; Loop: Boolean; Speed: Byte);
destructor Destroy(); override;
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;
FWidth, FHeight, FCount: Word; BackAnimation: Boolean = False): Boolean;
-function g_Frames_CreateMemory(ID: PDWORD; Name: ShortString; pData: Pointer;
+function g_Frames_CreateMemory(ID: PDWORD; Name: ShortString; pData: Pointer; dataSize: LongInt;
FWidth, FHeight, FCount: Word; BackAnimation: Boolean = False): Boolean;
//function g_Frames_CreateRevert(ID: PDWORD; Name: ShortString; Frames: string): Boolean;
function g_Frames_Get(var ID: DWORD; FramesName: ShortString): Boolean;
procedure DumpTextureNames();
+function g_Texture_Light(): Integer;
+
implementation
uses
- g_game, e_log, g_basic, SysUtils, g_console, WADEDITOR,
- g_language;
+ g_game, e_log, g_basic, SysUtils, g_console, wadreader,
+ g_language, GL;
type
_TTexture = record
function g_Texture_CreateWAD(var ID: DWORD; Resource: String): Boolean;
var
- WAD: TWADEditor_1;
- FileName,
- SectionName,
- ResourceName: String;
+ WAD: TWADFile;
+ FileName: String;
TextureData: Pointer;
ResourceLength: Integer;
begin
Result := False;
- g_ProcessResourceStr(Resource, FileName, SectionName, ResourceName);
+ FileName := g_ExtractWadName(Resource);
- WAD := TWADEditor_1.Create;
+ WAD := TWADFile.Create;
WAD.ReadFile(FileName);
- if WAD.GetResource(SectionName, ResourceName, TextureData, ResourceLength) then
+ if WAD.GetResource(g_ExtractFilePathName(Resource), TextureData, ResourceLength) then
begin
- if e_CreateTextureMem(TextureData, ID) then
+ if e_CreateTextureMem(TextureData, ResourceLength, ID) then
Result := True
else
FreeMem(TextureData);
else
begin
e_WriteLog(Format('Error loading texture %s', [Resource]), MSG_WARNING);
- e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
+ //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
end;
WAD.Free();
end;
function g_Texture_CreateWADEx(TextureName: ShortString; Resource: String): Boolean;
var
- WAD: TWADEditor_1;
- FileName,
- SectionName,
- ResourceName: String;
+ WAD: TWADFile;
+ FileName: String;
TextureData: Pointer;
find_id: DWORD;
ResourceLength: Integer;
begin
- g_ProcessResourceStr(Resource, FileName, SectionName, ResourceName);
+ FileName := g_ExtractWadName(Resource);
find_id := FindTexture();
- WAD := TWADEditor_1.Create;
+ WAD := TWADFile.Create;
WAD.ReadFile(FileName);
- if WAD.GetResource(SectionName, ResourceName, TextureData, ResourceLength) then
+ if WAD.GetResource(g_ExtractFilePathName(Resource), TextureData, ResourceLength) then
begin
- Result := e_CreateTextureMem(TextureData, TexturesArray[find_id].ID);
+ Result := e_CreateTextureMem(TextureData, ResourceLength, TexturesArray[find_id].ID);
if Result then
begin
e_GetTextureSize(TexturesArray[find_id].ID, @TexturesArray[find_id].Width,
else
begin
e_WriteLog(Format('Error loading texture %s', [Resource]), MSG_WARNING);
- e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
+ //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
Result := False;
end;
WAD.Free();
a: DWORD;
begin
Result := False;
-
+
if TexturesArray = nil then Exit;
if TextureName = '' then Exit;
Result := True;
end;
-function CreateFramesMem(pData: Pointer; ID: PDWORD; Name: ShortString;
+function CreateFramesMem(pData: Pointer; dataSize: LongInt; ID: PDWORD; Name: ShortString;
FWidth, FHeight, FCount: Word; BackAnimation: Boolean = False): Boolean;
var
find_id: DWORD;
else SetLength(FramesArray[find_id].TexturesID, FCount);
for a := 0 to FCount-1 do
- if not e_CreateTextureMemEx(pData, FramesArray[find_id].TexturesID[a],
+ if not e_CreateTextureMemEx(pData, dataSize, FramesArray[find_id].TexturesID[a],
a*FWidth, 0, FWidth, FHeight) then
begin
- FreeMem(pData);
+ //!!!FreeMem(pData);
Exit;
end;
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
- WAD: TWADEditor_1;
- FileName,
- SectionName,
- ResourceName: string;
+ WAD: TWADFile;
+ FileName: string;
TextureData: Pointer;
ResourceLength: Integer;
begin
Result := False;
- g_ProcessResourceStr(Resource, FileName, SectionName, ResourceName);
+ FileName := g_ExtractWadName(Resource);
- WAD := TWADEditor_1.Create();
+ WAD := TWADFile.Create();
WAD.ReadFile(FileName);
- if not WAD.GetResource(SectionName, ResourceName, TextureData, ResourceLength) then
+ if not WAD.GetResource(g_ExtractFilePathName(Resource), TextureData, ResourceLength) then
begin
WAD.Free();
e_WriteLog(Format('Error loading texture %s', [Resource]), MSG_WARNING);
- e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
+ //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
Exit;
end;
- if not CreateFramesMem(TextureData, ID, Name, FWidth, FHeight, FCount, BackAnimation) then
+ if not CreateFramesMem(TextureData, ResourceLength, ID, Name, FWidth, FHeight, FCount, BackAnimation) then
begin
WAD.Free();
Exit;
Result := True;
end;
-function g_Frames_CreateMemory(ID: PDWORD; Name: ShortString; pData: Pointer;
+function g_Frames_CreateMemory(ID: PDWORD; Name: ShortString; pData: Pointer; dataSize: LongInt;
FWidth, FHeight, FCount: Word; BackAnimation: Boolean = False): Boolean;
begin
- Result := CreateFramesMem(pData, ID, Name, FWidth, FHeight, FCount, BackAnimation);
+ Result := CreateFramesMem(pData, dataSize, ID, Name, FWidth, FHeight, FCount, BackAnimation);
end;
{function g_Frames_CreateRevert(ID: PDWORD; Name: ShortString; Frames: string): Boolean;
Mem.ReadBoolean(FRevert);
end;
+
+var
+ ltexid: GLuint = 0;
+
+function g_Texture_Light(): Integer;
+const
+ Radius: Integer = 128;
+var
+ tex, tpp: PByte;
+ x, y, a: Integer;
+ dist: Double;
+begin
+ if ltexid = 0 then
+ begin
+ GetMem(tex, (Radius*2)*(Radius*2)*4);
+ tpp := tex;
+ for y := 0 to Radius*2-1 do
+ begin
+ for x := 0 to Radius*2-1 do
+ begin
+ dist := 1.0-sqrt((x-Radius)*(x-Radius)+(y-Radius)*(y-Radius))/Radius;
+ if (dist < 0) then
+ begin
+ tpp^ := 0; Inc(tpp);
+ tpp^ := 0; Inc(tpp);
+ tpp^ := 0; Inc(tpp);
+ tpp^ := 0; Inc(tpp);
+ end
+ else
+ begin
+ //tc.setPixel(x, y, Color(cast(int)(dist*255), cast(int)(dist*255), cast(int)(dist*255)));
+ if (dist > 0.5) then dist := 0.5;
+ a := round(dist*255);
+ if (a < 0) then a := 0 else if (a > 255) then a := 255;
+ tpp^ := 255; Inc(tpp);
+ tpp^ := 255; Inc(tpp);
+ tpp^ := 255; Inc(tpp);
+ tpp^ := Byte(a); Inc(tpp);
+ end;
+ end;
+ end;
+
+ glGenTextures(1, @ltexid);
+ //if (tid == 0) assert(0, "VGL: can't create screen texture");
+
+ glBindTexture(GL_TEXTURE_2D, ltexid);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ //GLfloat[4] bclr = 0.0;
+ //glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, bclr.ptr);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Radius*2, Radius*2, 0, GL_RGBA{gltt}, GL_UNSIGNED_BYTE, tex);
+ end;
+
+ result := ltexid;
+end;
+
end.