Recent

Author Topic: Allegro.pas  (Read 19718 times)

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1072
    • Burdjia
Re: Allegro.pas
« Reply #45 on: March 26, 2020, 12:47:40 pm »
In theory, it does, but MinGW 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.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1072
    • Burdjia
Re: Allegro.pas
« Reply #46 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!).  More details here.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

x2nie

  • Sr. Member
  • ****
  • Posts: 487
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Allegro.pas
« Reply #47 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?
When you were logged in, you can see attachments.
Lazarus Trunk @ Windows7 64bit, XP 32bit, Debian under VirtualMachine

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1072
    • Burdjia
Re: Allegro.pas
« Reply #48 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...
« Last Edit: October 24, 2020, 11:46:00 am by Ñuño_Martínez »
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

x2nie

  • Sr. Member
  • ****
  • Posts: 487
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Allegro.pas
« Reply #49 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.  
« Last Edit: October 25, 2020, 05:35:35 am by x2nie »
When you were logged in, you can see attachments.
Lazarus Trunk @ Windows7 64bit, XP 32bit, Debian under VirtualMachine

x2nie

  • Sr. Member
  • ****
  • Posts: 487
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Allegro.pas
« Reply #50 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!
When you were logged in, you can see attachments.
Lazarus Trunk @ Windows7 64bit, XP 32bit, Debian under VirtualMachine

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1072
    • Burdjia
Re: Allegro.pas
« Reply #51 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. :)
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

x2nie

  • Sr. Member
  • ****
  • Posts: 487
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Allegro.pas
« Reply #52 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
When you were logged in, you can see attachments.
Lazarus Trunk @ Windows7 64bit, XP 32bit, Debian under VirtualMachine

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1072
    • Burdjia
Re: Allegro.pas
« Reply #53 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.
« Last Edit: November 09, 2020, 08:02:17 pm by Ñuño_Martínez »
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

x2nie

  • Sr. Member
  • ****
  • Posts: 487
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Allegro.pas
« Reply #54 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;
When you were logged in, you can see attachments.
Lazarus Trunk @ Windows7 64bit, XP 32bit, Debian under VirtualMachine

 

TinyPortal © 2005-2018