Re: [fpc-pascal] STM32F407?

2015-10-11 Thread Michael Ring
STM32F407 and STM32F429 share the same reference Manual so they should 
be highly compatible. Which Board do you own, a Discovery board or  
MicroE Board?


Michael

Am 12.10.15 um 03:31 schrieb Andrew Haines:

Hi,

I've seen on the list that the STM32F429 has some support in fpc now!

A couple of years ago I got a STM32F407 discovery board. Is the code 
for *29 compatible with *07?


Regards,

Andrew Haines
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Loading PNG files as OpenGL textures

2015-10-11 Thread Michael Van Canneyt



On Sun, 11 Oct 2015, Anthony Walter wrote:


I tend to use OS core elements or well known open source libraries for a
few reasons.

1) less code compiled and small programs
2) superior performance
3) more features


1. is not true for image code if you're using lazarus. The code will already be 
there.
2. May be true, depends on what it is.
3. May be true, depends on what it is.

But the downside is that you will need to write glue code for all libraries.
Which can be a real pain for cross-platform apps. Look at lazarus itself.
As a consequence your application may behave differently on each OS.
(XML is a sore point there, or Unicode)

So I would never recommend your route, unless there is no native pascal 
implementation.

For the specific case of image loading, only 2 holds true; 
so unless you really need great performance I see no reason to go this route.


Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Loading PNG files as OpenGL textures

2015-10-11 Thread Ryan Joseph

> On Oct 12, 2015, at 10:57 AM, Anthony Walter  wrote:
> 
> I tend to use OS core elements or well known open source libraries for a few 
> reasons.
> 
> 1) less code compiled and small programs
> 2) superior performance
> 3) more features
> 
> Example: When loading hundreds of textures you bet the Apple Quartz graphics 
> libs are faster and more reliable. Same goes to WIC on Windows and Cario on 
> linux.
> 

So your advice would be to keep my Apple libraries I use on Mac and something 
else for Windows? What would be the equivalent libraries on Windows for CGImage 
and CGBitmapContext be?

Loading PNG’s into a bitmap seems like a pretty thing for single unit but I 
could do the native route also if it was easier. I just wanted to get started 
on cross platform basically and I’m looking for the easiest strategy.


Here’s an example function to load a texture on Mac (given a CGImageRef you 
load from CGImageCreateWithURL). Pretty easy using Apple frameworks and I 
assume those would have some FPC RTL equivalents.

function GenerateTextureFromImage (image: CGImageRef): GLuint;
var
textureWidth, textureHeight: integer;
textureName: GLuint;
bounds: CGRect;
bitmapData: pointer;
colorSpace: CGColorSpaceRef;
context: CGContextRef;
begin
result := 0;

// generate texture
textureWidth := CGImageGetWidth(image);
textureHeight := CGImageGetHeight(image);
bounds := CGRectMake(0, 0, textureWidth, textureHeight);
bitmapData := GetMem(textureHeight * (textureWidth * 4));

if bitmapData <> nil then
begin
colorSpace := CGColorSpaceCreateDeviceRGB;
  context := CGBitmapContextCreate(bitmapData, textureWidth, 
textureHeight, 8, 4 * textureWidth, colorSpace, kCGImageAlphaPremultipliedLast);

if context <> nil then
begin
CGContextFlipVertically(context, 
bounds);
CGContextClearRect(context, bounds);
CGContextDrawImage(context, bounds, 
image);

glGenTextures(1, @result);
glBindTexture(GL_TEXTURE_2D, result);
glTexParameteri(GL_TEXTURE_2D, 
GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 
textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmapData);

//writeln('generated texture ', result, 
' (', textureWidth, 'x', textureHeight,')');
CGContextRelease(context);
end;

FreeMemory(bitmapData);
CFRelease(colorSpace);
end;
end;


Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Loading PNG files as OpenGL textures

2015-10-11 Thread Anthony Walter
I tend to use OS core elements or well known open source libraries for a
few reasons.

1) less code compiled and small programs
2) superior performance
3) more features

Example: When loading hundreds of textures you bet the Apple Quartz
graphics libs are faster and more reliable. Same goes to WIC on Windows and
Cario on linux.

Example: When processing XML, the power of the MSXML parser is going to be
both lighter and faster than any other implementation on Windows. It's also
includes the ability to do stylesheet transforms.

Example: When rendering video frames to textures you bet I am going to use
ffmpeg libs rather than some native implementation.

This isn't meant to dissuade people from writing native implementations in
Pascal. I wrote and maintain a game engine, but even so it's just a
friendly interface to SDL2, OpenGL, SSL, XML, FFMPEG, and System graphics
libs. I have no problem using that stuff when I write Pascal applications,
and that's where I think Pascal excels, which is making friendly OO
encapsulation wrappers around stuff using PME (objects with properties,
methods, and events).

http://www.baregame.org/#bare_game (SDL wrappers)
http://www.getlazarus.org/videos/crossgraphics/
(Quartz,Cairo,Direct2D,GdiPlus wrappers)
http://www.getlazarus.org/interfaces/xml/ (MSXML,libXML2 wrappers)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Loading PNG files as OpenGL textures

