Hello!
I have this problem:
I load a 100x100 picture from a very simple format (SizeX, SizeY, Colors)
Firstly i had this load procedure, and a static array:
Code:
cRGB, cRGBA: Array(.0..100, 0..100.) of Cardinal;
. . .
AssignFile(F, Filename);
Reset(F);
Readln(F, SizeX);
Readln(F, SizeY);
for I := 0 to SizeX do
for J := 0 to SizeY do
begin
Readln(F, cRGB(.I,J.));
if cRGB(.I,J.) = 0 then
cRGBA(.I,J.) := $FF000000 else // for transparency with glAlphaFunc
cRGBA(.I,J.) := cRGB(.I,J.);
end;
Closefile(F);
And drew it with: glDrawPixels(SizeX, SizeY, GL_RGBA, GL_UNSIGNED_BYTE, @cRGBA);
This worked great... but only if the picture was exactly 100x100 pixels large(the array size), otherwise i got a error(if larger) or a distorted picture(if smaller).
Then I searched the google a little, and found out about dynamic arrays (well i'm quite a newbie), and changed the procedure a little:
Code:
cRGB, cRGBA: Array of array of Cardinal;
. . .
AssignFile(F, Filename);
Reset(F);
Readln(F, SizeX);
Readln(F, SizeY);
// I think the problem is here: If i set the lengths to SizeX and SizeY
// i get thrown out of the program when variable I reaches SizeX,
// but if length is SizeX+1 the size of the array is 101 not 100 as it should be,
SetLength(cRGB, SizeX+1, SizeY+1);
SetLength(cRGBA, SizeX+1, SizeY+1);
for I := 0 to SizeX do
for J := 0 to SizeY do
begin
Readln(F, cRGB(.I,J.));
if cRGB(.I,J.) = 0 then
cRGBA(.I,J.) := $FF000000 else
cRGBA(.I,J.) := cRGB(.I,J.);
end;
Closefile(F);
And i drew this one with: glDrawPixels(SizeX, SizeY, GL_RGBA, GL_UNSIGNED_BYTE, @cRGBA(. 0,0 .));
If i didn't add (.0,0.) after the array, it just displayed garbage.
So now it displays a distorted image(kind of like the original, but very tilted), but i can't fix it... i tried some things (like setting the length again after the loop, and changeing the Drawpixles parameters,...) but none worked, the closest thing was glDrawPixels(SizeX+3, SizeY, GL_RGBA, GL_UNSIGNED_BYTE, @cRGBA(. 0,0 .)); but it had a diagonal black line, and it was slightly distorted
So can anyone help me :?:
Bookmarks