index 157ba55430200f8b1ed4b6216b58541914f14806..53ad6c64ee378ac6512170b2cb32243ec289b18c 100644 (file)
+(* 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 e_textures;
{$MODE DELPHI}
unit e_textures;
width, height: Word; // real
glwidth, glheight: Word; // powerof2
u, v: Single; // usually 1.0
width, height: Word; // real
glwidth, glheight: Word; // powerof2
u, v: Single; // usually 1.0
+ fmt: GLuint;
end;
var
end;
var
end;
end;
-{
-type
- TTGAHeader = packed record
- FileType: Byte;
- ColorMapType: Byte;
- ImageType: Byte;
- ColorMapSpec: array[0..4] of Byte;
- OrigX: array[0..1] of Byte;
- OrigY: array[0..1] of Byte;
- Width: array[0..1] of Byte;
- Height: array[0..1] of Byte;
- BPP: Byte;
- ImageInfo: Byte;
- end;
-}
-
-
// This is auxiliary function that creates OpenGL texture from raw image data
function CreateTexture (var tex: GLTexture; Width, Height, aFormat: Word; pData: Pointer): Boolean;
var
Texture: GLuint;
// This is auxiliary function that creates OpenGL texture from raw image data
function CreateTexture (var tex: GLTexture; Width, Height, aFormat: Word; pData: Pointer): Boolean;
var
Texture: GLuint;
+ fmt: GLenum;
+ buf: PByte;
+ f, c: Integer;
begin
tex.width := Width;
tex.height := Height;
begin
tex.width := Width;
tex.height := Height;
+ tex.glwidth := Width;
+ tex.glheight := Height;
+ tex.u := 1;
+ tex.v := 1;
+
if glLegacyNPOT then
begin
tex.glwidth := AlignP2(Width);
tex.glheight := AlignP2(Height);
if glLegacyNPOT then
begin
tex.glwidth := AlignP2(Width);
tex.glheight := AlignP2(Height);
- end
- else
- begin
- tex.glwidth := Width;
- tex.glheight := Height;
+ if tex.glwidth <> tex.width then tex.u := (tex.width+0.0)/(tex.glwidth+0.0);
+ if tex.glheight <> tex.height then tex.v := (tex.height+0.0)/(tex.glheight+0.0);
end;
end;
- tex.u := 1;
- tex.v := 1;
- if tex.glwidth <> tex.width then tex.u := (tex.width+0.0)/(tex.glwidth+0.0);
- if tex.glheight <> tex.height then tex.v := (tex.height+0.0)/(tex.glheight+0.0);
- if (tex.glwidth <> tex.width) or (tex.glheight <> tex.height) then
- begin
- e_WriteLog(Format('NPOT: orig is %ux%u; gl is %ux%u; u=%f; v=%f', [Width, Height, tex.glwidth, tex.glheight, tex.u, tex.v]), MSG_NOTIFY);
- end;
+ //if (tex.glwidth <> tex.width) or (tex.glheight <> tex.height) then
+ // e_WriteLog(Format('NPOT: orig is %ux%u; gl is %ux%u; u=%f; v=%f', [Width, Height, tex.glwidth, tex.glheight, tex.u, tex.v]), MSG_NOTIFY);
if e_DummyTextures then
begin
if e_DummyTextures then
begin
tex.id := Texture;
glBindTexture(GL_TEXTURE_2D, Texture);
tex.id := Texture;
glBindTexture(GL_TEXTURE_2D, Texture);
+ if (tex.glwidth <> tex.width) or (tex.glheight <> tex.height) then
+ e_WriteLog(Format('NPOT: %u is %ux%u; gl is %ux%u; u=%f; v=%f', [tex.id, Width, Height, tex.glwidth, tex.glheight, tex.u, tex.v]), MSG_NOTIFY);
+
// texture blends with object background
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
// texture does NOT blend with object background
// texture blends with object background
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
// texture does NOT blend with object background
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TEXTUREFILTER);
// create empty texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TEXTUREFILTER);
// create empty texture
- if aFormat = GL_RGBA then
- begin
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.glwidth, tex.glheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, pData);
- end
- else
- begin
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.glwidth, tex.glheight, 0, GL_RGB, GL_UNSIGNED_BYTE, nil);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, pData);
- end;
-
- // the following is ok too
- //bindTexture(0);
- //glTextureSubImage2D(tid, 0, 0, 0, img.width, img.height, GL_RGBA, GL_UNSIGNED_BYTE, img.imageData.bytes.ptr);
+ if aFormat = GL_RGBA then fmt := GL_RGBA else fmt := GL_RGB; // silly, yeah?
+ glTexImage2D(GL_TEXTURE_2D, 0, fmt, tex.glwidth, tex.glheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil);
- {
- if (tex.glwidth = tex.glwidth) and (tex.glheight = tex.height) then
- // easy case
- if aFormat = GL_RGBA then
- begin
- glTexImage2D(GL_TEXTURE_2D, 0, 4, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pData);
- end
- else
+ (*
+ GetMem(buf, tex.glwidth*4*tex.glheight);
+ try
+ FillChar(buf^, tex.glwidth*4*tex.glheight, 255);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, tex.glwidth, tex.glheight, fmt, GL_UNSIGNED_BYTE, buf);
+ if (tex.glheight = 128) and (tex.height = 80) then
begin
begin
- glTexImage2D(GL_TEXTURE_2D, 0, 3, Width, Height, 0, GL_RGB, GL_UNSIGNED_BYTE, pData);
+ for f := 0 to tex.glheight-1 do
+ begin
+ for c := 0 to tex.glwidth-1 do
+ begin
+ buf[f*(tex.glwidth*4)+c*4+0] := 255;
+ buf[f*(tex.glwidth*4)+c*4+1] := 127;
+ buf[f*(tex.glwidth*4)+c*4+2] := 0;
+ end;
+ end;
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 82, tex.glwidth, {tex.glheight}1, fmt, GL_UNSIGNED_BYTE, buf);
end;
end;
- end
- }
+ finally
+ FreeMem(buf);
+ end;
+ *)
+
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, Width, Height, fmt, GL_UNSIGNED_BYTE, pData);
+ //glTexSubImage2D(GL_TEXTURE_2D, 0, 0, tex.glheight-tex.height, Width, Height, fmt, GL_UNSIGNED_BYTE, pData);
glBindTexture(GL_TEXTURE_2D, 0);
glBindTexture(GL_TEXTURE_2D, 0);
if fY > img.height then exit;
if fX+fWidth > img.width then exit;
if fY+fHeight > img.height then exit;
if fY > img.height then exit;
if fX+fWidth > img.width then exit;
if fY+fHeight > img.height then exit;
+ //writeln('fX=', fX, '; fY=', fY, '; fWidth=', fWidth, '; fHeight=', fHeight);
imageSize := img.width*img.height*4;
GetMem(image, imageSize);
try
// it's slow, but i don't care for now
ii := image;
imageSize := img.width*img.height*4;
GetMem(image, imageSize);
try
// it's slow, but i don't care for now
ii := image;
- for y := fY+fHeight-1 downto 0 do
+ for y := fY+fHeight-1 downto fY do
begin
for x := fX to fX+fWidth-1 do
begin
begin
for x := fX to fX+fWidth-1 do
begin