X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_textures.pas;h=45ae37f73a17e422072f17142163e5a35660c049;hb=dd0d8ac4cc2a0aa774f25c8a1a774f7358acfae7;hp=613419e21e451e1f0793126bdbf9c67fe174eaf3;hpb=8b87c4d3552073bc1dd71381553fa9973adbe260;p=d2df-sdl.git diff --git a/src/game/g_textures.pas b/src/game/g_textures.pas index 613419e..45ae37f 100644 --- a/src/game/g_textures.pas +++ b/src/game/g_textures.pas @@ -1,4 +1,19 @@ -{$MODE DELPHI} +(* 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 . + *) +{$INCLUDE ../shared/a_modes.inc} unit g_textures; interface @@ -93,11 +108,13 @@ procedure g_Frames_DeleteAll(); procedure DumpTextureNames(); +function g_Texture_Light(): Integer; + implementation uses g_game, e_log, g_basic, SysUtils, g_console, wadreader, - g_language; + g_language, GL; type _TTexture = record @@ -367,7 +384,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; @@ -828,4 +845,64 @@ begin Mem.ReadBoolean(FRevert); end; + +var + ltexid: Integer = 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.