2015-10-11 Thread Ryan Joseph

> On Oct 12, 2015, at 9:47 AM, Anthony Walter  wrote:
> 
> Okay, I looked at my Darwin sources which use minimal wrappers around the 
> inbuilt Quartz classes to handle image loading, saving, and pixel data access.
> 


I have a good working implementation of loading OpenGL textures on Mac but I 
want to replace it with a cross platform solution that would run on 
Windows/Linux also that doesn’t rely on CoreGraphics libraries.

I think the classes in FPimage/FPCanvas from the RTL do this already so why do 
we need to use CoreGraphics and Apple-only libraries?

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Loading PNG files as OpenGL textures

2015-10-11 Thread Anthony Walter
Okay, I looked at my Darwin sources which use minimal wrappers around the
inbuilt Quartz classes to handle image loading, saving, and pixel data
access.

To load any image (png, jpg, bmp, gif, ect) you use a CGImageSourceRef
object.

>From file:

ImageSource :=
CGImageSourceCreateWithURL(UrlRefCreateFromFileSystem(FileName).Handle,
nil);

>From a stream:

ImageSource := CGImageSourceCreateWithData(DataRefCreate(Stream).Handle,
nil);

Then to access image data you need to create a bitmap context and tell the
image source to populate the bitmap. My bitmap context create looks like
this, which should give you a head start:

constructor TBitmapContextRef.Create(Image: IImageRef; ColorSpace:
TColorSpace = colorBGRA);
var
  R: CGRect;
begin
  Create(Image.Width, Image.Height);
  R.origin.x := 0;
  R.origin.y := 0;
  R.size.width := Image.Width;
  R.size.height := Image.Height;
  CGContextDrawImage(Handle, R, Image.Handle);
end;

constructor TBitmapContextRef.Create(Width, Height: Integer; ColorSpace:
TColorSpace = colorBGRA);
var
  PixelBytes: UIntPtr;
  C: CGColorSpaceRef;
  A: CGImageAlphaInfo;
  R: CGContextRef;
begin
  inherited Create(nil);
  PixelBytes := Width * Height * 4;
  FPixels := GetMem(PixelBytes);
  FillZero(FPixels^, PixelBytes);
  C := CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
  A := ColorSpaceToAlpha(ColorSpace);
  R := CGBitmapContextCreate(FPixels, Width, Height, 8, Width * 4, C, A);
  CGColorSpaceRelease(C);
  HandleOwn(R);
end;

https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGImageSource/
https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGBitmapContext/

You might be able to figure the rest out from there by yourself. If instead
of figuring things out for yourself, you might to use want the Darwin
graphics part of my library. For this you'll need two of my unit files:

The first unit wraps the ref object management pattern used by Darwin and
includes plus a few extra helper routines.
The second unit wraps the Quartz 2D objects and also includes a few simple
helper routines.

Let me know if you want to contribute and I can upload some code to a
repository on github. But please I would ask that if you have any
improvements to my code (such as wrapping more classes), that you share
those changes with everyone using the same github repository. I'll need you
github account names add you guys as contributors.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] STM32F407?

2015-10-11 Thread Andrew Haines

Hi,

I've seen on the list that the STM32F429 has some support in fpc now!

A couple of years ago I got a STM32F407 discovery board. Is the code for 
*29 compatible with *07?


Regards,

Andrew Haines
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Loading PNG files as OpenGL textures

2015-10-11 Thread Ryan Joseph

> On Oct 12, 2015, at 3:46 AM, Anthony Walter  wrote:
> 
> You can write an interface to the quartz libs and have them load or save a 
> variety of image formats such as bmp, jpg, gif, and png. I've done this with 
> OpenGL on OSX with Free Pascal and I look for the code and post it to git 
> sometime, maybe even Today.
> 

This is what I do on Mac but I wanted to make some cross platform code so I 
need to kill lots of this Apple stuff.

Basically I loaded the image from file, made a CGImage wrapper to it (which 
understands PNG) and then draw it into a CGContext (like a bitmap canvas) then 
extracted the pixel data from the bitmap for use with glTexImage2D.

The FPC RTL on http://wiki.freepascal.org/fcl-image seems to do this but I 
don’t see the interface for TFPCustomCanvas so I don’t know if it’s possible to 
access the pixel data. 

There’s code at 
http://www.sulaco.co.za/opengl_project_BMP_JPG_TGA_texture_loader.htm which 
follows a similar procedure but it’s Delphi and I couldn’t get it to run on FPC 
on my anyways.


Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Loading PNG files as OpenGL textures

2015-10-11 Thread Ryan Joseph

> On Oct 11, 2015, at 10:45 PM, Graeme Geldenhuys 
>  wrote:
> 
> As Michael mentioned, fpimage and fpreadpng can do this. Here is how I
> use it to populate fpGUI's TfpgImage class with image data.
> 
> https://github.com/graemeg/fpGUI/blob/develop/src/corelib/fpg_imgfmt_png.pas

