Lazarus

Programming => Graphics and Multimedia => Games => Topic started by: Ñuño_Martínez on May 10, 2016, 08:55:20 pm

Title: Allegro.pas
Post by: Ñuño_Martínez on May 10, 2016, 08:55:20 pm
Allegro.pas (http://allegro-pas.sf.net/) is a wrapper that allows to use the Allegro Game Library (http://liballeg.org/) with Pascal.

Allegro.pas 5.2.alpha released!  8)

Yep, about 3 years after 5.0.alpha, a new release of branch 5 (now TRUNK) was released today.  It has a lot of improvements, and should be slightly more stable than previous alpha.  But it is still an alpha.  :-[ Anyway, if you want to test it, download from here (https://sourceforge.net/projects/allegro-pas/files/5.2.alpha/).

I'll use it in the comming TINS 2016 (http://tins.amarillion.org/), and I plan to use my entry as demonstration game for the library.

Note:  I'll do release announcementes in this thread from now, instead of create a new thread every version.
Title: Allegro.pas 5.2.alpha-2
Post by: Ñuño_Martínez on June 26, 2016, 08:15:25 pm
There are a lot of work to be done yet, but I did several big improvements so I've just uploaded a new release.

In short:  There are several bugfixing, including (but not limited to) the primitives add-on that didn't work in previous versions.  There are new functionality too, as 3D transformations and custom memory management.  Also I added new examples and updated some other that shows how to use basic and advanced stuff to supply the lack of documentation.

You can download it from here (https://sourceforge.net/projects/allegro-pas/files/5.2.alpha/).

Any comment and suggestion will be welcome.
Title: Re: Allegro.pas
Post by: johnsson on June 26, 2016, 09:24:13 pm
Excellent work.
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on June 27, 2016, 01:41:49 pm
Thanks. :)

Now I'm wondering what would be a good demonstration game to be added.  :-\
Title: Re: Allegro.pas
Post by: Leledumbo on June 27, 2016, 06:45:50 pm
Thanks. :)

Now I'm wondering what would be a good demonstration game to be added.  :-\
Something achievable in a relatively short code. People tend to learn from examples these days, and I think providing a tutorial is also much harder than providing ready to run examples. The first 3 starter examples could be:
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on June 29, 2016, 01:40:37 pm
Something achievable in a relatively short code. People tend to learn from examples these days, and I think providing a tutorial is also much harder than providing ready to run examples. The first 3 starter examples could be:
  • tic-tac-toe or 15 puzzle (2d, no animation, no collision detection)
  • arkanoid (2d, simple linear animation, simple collision detection by position checking)
  • simplified 1945 / raiden (2d, a bit complex animation, bounding square/circle/triangle collision detection)
Not bad. I like it. Thanks.
Title: Allegro.pas 4.4.5-1
Post by: Ñuño_Martínez on July 20, 2016, 01:43:35 pm
Some days ago somebody found that unit alWin didn't compile.  Since I never used it, I didn't tested.

Anyway it is now fixed. I've also upgraded documentation adding a search engine.
Title: Re: Allegro.pas
Post by: Handoko on July 20, 2016, 04:01:15 pm
I will suggest Tetris to replace Tic Tac Toe. I personally think Tic Tac Toe is boring, Tetris is challenging. But Tic Tac Toe as demo game has it own value, that is to demonstrate simple AI.
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on July 21, 2016, 11:44:44 am
Agree.  I think I'll do a Tetris-like delphi (I like Puyo-puyo (https://www.youtube.com/watch?v=Gq0U-ml1HS4) :)) and a shooter.  One of them with 3D graphics even if they are 2D games.  That will show and teach a lot.
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on July 06, 2017, 11:16:48 am
Oh my oh my!  More than one year since the last release (5.2.alpha2).

But that's not the worst part, no it isn't.  The worst part is that I did a ton of improvements.  Mostly documentation but also:
If you're wondering why I didn't release 5.2.alpha3 yet the answer is simple:  I forgot it.  Last year I had a lot of personal and laboral issues that affected my memory.  Really.  I'll release it this evening or tomorrow.  I'll not do it now because I'm busy (I really am ::) ) and because I've found a flaw in the SVN tree I must fix too (There isn't 5.2.alpha in the RELEASE directory!).
Title: Allegro.pas 5.2.a3
Post by: Ñuño_Martínez on July 06, 2017, 09:35:43 pm
Ok: I just uploaded the new 5.2.a3 release.  Please enjoy (https://sourceforge.net/projects/allegro-pas/files/5.2.a3/).
Title: Re: Allegro.pas
Post by: timofonic on July 18, 2017, 03:15:17 am
Just a question:

Why using Allegro instead of SDL2? What are the reasons behind it?
Title: Re: Allegro.pas
Post by: Handoko on July 18, 2017, 07:31:52 am
Hello timofonic,
Welcome to the forum.

If you google the web you will find no winner, none of them has its own killer feature. Both of them are good libraries for game creation, and finding tutorials are very easy.

I've just started to learn Allegro some months ago. I found Allegro is very easy to start with. SDL API documentation is good, but Allegro is better. Allegro API pages offer more info, including see also and examples.

You can compare load bitmap documentation of SDL:
http://wiki.libsdl.org/SDL_LoadBMP?highlight=%28\bCategorySurface\b%29

With this:
https://www.allegro.cc/manual/5/al_load_bitmap

Furious Paladin is my first test project using Allegro:
http://forum.lazarus.freepascal.org/index.php/topic,35313.msg252085.html#msg252085

It had some minor issues, my problem not allegro's problem. It didn't run on same speed on different machines, solved easily. Later I found on Windows it didn't detect shift keys the same way on Linux. I modified the code to use ctrl keys instead of shift keys.

The demo was created using 500 x 300 pixels resolution. It is not good for large screen users. As recommended by some users here, I tried to make it better supports on large screen. I never thought it was so easy to make it double size if it detects running on large screen. Just added the code below then the program will display double sized without changing anything of the code.

Code: Pascal  [Select][+][-]
  1. const
  2.   ScreenWidth  = 500;
  3.   ScreenHeight = 300;
  4.  
  5. var
  6.   Display:     ALLEGRO_DISPLAYptr;
  7.   MonitorInfo: ALLEGRO_MONITOR_INFO;
  8.   Transform:   ALLEGRO_TRANSFORM;
  9.  
  10.   // Prepare display
  11.   al_get_monitor_info(0, MonitorInfo);
  12.   if (MonitorInfo.x2 > 1060) and (MonitorInfo.y2 > 610) then begin
  13.     Display := al_create_display(ScreenWidth*2, ScreenHeight*2);
  14.     al_identity_transform(Transform);
  15.     al_rotate_transform(Transform, 0);
  16.     al_scale_transform(Transform, 2, 2);
  17.     al_use_transform(Transform);
  18.   end
  19.   else
  20.     al_create_display(ScreenWidth, ScreenHeight);

I have not tried SDL, I cannot say Allegro is better. But I can say Allegro is really easy to start with.
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on July 18, 2017, 10:03:56 am
I think the main reasons to use Allegro instead of SDL are personal preferences.

Both libraries have support for (most) modern platforms.  Allegro is less popular than SDL, so there are less examples, tutorials and games (the awesome Factorio (https://www.factorio.com/) was made using Allegro) but me and others are working hard to change this.
Title: Allegro.pas 5.2.b.0 released
Post by: Ñuño_Martínez on April 23, 2018, 08:54:10 pm
[This is a copy of what I wrote for the news (https://www.sourceforge.net/p/allegro-pas/news/2018/04/allegropas-52b0-released/) section of SourceForge.  I'm a bit lazy today.]

Almost a year after the last release I've published version 5.2.b.0.

This version doesn't fix a lot of bugs nor adds new functionality, but it is an important milestone (hence the change from alpha to beta) as to recover Delphi compatibility.

May be you know, Allegro.pas was Delphi compatible from the beginning.  It was quite complex because Allegro API needed to share variables with DLL, and Delphi wasn't capable of this.  To make it possible, I used an extra DLL file that returned the pointers to such variables.  That made things quite complex to maintain and hard to use so I decided to remove Delphi compatibility being the latest compatible version the 4.2.2 but I always promised the back to Delphi with version 5 as the new API is more easy to port.

Now Delphi compatibility has back.  Unfortunatelly I wasn't able to make it 100% compatible yet and a few examples don't work but they will.  Also it was tested with Delphi 10 Tokio Starter Edition only.  I've try to keep track of older versions (thanks to Gregor A. Cieslak for his help) but it may fail.  Please let me know.

Visit the Files section (https://sourceforge.net/projects/allegro-pas/files/5.2.b.0/) to download and test this new version.  I've updated the on-line documentation (http://allegro-pas.sourceforge.net/docs/5.2/) that you can download from the Files section too.
Title: Re: Allegro.pas
Post by: dubst3pp4 on November 08, 2018, 07:31:19 am
Hi Ñuño_Martínez, thanks for your great work!

I'm testing the Allegro.pas bindings for a new project and figured out, that the latest sources (allegro.pas-5.2.b.0) don't build on Linux, whereas allegro.pas-5.2.a.3 builds fine. I've installed allegro 5.2.3.0 from the Ubuntu repositories. After I type make the linker tells me the following:
Quote
Allegro.pas 5.2.b
(c) Guillermo Martínez J. 2006-2017
http://allegro-pas.sourceforge.net

fpc -O- -gl -vh -vw -dDEBUGMODE -Sh -Si  -Fulib/ -FUobj/ examples/ex_bitmap_flip.pas -obin/examples/ex_bitmap_flip
Hint: Start of reading config file /etc/fpc.cfg
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 3.0.4 [2017/12/13] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling examples/ex_bitmap_flip.pas
Linking bin/examples/ex_bitmap_flip
/usr/bin/ld: warning: bin/examples/link.res contains output sections; did you forget -T?
/usr/bin/ld: -lallegro-debug was not found
/usr/bin/ld: -lallegro_image-debug was not found
/usr/bin/ld: -lallegro_font-debug was not found
/usr/bin/ld: -lallegro_dialog-debug was not found
Error: Error while linking
Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode
makefile.all:20: recipe for target 'bin/examples/ex_bitmap_flip' failed
make: *** [bin/examples/ex_bitmap_flip] Error 1
It seems that the allegro_*-debug files weren't referenced with the previous version of allegro.pas, weren't they? Do I miss something important when I use allegro.pas-5.2.a.3?

Thanks for any hints :-)
Title: Re: Allegro.pas
Post by: Soner on November 08, 2018, 03:53:11 pm
You must install allegro development package.
Install synaptic package program and search with it.
It has same name plus...-dev...


Look at this lines from compile result:

usr/bin/ld: -lallegro-debug was not found
/usr/bin/ld: -lallegro_image-debug was not found
/usr/bin/ld: -lallegro_font-debug was not found
/usr/bin/ld: -lallegro_dialog-debug was not found



Linker tells to you that some libs are missing.
Look for the name -lxxxxx in synaptic.
I.e for -lallegro_image is something like liballegro_image...-dev
Title: Re: Allegro.pas
Post by: dubst3pp4 on November 08, 2018, 04:00:54 pm
You must install allegro development package.
Install synaptic package program and search with it.
It has same name plus...-dev...
I've installed them already, that's why I was able to build the examples with 5.2.a.3 but not with the latest version (5.2.b.0).
Title: Re: Allegro.pas
Post by: Soner on November 08, 2018, 04:24:09 pm
The linker tells you have not installed them. Maybe your program is 32 bit and your allegro 64bit,or lib names are changed in allegro.pas 5.2.b.0.
I would compare library names in both versions.
Good luck.
Title: Re: Allegro.pas
Post by: dubst3pp4 on November 09, 2018, 08:21:36 am
Hi Soner,
thanks for your input. I found out that it was no problem to compile the demo game by Handoko, which is included in the latest allegro.pas. So the problem had to be in the makefile and voilà, in the file there are the following lines:

Code: [Select]
# Optimized compilation
# FLAGS = $(OPTOPT) $(PFLAGS) $(EFLAGS)
# Use next line instead to activate debug.
FLAGS = $(DBGOPT) $(PFLAGS) $(EFLAGS)

which I changed to

Code: [Select]
# Optimized compilation
FLAGS = $(OPTOPT) $(PFLAGS) $(EFLAGS)
# Use next line instead to activate debug.
# FLAGS = $(DBGOPT) $(PFLAGS) $(EFLAGS)

and now all the examples compile fine. Neither on Ubuntu nor on Fedora there are *-debug versions of allegro5, just the -dev packages.
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on November 09, 2018, 06:21:49 pm
That's weird.  I can compile it in my Linux system (Xubuntu 16.04, should upgrade and test  %)).  May be they changed something in the names, but I don't think so.  Or am I using a different version?  I'll take a look and update if needed. Thanks dubst3pp4.

BTW I'm working in the documentation (slowly because I don't have a lot of free time, and also I want to do something for GitHub Game Off (https://itch.io/jam/game-off-2018)) checking the whole library line per line comparing with the original Allegro.  This is also to find potential (API) bugs and also to know what stuff are not implemented yet.

[Edit]
I've created a bug ticket (https://sourceforge.net/p/allegro-pas/bugs/18/) just to keep track and not forget it.
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on November 22, 2018, 07:41:35 pm
Finally I found time to try and it didn't go well.

I updated Xubuntu Linux to 18.04.1 so I had to re-install Allegro but something goes wrong.  Allegro does work perfect but when I try Allegro.pas examples I have some unhandled exceptions when exiting.  Also I've found I can't compile my own game engine (mingro on SourceForge) because some issues with the library that deals with PNG files.  This is specially weird s Allegro.pas examples compile perfectly.

This is weird so I think I'll reinstall Linux.  This isn't the first time that Ubuntu update doesn't do the work correctly.
Title: Re: Allegro.pas
Post by: lainz on November 24, 2018, 05:12:06 pm
I think a good port with Allegro can be Open Surge
http://opensnc.sourceforge.net/forum/

Now it has his own scripting engine as well.

I think they was using Allegro 4, but now I don't know. I never get to compile their code, I'm not good using 'make' and similar tools, getting things working in the C world seems harder that installing everything with packages / OPM.

Anyways is a good allegro game, that will be cool to have in Pascal. I some time started a port to JS, to discover that a port to JS was already available  ::)
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on November 27, 2018, 11:17:57 am
I think a good port with Allegro can be Open Surge
http://opensnc.sourceforge.net/forum/
Yep, I know that project too.  Actually I plan to add some ideas from it to my engine, such some of the scripting stuff to help defining tilesets and spritesheets.
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on November 27, 2018, 06:14:21 pm
Ok, with a clean Linux installation it seems to work, and I think I've found what's the problem found by dubst3pp4:

-dev packages provided by Ubuntu doesn't includes the library compiled with "debug" option.  The only way to get such library is to download sources and compile by yourself.  I'll add a note to the installation instructions.
Title: Re: Allegro.pas
Post by: lucamar on November 27, 2018, 08:53:29 pm
[...] Ubuntu doesn't includes the library compiled with "debug" option.  The only way to get such library is to download sources and compile by yourself.  I'll add a note to the installation instructions.

Yeah, my Kubuntu hasn't got any "-debug" package:
Code: Bash  [Select][+][-]
  1. lucamar@luna:~$ apt list *allegro*
  2. Listing... Done
  3. allegro4-doc/trusty 2:4.4.2-4 all
  4. allegro5-doc/trusty 2:5.0.10-2 all
  5. liballegro-acodec5-dev/trusty 2:5.0.10-2 i386
  6. liballegro-acodec5.0/trusty 2:5.0.10-2 i386
  7. liballegro-audio5-dev/trusty 2:5.0.10-2 i386
  8. liballegro-audio5.0/trusty 2:5.0.10-2 i386
  9. liballegro-dialog5-dev/trusty 2:5.0.10-2 i386
  10. liballegro-dialog5.0/trusty 2:5.0.10-2 i386
  11. liballegro-doc/trusty 2:4.4.2-4 all
  12. liballegro-image5-dev/trusty 2:5.0.10-2 i386
  13. liballegro-image5.0/trusty 2:5.0.10-2 i386
  14. liballegro-physfs5-dev/trusty 2:5.0.10-2 i386
  15. liballegro-physfs5.0/trusty 2:5.0.10-2 i386
  16. liballegro-ttf5-dev/trusty 2:5.0.10-2 i386
  17. liballegro-ttf5.0/trusty 2:5.0.10-2 i386
  18. liballegro4-dev/trusty 2:4.4.2-4 i386
  19. liballegro4.4/trusty 2:4.4.2-4 i386
  20. liballegro4.4-plugin-alsa/trusty 2:4.4.2-4 i386
  21. liballegro5-dev/trusty 2:5.0.10-2 i386
  22. liballegro5.0/trusty 2:5.0.10-2 i386
  23. libguichan-allegro-0.8.1-1/trusty 0.8.2-13 i386
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on November 28, 2018, 11:05:03 am
I was re-thinking it.  The "-debug" versions are to debug Allegro itself.  So they're not actually needed when working in your game, but it is useful when working on Allegro.pas or creating a new add-on.  So, to not link the "-debug" version just remove the "-dDEBUGMODE" option from the makefile (just line 85 (https://sourceforge.net/p/allegro-pas/code/HEAD/tree/RELEASES/5.2.b.0/makefile#l85)) and/or use the optimized  configuration as dubst3pp4 said (lines 114 to 117 (https://sourceforge.net/p/allegro-pas/code/HEAD/tree/RELEASES/5.2.b.0/makefile#l114))

This will be "fixed" in the next release, including the documentation explaining it.  I don't know when it will be released but I doubt it will be before next year (too little time :().
Title: Re: Allegro.pas
Post by: dubst3pp4 on November 28, 2018, 12:06:11 pm
Ok, with a clean Linux installation it seems to work, and I think I've found what's the problem found by dubst3pp4:

-dev packages provided by Ubuntu doesn't includes the library compiled with "debug" option.  The only way to get such library is to download sources and compile by yourself.  I'll add a note to the installation instructions.
Thanks Ñuño! When I compile without the DBGOPT flags, everything works also without the -debug packages. For what do I need those debug packages? To get a proper support of Allegro.pas in gdb?
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on November 29, 2018, 12:08:48 pm
Thanks Ñuño! When I compile without the DBGOPT flags, everything works also without the -debug packages. For what do I need those debug packages? To get a proper support of Allegro.pas in gdb?
The -debug packages are to debug Allegro, so yes, they're to debug Allegro.pas with GDB too.  They're not needed to debug your games.  Now I have to test if -dev packages are mandatory or if it can work with the release ones.
Title: Re: Allegro.pas
Post by: knerking@gmail.com on May 12, 2019, 03:53:33 am
I just like to thank you for your work with allegro5. I works very well.  8)
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on May 13, 2019, 11:21:40 am
I just like to thank you for your work with allegro5. I works very well.  8)
Thank you for using it. ;)

Curiously, I came to write something.

Few days ago I finished to revise the allegro5.pas (https://sourceforge.net/p/allegro-pas/code/HEAD/tree/TRUNK/lib/allegro5.pas) unit.  It was a loooooong work, checking everything and updating the documentation.  As a result, documentation is complete for that unit, and I've fixed some mistakes, changed a few stuff (data types, parameters...) and added a few new procedures and functions.

I've also spend some time trying to update the website, but was not able to change the background color (sigh!).  I think I'll create a new one, but not yet.  A month ago I created a new project to help build websites for SourceForge projects called sfwebsite (https://sfwebsite.sourceforge.io/).  It's still in a very early stage but once finished it will help a lot.

So, I'll not upload a new version soon, as there's work to do:

But I'm in the way...
Title: Still alive...
Post by: Ñuño_Martínez on November 14, 2019, 09:38:53 pm
Still alive and working on the project.

Two days ago I've finished to check all addons and documentation.  Right now I'm working porting more examples from the original Allegro.  This will show me if there's still any mistake or error.

Also, I've synced the GitHub mirror (https://github.com/niuniomartinez/allegro-pas) if you don't like SourceForge.
Title: Allegro.pas 5.2.β.1 released
Post by: Ñuño_Martínez on March 01, 2020, 09:08:10 pm
As the title said, I've released Allegro.pas 5.2.β.1.

It was almost two years but it is finally out.  You can read the release notice here (https://sourceforge.net/p/allegro-pas/news/2020/03/allegropas-52%CE%B21-released/), but mainly I've added a lot of functionality, completed the documentation and reach 98% Delphi compatibility. The 2% is because a few issues in two examples.  You can download from here (https://sourceforge.net/projects/allegro-pas/files/5.2.b.1/) (the GitHub mirror (https://github.com/niuniomartinez/allegro-pas) will be synchronized ASAP, but there are only minor differences right now).

Next I'll refurnish the website. It is quite ugly and hard to read.
Title: Re: Allegro.pas
Post by: furious programming on March 06, 2020, 03:06:58 pm
Great job Ñuño_Martínez! Keep it up, in my opinion it is an important project and should be constantly developed. I just hope that people will start creating some larger productions using this API, Allegro library and Free Pascal, because somehow there are not many of them. 8)
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on March 14, 2020, 08:08:41 pm
Thanks furious programming. :)

I'm now updating the web site.  I finished the main site (and it is working (http://allegro-pas.sf.net/)) but have problems with wiki.  Seems that Dokuwiki doesn't work on SourceForge anymore due to configuration of the server (more restrictive to avoid abuse and security gaps).  I'm thinking what to do.  I don't like SourceForge's wiki system a lot.  A solution would be to use GitHub Wiki but I don't like GitHub (%)).  I would use FPC Wiki but I think it is an abuse. :-[

I'm tempted to create my own wiki software... ::)
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on March 15, 2020, 09:28:33 pm
Sorry for the double post but it is to make more evident that I've decided to add a tutorial in the Lazarus Wiki (https://wiki.freepascal.org/Allegro.pas_Vivace_tutorial).  Not sure if I'll keep it there yet.  Just let me know.
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on March 23, 2020, 08:51:34 pm
I've finished with the new web site, including the Allegro.pas Vivace Tutorial, so I've finished with this Allegro.pas cycle (FINALLY!!!).

Anyway, please visit it (http://allegro-pas.sf.net/ (http://allegro-pas.sf.net/)) and tell me what do you think, specially if you find any flaw, problem or mistake.
Title: Re: Allegro.pas
Post by: furious programming on March 24, 2020, 01:24:58 am
Anyway, please visit it (http://allegro-pas.sf.net/ (http://allegro-pas.sf.net/)) and tell me what do you think, specially if you find any flaw, problem or mistake.

Your site looks ancient, primitive — it lacks... style. 8)

Even if you care about making the website light and created only using HTML and CSS (noscript), it can be done in such a way that it looks modern. The project's website is its showcase, so it should look well and contain clearly presented data. Too simple website will inform viewers that the project is amateur, which will discourage potential interested.

Long ago, I needed to make a light website for my own project (in Polish, but this is not the key), which was also supposed to work locally. Look at this website — https://tsinfo.4programmers.net/ — and compare with yours. That should give you food for thought.



Second thing is the code. Don't write the sample code as if it was from the '70s. Follow the guidelines for naming conventions and code formatting, including write lowercase keywords. Also, show the colored code on the page — analyzing one-color code is more difficult.

To beautify the code you can simply use Lazarus. Just write the code in the code editor, export it to HTML document (go to File and use Export as HTML) and copy the final HTML code to your file.
Title: Re: Allegro.pas
Post by: winni on March 24, 2020, 01:40:01 am
Hi!

I like your website. Very 90ies without blink and boing and gimmickry.

But I think this is not the style that your users prefer.

CSS is simple and full  of (unlogic) possibilities.

Just as a hint.

Winni
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on March 24, 2020, 12:50:14 pm
Thanks for the comments.

I will change the color palette.  I'm still working on it.  Green is because the allegator, but that color seems not to be friend with complementary (http://paletton.com/#uid=32t0f0kkagjcnp2gpkkokc-tB87). %)  Would change anytime.

About code displaying, I agree that syntax highlighting will improve the reading, but the way the pages are build doesn't allow to do it (yet) as it doesn't allow HTML code.  I plan to add a wiki to the site so that will deal with it.

About uppercase keywords, sorry but I don't agree:  I find it easier to read even with syntax highlighting so I'll keep it (specially while syntax highlighting can't be applied).  Will not discuss anyway.

And maybe you didn't notice, but Allegro is an amateur project. ::)  Just kidding (actually not).  I understand what do you mean (actually yes):  Allegro.pas is a one man (amateurish) project so deal with it or do a serious proposal (just remember I didn't put a link to the donation page, should I?  That would allow me to hire a designer. :-[).
Title: Re: Allegro.pas
Post by: Otto on March 24, 2020, 02:17:20 pm
Hello Ñuño_Martínez.

I believe that the usability of your site is good, the essential content is easily accessible and clearly described. You preceded me, otherwise I would have recommended you to prepare a dedicated wiki. However, in case you thought it was appropriate, I could help you with the Italian translation. 

If it all goes well, we could have a direct link in "Portal:Game Development".

As for colors, in my opinion, it is a matter of taste and momentary fashion. I personally have always preferred dark backgrounds with high contrasts, with a few different colors and possibly very saturated.

Compatible with all the other commitments I already have, I would like to help in the enhancement of your project <Allegro.pas>: I think it's a really good project. Unfortunately I am also managing my projects and I have very little free time. As was said in ancient times: "Tempus fugit".

Otto.
Title: Re: Allegro.pas
Post by: furious programming on March 24, 2020, 05:23:03 pm
I will change the color palette.  I'm still working on it.  Green is because the allegator, but that color seems not to be friend with complementary (http://paletton.com/#uid=32t0f0kkagjcnp2gpkkokc-tB87). %)  Would change anytime.

You don't have to change the color palette, because green is a pleasant color. What bothers me is not very interesting design of the site, including careless margins and padding (too small). Just try not to make the site look old/primitive, because it will deter users. Minimalism, not primitives.

Quote
About code displaying, I agree that syntax highlighting will improve the reading, but the way the pages are build doesn't allow to do it (yet) as it doesn't allow HTML code.

You can generate pages, but you can manually insert HTML for source code. But I don't know where these restrictions come from — I don't know what you use to generate pages.

Quote
About uppercase keywords, sorry but I don't agree:  I find it easier to read even with syntax highlighting so I'll keep it (specially while syntax highlighting can't be applied).  Will not discuss anyway.

No no no... Virtually no one writes the code this way. Even FPC/Lazarus developers, despite many formatting styles, do not write keywords in capital letters. This is not a good technique.

If you create a project yourself and for yourself, you can write the source code as you like — after all, only you will be able to see it. However, if you create a common project (and the tutorial is it), you should adhere to common principles and promote practices considered by most as essential.

Most are described here — Object Pascal Style Guide (https://edn.embarcadero.com/article/10280) — please, read carefully and follow the rules.

Quote
And maybe you didn't notice, but Allegro is an amateur project. ::)

Yep, I know. The problem is you don't have to brag about it.

You must understand that the first impression is most important, that the appearance of the website and formatting of source code is very important. You have to think about what the user will think — otherwise all the work will be wasted, because so far the site doesn't encourage users to browse it.

Quote
That would allow me to hire a designer. :-[).

You don't need a designer. There are many different websites on the web, minimalistic, full of content and nice looking at the same time. Just look for the one you like, look at the sources how it is made and use a similar style. The very good example is the SFML website (https://www.sfml-dev.org) — see yourself.

Remember that I'm a fan of this project and I wish you the best — hence my posts in this thread. 8)
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on March 24, 2020, 07:30:51 pm
I must say I'm a very special person. My psychologist stated I may be the most astonishing Asperger he ever saw, and a friend of me (psychology student ::)) asked if she can open my skull to see how my brain works (and that was way before Dr. Farrah Fowler asked the same to Dr. Koothrappali, by the way). So if I sound I'm upset, I'm actually not.  I'm taking notes of everything.

So, thanks @Otto for the comments.  Don't worry, I know what is to have so many projects and almost no time.  %)

@winni, thanks. I take note and I'll try to make it better.

@furious programming, thanks too.  Really.  I knew about Borland style document when I used Delphi 6.  I should read it again to see what changed.  Then may be I update my own style document (yes, I have one, and everybody should).

I'll advance in other stuff but soon I'll make tests in my local server to see how MediaWiki works and change in the CSS.  Stay tuned. :)

[edit] Almost forgot, you have the web sources in the SVN repository (https://sourceforge.net/p/allegro-pas/code/HEAD/tree/WEBSITE/).  Yes, all custom PHP, I know. Please don't say it is bad idea and use a CMS and all that, I know.  I've developed tons of webpages for decades, I really don't trust in many 3th party PHP software, and AFAIK none of my webs have been cracked yet (remember, AFAIK) and I know they tried several times.
Title: Re: Allegro.pas
Post by: furious programming on March 25, 2020, 12:44:40 am
Almost forgot, you have the web sources in the SVN repository (https://sourceforge.net/p/allegro-pas/code/HEAD/tree/WEBSITE/).  Yes, all custom PHP, I know. Please don't say it is bad idea and use a CMS and all that, I know.

This is not a bad idea if you can do it and if the website works correct and efficiently. I prefer to browse hand-carved pages that work well than to vomit at the size and loading time of “modern” websites.  :D
Title: Re: Allegro.pas
Post by: furious programming on March 25, 2020, 07:23:17 pm
@Ñuño_Martínez: does this library support Windows XP? I tried to run this sample game Furious Paladin but during startup I received messagebox with error saying something is missing from the kernel32.dll library, witch is the system library. I used the latest version of allegro.pas and the included monolith dll.

So, is this OS supported?
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on March 26, 2020, 12:47:40 pm
In theory, it does, but MinGW (http://www.mingw.org/) dropped WinXP support few time ago;  so Allegro supports WinXP but MinGW doesn't.

I tried to download and install an older MinGW to compile Allegro but I wasn't able to find the latest version that support XP, and the MinGW package manager doesn't work properly (it was always buggy) so I downloaded a precompiled version available in Allegro's website.  Maybe that's the problem.
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on April 16, 2020, 01:25:28 pm
I did a bugfix release because I found a sily bug and I need the library shining this weekend (LudumDare!) and also in May (TINS (https://tins.amarillion.org/)!).  More details here (https://sourceforge.net/p/allegro-pas/news/2020/04/bugfix-release-allegropas-52%CE%B21-1/).
Title: Re: Allegro.pas
Post by: x2nie on October 21, 2020, 01:11:16 pm
Hi Ñuño_Martínez

I want to ask,
did I do a mistake or is it the normal, but the area of game is corrupted.

I followed the first tutorial of Allegro.Pas, and set
  Display := al_create_display (128, 128); 
so I expect that the area for game is a square (same width of sides)
but the result is not.

why?
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on October 24, 2020, 11:42:58 am
That's weird.  I did a test (Xubuntu) and works properly.  I assume you're using Windows 10.  Maybe it is a limitation that prevents it to create windows (displays) smaller than 160 pixel width.  I see some duplicated pixels that tells me it is scaling the output to fit the window.

Can you post/attach you code here?  Maybe there's something somewhere...
Title: Re: Allegro.pas
Post by: x2nie on October 25, 2020, 04:55:23 am

yes, I am using Windows 10.

Can you post/attach you code here?  Maybe there's something somewhere...


Code: Pascal  [Select][+][-]
  1.  
  2. PROGRAM HelloWorld;
  3. (* First Allegro program. *)
  4.  
  5.  
  6. USES
  7.   allegro5, al5font;
  8.  
  9.  
  10. VAR
  11.   Timer: ALLEGRO_TIMERptr;
  12.   Queue: ALLEGRO_EVENT_QUEUEptr;
  13.   Event: ALLEGRO_EVENT;
  14.   Display: ALLEGRO_DISPLAYptr;
  15.   Font: ALLEGRO_FONTptr;
  16.  
  17.  
  18.   Redraw, EndProgram: BOOLEAN;
  19.  
  20.  
  21. BEGIN
  22.   al_init;
  23.   al_install_keyboard;
  24.  
  25.  
  26.   Timer := al_create_timer (1 / 30);
  27.   Queue := al_create_event_queue;
  28.   Display := al_create_display (128, 128);
  29.   Font := al_create_builtin_font;
  30.  
  31.  
  32.   al_register_event_source (Queue, al_get_keyboard_event_source);
  33.   al_register_event_source (Queue, al_get_display_event_source (Display));
  34.   al_register_event_source (Queue, al_get_timer_event_source (Timer));
  35.  
  36.  
  37.   Redraw := TRUE;
  38.   EndProgram := FALSE;
  39.  
  40.  
  41.   al_start_timer (Timer);
  42.   REPEAT
  43.     al_wait_for_event (Queue, @Event);
  44.  
  45.  
  46.     IF Event.ftype = ALLEGRO_EVENT_TIMER THEN
  47.       Redraw := TRUE
  48.     ELSE
  49.       IF (Event.ftype = ALLEGRO_EVENT_KEY_DOWN) OR (Event.ftype = ALLEGRO_EVENT_DISPLAY_CLOSE) THEN
  50.         EndProgram := TRUE;
  51.  
  52.  
  53.     IF Redraw AND al_is_event_queue_empty (Queue) THEN
  54.     BEGIN
  55.       al_clear_to_color (al_map_rgb (255, 128, 64));
  56.       al_draw_text (Font, al_map_rgb (255, 255, 255), 16, 32, 0, 'Holla, World!');
  57.       al_flip_display;
  58.  
  59.  
  60.       Redraw := FALSE
  61.     END
  62.   UNTIL EndProgram;
  63.  
  64.  
  65.   al_destroy_font (Font);
  66.   al_destroy_display (Display);
  67.   al_destroy_timer (Timer);
  68.   al_destroy_event_queue (Queue)
  69. END.
  70.  
  71.  
  72.  
Title: Re: Allegro.pas
Post by: x2nie on October 25, 2020, 02:30:21 pm
Hi Yes! if I change the size larger than 160, the client size is then correct.


Thanks you!
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on October 30, 2020, 07:48:15 pm
I tested your code on Xubuntu Linux and it created the window of correct size.

I knew Windows had problems creating windows bigger than the desktop, but now I know it has small size limits.

Let me know about advances. :)
Title: Re: Allegro.pas
Post by: x2nie on November 09, 2020, 12:23:00 pm
Hi


during searching a way to work directly with allegro-bitmap,
suddenly I solve the yet unsolved problem : copy the allegro-bitmap content into byte array.
(see the below picture of the result.)


It also solve my own problem of how to directly modify the bitmap content.


here is to modified function
Code: Pascal  [Select][+][-]
  1. PROCEDURE Draw;
  2.   type
  3.     TByteArray = array [Word] of byte;
  4.     PByteArray = ^TByteArray;
  5.   VAR
  6.     x, y: SINGLE;
  7.     i,ix,iy,iw, ih , FormatSize : INTEGER;
  8.     FormatLock: ALLEGRO_PIXEL_FORMAT;
  9.     Screen, Temp: ALLEGRO_BITMAPptr;
  10.       Lock: ALLEGRO_LOCKED_REGIONptr;
  11.     Data: PByteArray;
  12.   BEGIN
  13.     iw := al_get_bitmap_width (Pattern);
  14.     ih := al_get_bitmap_height (Pattern);
  15.     al_set_blender (ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
  16.     al_clear_to_color (Background);
  17.     Screen := al_get_target_bitmap;
  18.  
  19.  
  20.     SetXY (8, 8);
  21.  
  22.  
  23.   { Test 1. }
  24.   { /* Disabled: drawing to same bitmap is not supported. }
  25.   (*
  26.     Print ('Screen -> Screen (%.1f fps)', get_fps(0));
  27.     get_xy(&x, &y);
  28.     al_draw_bitmap(ex.Pattern, x, y, 0);
  29.  
  30.  
  31.     start_timer(0);
  32.     al_draw_bitmap_region(screen, x, y, iw, ih, x + 8 + iw, y, 0);
  33.     stop_timer(0);
  34.     SetXY (x, y + ih);
  35.    *)
  36.  
  37.  
  38.   { Test 2. }
  39.     Print ('Screen -> Bitmap -> Screen (%.1f fps)', [GetFPS (1)]);
  40.     GetXY (x, y);
  41.     al_draw_bitmap (Pattern, x, y, 0);
  42.  
  43.  
  44.     Temp := al_create_bitmap (iw, ih);
  45.     al_set_target_bitmap (Temp);
  46.     al_clear_to_color (Red);
  47.     StartTimer (1);
  48.     al_draw_bitmap_region (Screen, x, y, iw, ih, 0, 0, 0);
  49.  
  50.  
  51.     al_set_target_bitmap (Screen);
  52.     al_draw_bitmap (Temp, x + 8 + iw, y, 0);
  53.     StopTimer (1);
  54.     SetXY (x, y + ih);
  55.  
  56.  
  57.     al_destroy_bitmap (Temp);
  58.  
  59.  
  60.   { Test 3. }
  61.     Print ('Screen -> Memory -> Screen (%.1f fps)', [getfps (2)]);
  62.     GetXY (x, y);
  63.     al_draw_bitmap (Pattern, x, y, 0);
  64.  
  65.  
  66.     al_set_new_bitmap_flags (ALLEGRO_MEMORY_BITMAP);
  67.     Temp := al_create_bitmap (iw, ih);
  68.     al_set_target_bitmap (Temp);
  69.     al_clear_to_color (Red);
  70.     StartTimer (2);
  71.     al_draw_bitmap_region (Screen, x, y, iw, ih, 0, 0, 0);
  72.  
  73.  
  74.     al_set_target_bitmap (Screen);
  75.     al_draw_bitmap (Temp, x + 8 + iw, y, 0);
  76.     StopTimer (2);
  77.     SetXY (x, y + ih);
  78.  
  79.  
  80.     al_destroy_bitmap (Temp);
  81.     al_set_new_bitmap_flags (ALLEGRO_VIDEO_BITMAP);
  82.  
  83.  
  84.  
  85.  
  86. (*
  87.   Disabled because the "memcpy".  I tried it but I never used 'memcpy' on C nor
  88.   pointers on Pascal so I don't know how to translate it. *)
  89.  
  90.  
  91.    { Test 4. }
  92.     Print ('Screen -> Locked -> Screen (%.1f fps)', [getfps(3)]);
  93.     getxy(x, y);
  94.     al_draw_bitmap(Pattern, x, y, 0);
  95.  
  96.  
  97.     StartTimer (3);
  98.     ix := round(x);
  99.     iy := round(y);
  100.     lock := al_lock_bitmap_region(Screen, ix, iy, iw, ih,
  101.       ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY);
  102.     FormatLock := ALLEGRO_PIXEL_FORMAT(lock.format);
  103.     FormatSize := lock.pixel_size;
  104.     data := AllocMem(FormatSize * iw * ih);
  105.     for i := 0 to ih -1 do
  106.        move(PByteArray(lock.data)[ + i * lock.pitch],
  107.        data[ + i * FormatSize * iw],
  108.  
  109.  
  110.        FormatSize * iw
  111.          );
  112.  
  113.  
  114.     al_unlock_bitmap(Screen);
  115.  
  116.  
  117.    lock := al_lock_bitmap_region(Screen, ix + 8 + iw, iy, iw, ih, FormatLock,
  118.       ALLEGRO_LOCK_WRITEONLY);
  119.    for i := 0 to  ih-1 do
  120.       move(data[ + i * FormatSize * iw],
  121.          PByteArray(lock.data)[ + i * lock.pitch],
  122.          FormatSize * iw);
  123.    al_unlock_bitmap(Screen);
  124.    freeMem(data);
  125.    StopTimer (3);
  126.     SetXY (x, y + ih);
  127.  
  128.   END;


-- I am sorry for the bad lines indentation
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on November 09, 2020, 07:27:08 pm
Nice.  I'll take a look.

[Edit] Tested but it throws a Range check error.

Tempted to upload it as a branch at SourceForge's Subversion or at GitHub. Btw, if you use GitHub you can fork it and later I can merge (or do a pull request, I'm not sure if it's the same thing).

Anyway I see what I was doing wrong:  The move procedure have the parameters in different order than memcpy.  Thanks for the tip.
Title: Re: Allegro.pas
Post by: x2nie on November 24, 2020, 07:53:55 am
hi! with Range (-Cr) debug option checked, the error is by type array insufficient:
Code: Pascal  [Select][+][-]
  1. TByteArray = array[Word] of byte;


now, by giving larger array range, the error has gone:
Code: Pascal  [Select][+][-]
  1. TByteArray = array [0..MaxInt-1] of byte;


Something else is same as before (except the indent lines for beautify purpose)
the complete code:
Code: Pascal  [Select][+][-]
  1. PROCEDURE Draw;
  2.   type
  3.   TByteArray = array [0..MaxInt-1] of byte;
  4.   PByteArray = ^TByteArray;
  5.   VAR
  6.     x, y: SINGLE;
  7.     i,ix,iy,iw, ih , FormatSize : INTEGER;
  8.     FormatLock: ALLEGRO_PIXEL_FORMAT;
  9.     Screen, Temp: ALLEGRO_BITMAPptr;
  10.       Lock: ALLEGRO_LOCKED_REGIONptr;
  11.     Data: PByteArray;
  12.   BEGIN
  13.     iw := al_get_bitmap_width (Pattern);
  14.     ih := al_get_bitmap_height (Pattern);
  15.     al_set_blender (ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
  16.     al_clear_to_color (Background);
  17.     Screen := al_get_target_bitmap;
  18.  
  19.  
  20.     SetXY (8, 8);
  21.  
  22.  
  23.   { Test 1. }
  24.   { /* Disabled: drawing to same bitmap is not supported. }
  25.   (*
  26.     Print ('Screen -> Screen (%.1f fps)', get_fps(0));
  27.     get_xy(&x, &y);
  28.     al_draw_bitmap(ex.Pattern, x, y, 0);
  29.  
  30.  
  31.     start_timer(0);
  32.     al_draw_bitmap_region(screen, x, y, iw, ih, x + 8 + iw, y, 0);
  33.     stop_timer(0);
  34.     SetXY (x, y + ih);
  35.    *)
  36.  
  37.  
  38.   { Test 2. }
  39.     Print ('Screen -> Bitmap -> Screen (%.1f fps)', [GetFPS (1)]);
  40.     GetXY (x, y);
  41.     al_draw_bitmap (Pattern, x, y, 0);
  42.  
  43.  
  44.     Temp := al_create_bitmap (iw, ih);
  45.     al_set_target_bitmap (Temp);
  46.     al_clear_to_color (Red);
  47.     StartTimer (1);
  48.     al_draw_bitmap_region (Screen, x, y, iw, ih, 0, 0, 0);
  49.  
  50.  
  51.     al_set_target_bitmap (Screen);
  52.     al_draw_bitmap (Temp, x + 8 + iw, y, 0);
  53.     StopTimer (1);
  54.     SetXY (x, y + ih);
  55.  
  56.  
  57.     al_destroy_bitmap (Temp);
  58.  
  59.  
  60.   { Test 3. }
  61.     Print ('Screen -> Memory -> Screen (%.1f fps)', [getfps (2)]);
  62.     GetXY (x, y);
  63.     al_draw_bitmap (Pattern, x, y, 0);
  64.  
  65.  
  66.     al_set_new_bitmap_flags (ALLEGRO_MEMORY_BITMAP);
  67.     Temp := al_create_bitmap (iw, ih);
  68.     al_set_target_bitmap (Temp);
  69.     al_clear_to_color (Red);
  70.     StartTimer (2);
  71.     al_draw_bitmap_region (Screen, x, y, iw, ih, 0, 0, 0);
  72.  
  73.  
  74.     al_set_target_bitmap (Screen);
  75.     al_draw_bitmap (Temp, x + 8 + iw, y, 0);
  76.     StopTimer (2);
  77.     SetXY (x, y + ih);
  78.  
  79.  
  80.     al_destroy_bitmap (Temp);
  81.     al_set_new_bitmap_flags (ALLEGRO_VIDEO_BITMAP);
  82.  
  83.  
  84.  
  85.  
  86. (*
  87.   Disabled because the "memcpy".  I tried it but I never used 'memcpy' on C nor
  88.   pointers on Pascal so I don't know how to translate it. *)
  89.  
  90.  
  91.    { Test 4. }
  92.     Print ('Screen -> Locked -> Screen (%.1f fps)', [getfps(3)]);
  93.     getxy(x, y);
  94.     al_draw_bitmap(Pattern, x, y, 0);
  95.  
  96.  
  97.     StartTimer (3);
  98.     ix := round(x);
  99.     iy := round(y);
  100.     lock := al_lock_bitmap_region(Screen, ix, iy, iw, ih,
  101.       ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY);
  102.     FormatLock := ALLEGRO_PIXEL_FORMAT(lock.format);
  103.     FormatSize := lock.pixel_size;
  104.     data := AllocMem(FormatSize * iw * ih);
  105.     for i := 0 to ih -1 do
  106.        move(
  107.           PByteArray(lock.data)[ i * lock.pitch],
  108.           data[ i * FormatSize * iw],
  109.           FormatSize * iw
  110.        );
  111.  
  112.  
  113.     al_unlock_bitmap(Screen);
  114.  
  115.  
  116.    lock := al_lock_bitmap_region(Screen, ix + 8 + iw, iy, iw, ih, FormatLock,
  117.       ALLEGRO_LOCK_WRITEONLY);
  118.    for i := 0 to  ih-1 do
  119.       move(
  120.          data[ i * FormatSize * iw],
  121.          PByteArray(lock.data)[ i * lock.pitch],
  122.          FormatSize * iw
  123.       );
  124.  
  125.  
  126.    al_unlock_bitmap(Screen);
  127.    freeMem(data);
  128.    StopTimer (3);
  129.    SetXY (x, y + ih);
  130.  
  131.  
  132.   END;
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on December 08, 2020, 01:13:05 pm
Sorry for the time without answering, but I had a bad month.

That wasn't the problem.  The problem is that my graphics card stores the textures upside-down, so pitch is negative, so results in a negative index witch is out of range (all indexes must be positive).  Fix is to use a pointer instead of array, since the Lock.data points to the top-left corner of the bitmap (doesn't matter if it stored upside-up or -down).

I've commit the fix (https://sourceforge.net/p/allegro-pas/code/474/), including credits to your work (if you want to change it, let me know).
Title: Re: Allegro.pas
Post by: x2nie on December 12, 2020, 03:06:39 pm
Hi Nuno,
Your modification doesn't work.  >:D  (I have checkout the svn trunk repository).
at least didn't properly work on my machine.
** But, thanks for including my name in credit.  8-) Thats great, perhaps someday my son read it. :-X
--------------------------


However, after tried several scenario, the solution is quite simple....

The error was runtime "SIGSENV" without Lazarus prefer into which line of code the problem is being executed.
Well, years ago I have had bad day experience when porting C code into pascal, especially in copying array of bytes with pointer addressing.
-
I wonder how the code is working well in your side:
Code: Pascal  [Select][+][-]
  1. move (
  2.         ScreenData,
  3.         BitmapData[i * FormatSize * iw],
  4.         FormatSize * iw
  5.       )


but the only working code in my Lazarus Win10 32bit is by make the first array explicitly as the pointer address. like this:
Code: Pascal  [Select][+][-]
  1. move (
  2.         ScreenData[0],
  3.         BitmapData[i * FormatSize * iw],
  4.         FormatSize * iw
  5.       )



Now, the complete code (partially) is :
Code: Pascal  [Select][+][-]
  1. { Test 4. }
  2.     Print ('Screen -> Locked -> Screen (%.1f fps)', [GetFPS(3)]);
  3.     GetXY (x, y);
  4.     al_draw_bitmap (Pattern, x, y, 0);
  5.  
  6.  
  7.     StartTimer (3);
  8.  
  9.  
  10.     ix := Round (x); iy := Round (y);
  11.     Lock := al_lock_bitmap_region (
  12.       Screen,
  13.       ix, iy, iw, ih,
  14.       ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY
  15.     );
  16.     FormatLock := ALLEGRO_PIXEL_FORMAT (Lock.format);
  17.     FormatSize := Lock.pixel_size;
  18.     BitmapData := AllocMem (FormatSize * iw * ih);
  19.     FOR i := 0 TO ih - 1 DO
  20.     BEGIN
  21.     { Lock.pitch may be negative (i.e. graphics card stores textures upside down)
  22.       so indexes can't be used here as only positive values can be used.
  23.       So use pointers.
  24.     }
  25.       ScreenData := Lock.Data + (i * Lock.pitch);
  26.       move (
  27.         ScreenData[0],
  28.         BitmapData[i * FormatSize * iw],
  29.         FormatSize * iw
  30.       )
  31.     END;
  32.     al_unlock_bitmap (Screen);
  33.  
  34.  
  35.     Lock := al_lock_bitmap_region (
  36.       Screen,
  37.       ix + 8 + iw, iy, iw, ih,
  38.       FormatLock, ALLEGRO_LOCK_WRITEONLY
  39.     );
  40.     FOR i := 0 TO ih - 1 DO
  41.     BEGIN
  42.       ScreenData := Lock.Data + (i * Lock.pitch);
  43.       move (
  44.         BitmapData[i * FormatSize * iw],
  45.         ScreenData[0],
  46.         FormatSize * iw
  47.       )
  48.     END;
  49.     al_unlock_bitmap (Screen);
  50.     FreeMem (BitmapData);
  51.  
  52.  
  53.     StopTimer (3);    


It works fine with all valgrind,I/O, Range Check,Stack & Overflow assertions set on.
---------


Anyway, now I knew the reason of why the copying bitmap data is done in a loop (like the ex_blit.c does too), since we can also to copy the whole data at glance. That it because in some graphic card the data is upside down.
Thanks you
Title: Re: Allegro.pas
Post by: Ñuño_Martínez on December 13, 2020, 12:57:38 pm
Your new fix works for me as well. :) Now I have to test it on Delphi (first I have to upgrade my license %))

I'm curious what's your system.  Mine is Xubuntu/Linux 20.04.1, fpc 3.2.0.
TinyPortal © 2005-2018