[fpc-pascal] Loading PNG files as OpenGL textures

Michael Van Canneyt michael at freepascal.org
Wed Oct 14 08:49:12 CEST 2015

On Wed, 14 Oct 2015, Michael Van Canneyt wrote:

> On Wed, 14 Oct 2015, Ryan Joseph wrote:
>>> On Oct 12, 2015, at 2:25 PM, Michael Van Canneyt <michael at freepascal.org> 
>>> wrote:
>>> TFPCustomImage is an abstract image class, it provides no storage for the 
>>> data. It can have several descendants such as TFPMemoryImage and 
>>> TFPCompactImgRGBA8Bit.
>>> If you just want the raw data, create a TFPMemoryImage and access the 
>>> Colors array property.
>> Sorry for the silence.
>> I’ve learned that the FPImage classes are pretty slow but I’d like to try 
>> them anyways first to see if they’re acceptable.
>> I don’t use Delphi so the FPC docs are a little confusing for me. There is 
>> a colors/pixels property but from what I can tell they map to getting a 
>> single pixel/color at a specific location, but the docs aren’t clear 
>> because the method arguments are never shown. 
>> Do I need to loop through all the pixels or something and pack them into a
>> pointer?  There should be some a single continuous block of memory in this
>> class but I can’t seem to find it using the colors/pixels property.  What
>> am I missing?
> Your are not missing anything, you saw correct.
> TFPCompactImgRGBA8Bit is probably what you need, you'll need to subclass it 
> to get direct access to the
>  FData: PFPCompactImgRGBA8BitValue; field, which is the memory buffer.

TMyImage = Class(TFPCompactImgRGBA8Bit)
   property Data :  PFPCompactImgRGBA8BitValue read FData;

Should do it. Or if you don't need Alpha:

TMyImage = Class(TFPCompactImgRGB8Bit)
   property Data :  PFPCompactImgRGB8BitValue read FData;

You could throw in a property to get a direct pointer to a scanline.
I should maybe add that to the base classes...


More information about the fpc-pascal mailing list