But can I then access the pixel data so I can hand it to glTexImage2D and make 
the texture? I think the FPC RTL classes on 
http://wiki.freepascal.org/fcl-image would do this also but again it’s not 
clear how to get the pixel data for glTexImage2D

Thanks.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Loading PNG files as OpenGL textures

2015-10-11 Thread Anthony Walter
You can write an interface to the quartz libs and have them load or save a
variety of image formats such as bmp, jpg, gif, and png. I've done this
with OpenGL on OSX with Free Pascal and I look for the code and post it to
git sometime, maybe even Today.

http://codebot.org/baregame/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Distinguishing between ARM and ARMHF at build time

2015-10-11 Thread Sven Barth
Am 11.10.2015 18:46 schrieb "Mark Morgan Lloyd" <
markmll.fpc-pas...@telemetry.co.uk>:
>
> I habitually use something like
>
>   fpcV= 'Free Pascal v' + (*$I %FPCVERSION% *) ;
>   fpcC= ' for ' + (*$I %FPCTARGETCPU% *) ;
>
> to generate "about box" text for programs, and designate the binary name
using the Lazarus IDE like
>
> HeavyWethers-$(TargetCPU)-$(TargetOS)-$(LCLWidgetType)
>
> Is there any way of determining that the target is actually an ARM HF
(e.g. Raspberry Pi) rather than some other ARM, so that "HF" could be
incorporated at compilation time or at the very least the about box text
could be patched at runtime?

Maybe we could add a FPCTARGETABI include...

Refards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] interface inheritance implementation

2015-10-11 Thread David Emerson
Not sure what subject line to use to summarize what I'm trying to do 
here, but that is kind of related :)


So I would like to use an interface that inherits from another 
interface, and ... well rather than describe what I'm trying to do, I 
think code speaks best.


type

// here is the first interface
i_adder = interface
  ['{01234567--407C-8133-987654FEDCBA}']
  function add (a, b : longint) : longint;
  end;

// this next interface inherits from i_adder, and thus does two things
i_multiplier_and_adder = interface (i_adder)
  ['{A1234567--407C-8133-987654FEDCBA}']
  function multiply (a, b : longint) : longint;
  end;

t_base = TInterfacedObject;

// now an implementing class for i_adder
t_adder = class (t_base, i_adder)
  function add (a, b : longint) : longint;
  end;

// and finally the implementing class for i_multiplier_and_adder
t_multiplier_and_adder = class (tbase, i_multiplier_and_adder)
  f_adder : i_adder;
  function multiply (a, b : longint) : longint;
// THIS PROPERTY DOES NOT WORK:
  property adder : i_adder read f_adder implements i_adder;
  end;


The structure I have is like... I have one instance of t_adder, and I 
want to have several instances of t_multiplier_and_adder that all use 
the one instance of t_adder as their hook.


And in my real code, t_adder has 6 methods or so, thus it becomes 
cumbersome to implement all those in t_multiplier_and_adder, each just 
calling the function on the t_adder that I'd like to use as a hook.


Do I have to implement all of the individual i_adder methods for 
t_multiplier_and_adder? Is there no shortcut?



Thanks!
~David.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Distinguishing between ARM and ARMHF at build time

2015-10-11 Thread Mark Morgan Lloyd

I habitually use something like

  fpcV= 'Free Pascal v' + (*$I %FPCVERSION% *) ;
  fpcC= ' for ' + (*$I %FPCTARGETCPU% *) ;

to generate "about box" text for programs, and designate the binary name 
using the Lazarus IDE like


HeavyWethers-$(TargetCPU)-$(TargetOS)-$(LCLWidgetType)

Is there any way of determining that the target is actually an ARM HF 
(e.g. Raspberry Pi) rather than some other ARM, so that "HF" could be 
incorporated at compilation time or at the very least the about box text 
could be patched at runtime?


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Loading PNG files as OpenGL textures

2015-10-11 Thread Graeme Geldenhuys
On 2015-10-11 05:29, Ryan Joseph wrote:
> Does the FPC RTL contain any units for loading PNG files as bitmaps

As Michael mentioned, fpimage and fpreadpng can do this. Here is how I
use it to populate fpGUI's TfpgImage class with image data.

https://github.com/graemeg/fpGUI/blob/develop/src/corelib/fpg_imgfmt_png.pas


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Loading PNG files as OpenGL textures

2015-10-11 Thread Ryan Joseph

> On Oct 11, 2015, at 1:53 PM, Michael Van Canneyt  
> wrote:
> 
> You can use the fpimage and fpreadpng units. Check the packages/fcl-image 
> sources. There is a small demo program that shows how to do it.

I see you can load an image as TFPCustomImage with TFPCustomImageReader then 
there is a canvas class (TFPCustomCanvas) which I assume I could draw the 
TFPCustomImage into and expose the pixels as a pointer to memory which I could 
then use to make the OpenGL texture.

I’m not able to see the references for TFPCustomCanvas in particular so I’m not 
sure how this would work. There is the guide I found but is there any more 
complete examples I could look at? Too much is missing to understand exactly 
how all these classes work together. 

http://wiki.freepascal.org/fcl-image

Thanks.


Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal