[fpc-pascal] FPC Graphics options?

Nikolay Nikolov nickysn at gmail.com
Tue May 16 02:46:05 CEST 2017



On 05/16/2017 01:37 AM, James Richters wrote:
> I have managed to get ptcgraph and ptccrt to work with my program and I can report that there is an AMAZING increase in graphics performance!   It is pretty much a drop in replacement and I did not change any compiler settings.  I did have to make a few minor changes to get it to work, not enough to change the speed of anything.
>
> I am getting an error 217 access violation when I try to use outtextXY after a  SetTextJustify(2,2);  (Top, Right justify)  but with the graph unit my text was in the correct place and not off the screen.
Can you send me a small program that demonstrates the problem, so I can 
try to reproduce it and fix it?
>
> I also no longer have the 'graphwindow' handle variable so I had to comment out anything that was using it like
>
> SetWindowTextA(graphicwindow,graphwindowtext);
> And
> ShowWindow(graphwindow, SW_SHOW);
> So I just commented them out for now.    I'm hoping there is a way to get around the graphwindow variable because I was using the above 2 functions and I don't know how else to determine the graphic window handle... but the performance gain and ease of implementation will make working out any other issues worth the effort.  Any advice on how I can capture the graph window handle would be appreciated
Unfortunately, you can't do that and it's actually the main reason why 
ptcgraph is fast. Even if you modify the ptcgraph source, so that you 
get the window handle, it would do you no good, because the window is 
created in a different thread and this means that you cannot draw to the 
window from your program's thread. In fact, all the ptcgraph drawing 
routines actually render to an internal software buffer and issue no 
winapi drawing calls at all. That's the reason ptcgraph is fast and the 
regular graph unit is slow - the winapi drawing routines are really the 
bottleneck in this case and not the speed of the code, generated by FPC.

I know this is not ideal, but probably the easiest option is to find a 
suitable bgi .chr font pack or try a ttf to .chr conversion tool. If you 
own a copy of Turbo Pascal (or Turbo C/C++), you can use the .chr fonts 
that came with it. Unfortunately, other solutions are hard - they 
involve e.g. linking the freetype library, using it to render to a 
software buffer, and then blitting this buffer to the ptcgraph canvas 
with PutImage. Or doing a similar thing with winapi functions, but by 
drawing the text on a DIB (device independent bitmap, basically a memory 
buffer, holding an image) that you created, instead of on the window 
directly, then reading from the DIB and blitting it with PutImage once 
again.

Best regards,
Nikolay



More information about the fpc-pascal mailing list