PDA

View Full Version : Allegro.pas - alpng?



Darkhog
28-05-2013, 02:34 PM
I'm using Allegro.pas for allegro 4.4, but it is missing one certain file - alpng. I can't use PNGs without it and TGA doesn't offer as good compression as PNG does. Do you know where can I download this for Allegro.pas? I'd rather not switch to another framework like JEDI-SDL since for me coding with SDL is a chore and coding with allegro is a joy :).

Also I find it strange that we don't have board for Allegro.pas in libraries and tools section. We have for JEDI-SDL, we have for some obscure game libraries (most of which are discontinued, and one is even discontinued! ;)).

SilverWarior
28-05-2013, 05:51 PM
It is true that there is no special forum for Allegro.pas but there is a thread from its author and you can find it here:
http://www.pascalgamedevelopment.com/showthread.php?10899-Allegro-pas/page2
Unfortunately author also mentioned in one post that his atempt on adding PNG support failed.

imcold
28-05-2013, 07:20 PM
If you need png reading, why not use http://www.pascalgamedevelopment.com/showthread.php?9861-BeRoPNG-A-very-tiny-but-complete-PNG-loader ?

Darkhog
28-05-2013, 07:36 PM
For once, it seems confusing to use. Secondly, I don't see how I can use it to directly load PNG into Allegro.pas' al_Bitmapptr structure.

Ñuño Martínez
29-05-2013, 11:18 AM
As Silver Warrior said, I tried it but I failed.

Unfortunatelly, Allegro 4.x internals are quite obscured, and the library wasn't designed to be used in other languages than C and C++. That's why I didn't ported any of the original add-ons included with Allegro 4.4 (I tried to port AllegroGL too :().

Also I tried to use BeRoPNG but I failed too. It was quite confusing. :(

Now, I'll answer your message here (http://www.pascalgamedevelopment.com/showthread.php?10899-Allegro-pas/page3). ;)

imcold
29-05-2013, 03:45 PM
There's only one function to use and you need to load the png file into memory before calling it. It'll return the image in an RGBA array. Example:


var
f: file;
fsize: longword;
buffer: pbyte;
ImageData: PPNGPixel;
ImageWidth,
ImageHeight:longint;
begin
AssignFile(f, 'some.png');
Reset(f, 1);
fsize := FileSize(f);
buffer := getmem(fsize);
blockread(f, buffer^, fsize);
CloseFile(f);

BeRoPNG.LoadPNG(buffer, fsize, ImageData, ImageWidth, ImageHeight, false);
writeln(ImageWidth, 'x', ImageHeight);
freemem(buffer);
freemem(ImageData);


I don't know allegro, but looks like the only thing you need to do is to create a 32 bit bitmap (al_bitmap) and copy the read data into its line pointers (see https://www.allegro.cc/manual/4/api/structures-and-types-defined-by-allegro/bitmap )