Hi, I’m trying to create a texture from a file and from a simple gridmap, a 100 x 100 array map of rgb byte values
but the problem is that the image is loaded to opengl but it gets distorted and with bad effects,
I’m using this:
to Create then image in opengl from a pointer to the image
CreateTexture(Width, Height, Format: Integer; Data: Pointer): Integer;
var
Texture: GLuint;
begin
glGenTextures(1, @Texture);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glBindTexture(GL_TEXTURE_2D, Texture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
if Format = GL_RGBA
then gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, pData)
else gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, pData);
result := Texture;
end;
and this to get the Imagedata from a file wich contains the pixel information like this:
R: Byte;
G: Byte;
B: Byte;
function CreateDSTextureFromData(Data: TTextureData): TDSImage;
var
DataType, Size: Integer;
Image: Pointer;
begin
Result.Width := Length(Data.Data[0]);
Result.Height := Length(Data.Data);
DataType := Data.DataType;
Size := Result.Width * Result.Height * DataType;
GetMem(Image, Size);
case DataType of
3: Result.Texture := CreateTexture(Result.Width, Result.Height, GL_RGB, Image);
4: Result.Texture := CreateTexture(Result.Width, Result.Height, GL_RGBA, Image);
end;
FreeMem(Image);
end
But it seems to doesn’t workd, is there any problem?
Thks for any help on this