Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » convert from hbitmap to bitmap? allegro 4.9.19

This thread is locked; no one can reply to it. rss feed Print
convert from hbitmap to bitmap? allegro 4.9.19
Desmond Taylor
Member #11,943
May 2010
avatar

I know how to read the resource files. I have had help with this before but that was for allegro 4.2.2 and now I am using allegro 4.9.19.

I was wondering if any of you guys know how to do this as the last one called <allegro.h> from the old one.

Edit:
I have just tried LennyLen's script can be found here http://www.allegro.cc/forums/thread/604022 and as I thought, it didn't work for allegro 4.9.19. I am gonna look at his code later to see if there is anything in threre I can update so that it works with the new release of allegro.

Thomas Fjellstrom
Member #476
June 2000
avatar

You'd need to convert all of the Allegro 4 api calls to Allegro 5 api calls.

It probably won't be hard, but it may take some time to learn the new api.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Desmond Taylor
Member #11,943
May 2010
avatar

You'd need to convert all of the Allegro 4 api calls to Allegro 5 api calls.

Dammit ;D, Gonna have to learn alot then. I have a basic sprite moving arround the screen with keyboard events at the moement. I have bookmarked this http://alleg.sourceforge.net/a5docs/refman/index.html so that I can learn new calls. I don't seem to find packfile tho.

Can packfiles be read from allegro 5?

Thomas Fjellstrom
Member #476
June 2000
avatar

Can packfiles be read from allegro 5?

That code just uses PACKFILEs as regular files, so yes. You can use the new "File I/O" api. It provides everything and more that the old api did (except built in compression, you need to use an addon like physfs, or zlib manually to get that).

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Desmond Taylor
Member #11,943
May 2010
avatar

That code just uses PACKFILEs as regular files, so yes. You can use the new "File I/O" api. It provides everything and more that the old api did (except built in compression, you need to use an addon like physfs, or zlib manually to get that).

I will look into that now. I really need to use allegro 5 with my project as I'm trying to make an Endless Online clone.

LennyLen
Member #5,313
December 2004
avatar

Converting my code from A4 to A5 should be pretty easy. It uses the A4 packfile routines, but it's not loading from a packfile but from a regular file. I used the packfile routines to ensure that the correct endianness would be used on all platforms.

In most the A4 command name can be just substituted with the A5 one:

pack_fopen() -> al_fopen(), pack_igetw() -> al_fread16le(), pack_igetl() -> al_fread32le(), pack_getc -> al_fgetc

edit: Oops, accidentally clicked Add reply before I'd finished.

The pack_fseek() calls can be replaced by al_fseek() calls, but you'll need to add a third parameter (which in all cases will be ALLEGRO_SEEK_SET).

Likewise, create_bitmap() calls will need to be replaced with al_create_bitmap() and putpixel() with al_put_pixel(), etc. Mostly it's just going to be the file IO commands that need replacing, since they make up the bulk of the code.

If I have some time this morning, I'll try converting it all over to A5 myself. It should be a bit quicker for me to do it since I'm familiar with the original code.

Desmond Taylor
Member #11,943
May 2010
avatar

Cheers LennyLen, I will keep an eye out for your A5 version. I'm definatly gonna add you to the credits for doing this.

I tried to convert it but failed ;D!

LennyLen
Member #5,313
December 2004
avatar

I've attached the A5 version.

Here's an example of using it:

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro5.h> 3#include <allegro5/allegro_image.h> 4#include <al_load_PE_bmp.h> 5 6 7void abort_example(char const *format, ...) 8{ 9 va_list args; 10 va_start(args, format); 11 vfprintf(stderr, format, args); 12 va_end(args); 13 exit(1); 14} 15 16 17int main() 18{ 19 ALLEGRO_DISPLAY *display; 20 ALLEGRO_TIMER *timer; 21 ALLEGRO_EVENT_QUEUE *queue; 22 bool redraw = true; 23 24 if (!al_init()) { 25 abort_example("Could not init Allegro.\n"); 26 return 1; 27 } 28 29 al_install_mouse(); 30 al_install_keyboard(); 31 32 display = al_create_display(640, 480); 33 if (!display) { 34 abort_example("Error creating display\n"); 35 } 36 37 al_set_window_title("Testing al_load_PE_bmp"); 38 39 al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); 40 ALLEGRO_BITMAP *bitmap; 41 bitmap = load_PE_bmp("gfx025.egf", 1); 42 if (!bitmap) { 43 abort_example("Error loading image - %s", load_PE_bmp_error()); 44 } 45 al_set_new_bitmap_flags(0); 46 47 timer = al_install_timer(1.0 / 30); 48 queue = al_create_event_queue(); 49 al_register_event_source(queue, al_get_keyboard_event_source()); 50 al_register_event_source(queue, al_get_display_event_source(display)); 51 al_register_event_source(queue, al_get_timer_event_source(timer)); 52 al_start_timer(timer); 53 54 al_set_target_bitmap(al_get_backbuffer()); 55 56 while (1) { 57 ALLEGRO_EVENT event; 58 al_wait_for_event(queue, &event); 59 if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) 60 break; 61 if (event.type == ALLEGRO_EVENT_KEY_DOWN) { 62 if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) 63 break; 64 } 65 if (event.type == ALLEGRO_EVENT_TIMER) 66 redraw = true; 67 68 if (redraw && al_event_queue_is_empty(queue)) { 69 redraw = false; 70 al_clear_to_color(al_map_rgb_f(0, 0, 0)); 71 al_draw_bitmap(bitmap, 0, 0, 0); 72 al_flip_display(); 73 } 74 } 75 76 al_destroy_bitmap(bitmap); 77 78 return 0; 79}

Desmond Taylor
Member #11,943
May 2010
avatar

Dude your a star, That should get me working on my project again, I had to use resource hacker to get the bitmaps juat to develop now to edit my code and use the resource files itself. That will be easier since I'm making an Endless Online clone project. Hence the *.EGF files.

Custom map files.
Custom server.
Custom Client.
Custom map editor.

It's gonna be a very big project :D

EDIT:
I was just wondering why was you using it for *.EGF files? ???

EDIT 2
There is a problem with the archive. Could you re-attach?

#SelectExpand
1! C:\Users\Desmond Taylor\Desktop\Web Downloads\al_load_PE_bmp.rar: CRC failed in load_PE_bmp.c. The file is corrupt 2! C:\Users\Desmond Taylor\Desktop\Web Downloads\al_load_PE_bmp.rar: Unexpected end of archive

LennyLen
Member #5,313
December 2004
avatar

One thing I'd suggest you do is extract all the graphics from the .egf files and either store them in directories, or in a more sensible archive format. Since you're working on a clone rather than a EO tool, you don't need to keep them in .bmp format either, so you can convert them to PNG to save space.

edit: I reattached the archive in .zip format. For some reason, any .rar files I upload here seem to get corrupted.

edit2: I've never used .egf files myself (the whole idea of using a portable executable to store images seems absurd to me). I wrote those functions for someone who was making an EO map editor.

Desmond Taylor
Member #11,943
May 2010
avatar

LennyLen said:

One thing I'd suggest you do is extract all the graphics from the .egf files and either store them in directories, or in a more sensible archive format. Since you're working on a clone rather than a EO tool, you don't need to keep them in .bmp format either, so you can convert them to PNG to save space.

The reason I'm using the Endless Online egf files is because I cannot distribute the egf files with the game. I will have to give instructions on where to download them as Arvid will have a hissy fit on me. He is very proud of his artwork and won't give permission to use it.

If I tell people to download the original EO Client from the official site and rip the GFX he can't have me for it ;D! Vult-r don't care about anyone re-making the game it's just Arvid with his GFX.

EDIT:
Thanks dude, I have it extracted this time.

Ahh, Sausage is making a map editor but he's using allegro 5. I have his source code but his conversion makes no sence to me at all. His code is also like

#SelectExpand
1al::draw_bitmap();

I dont get how he made it point like a class but hey.

EDIT 2:
I have modified you load_PE_bmp.c file and took out.

#SelectExpand
1al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);

as it made my FPS suck. Without that line it does the job alot faster and without loosing framerate.

Charles Pharis
Member #11,946
May 2010

Desmond if you want to know how Sausage is making his into classes then download his eoserv source and take a look at it again. I am pretty sure he used a lot of class developing just like that in there.

Desmond Taylor
Member #11,943
May 2010
avatar

I already know how he did it. You could have said that last night on MSN ;D

Charles Pharis
Member #11,946
May 2010

Well you was busy and i was already rambling on. I still haven't been to sleep. That shot I got really did keep me up all night. I go to school in 2 and a half hours.

Srry about going off topic.

LennyLen
Member #5,313
December 2004
avatar

as it made my FPS suck. Without that line it does the job alot faster and without loosing framerate.

Yes, it will definitely work faster if stored as a display bitmap instead of a memory bitmap, which is why I would suggest anyone who uses the current code converts it to a video bitmap as soon as possible. The reason I load it into a memory bitmap however, is so that the function can load images that are larger than the maximum texture size. As far as I know, none of the EO graphics come anywhere near this size, but if it gets used to load graphics from modded .egf files, these possibly could be large enough. So as a matter of robustness, I'm only using memory bitmaps.

Charles Pharis
Member #11,946
May 2010

How would you have to go about converting it? Cause when I look at it, I just kinda stare and wonder what everything does. ;D

I bet that if I actually sat down and looked at everything for awhile I could get close.

Desmond Taylor
Member #11,943
May 2010
avatar

where it says

#SelectExpand
1al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);

Change with

#SelectExpand
1al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);

or keep it as it is and clone it to a VIDEO BITMAP like I did

LennyLen
Member #5,313
December 2004
avatar

I've highlighted here how to convert the memory bitmap returned by my function to a video bitmap.

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro5.h> 3#include <allegro5/allegro_image.h> 4#include <al_load_PE_bmp.h> 5 6 7void abort_example(char const *format, ...) 8{ 9 va_list args; 10 va_start(args, format); 11 vfprintf(stderr, format, args); 12 va_end(args); 13 exit(1); 14} 15 16 17int main() 18{ 19 ALLEGRO_DISPLAY *display; 20 ALLEGRO_TIMER *timer; 21 ALLEGRO_EVENT_QUEUE *queue; 22 bool redraw = true; 23 24 if (!al_init()) { 25 abort_example("Could not init Allegro.\n"); 26 return 1; 27 } 28 29 al_install_mouse(); 30 al_install_keyboard(); 31 32 display = al_create_display(640, 480); 33 if (!display) { 34 abort_example("Error creating display\n"); 35 } 36 37 al_set_window_title("Testing al_load_PE_bmp"); 38 39 al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); 40 ALLEGRO_BITMAP *membitmap; 41 membitmap = load_PE_bmp("gfx025.egf", 1); 42 if (!membitmap) { 43 abort_example("Error loading image - %s", load_PE_bmp_error()); 44 } 45
46 al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
47 ALLEGRO_BITMAP *bitmap = al_clone_bitmap(membitmap);
48 49 timer = al_install_timer(1.0 / 30); 50 queue = al_create_event_queue(); 51 al_register_event_source(queue, al_get_keyboard_event_source()); 52 al_register_event_source(queue, al_get_display_event_source(display)); 53 al_register_event_source(queue, al_get_timer_event_source(timer)); 54 al_start_timer(timer); 55 56 al_set_target_bitmap(al_get_backbuffer()); 57 58 while (1) { 59 ALLEGRO_EVENT event; 60 al_wait_for_event(queue, &event); 61 if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) 62 break; 63 if (event.type == ALLEGRO_EVENT_KEY_DOWN) { 64 if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) 65 break; 66 } 67 if (event.type == ALLEGRO_EVENT_TIMER) 68 redraw = true; 69 70 if (redraw && al_event_queue_is_empty(queue)) { 71 redraw = false; 72 al_clear_to_color(al_map_rgb_f(0, 0, 0)); 73 al_draw_bitmap(membitmap, 0, 0, 0); 74 al_flip_display(); 75 } 76 } 77 78 al_destroy_bitmap(bitmap); 79 al_destroy_bitmap(membitmap); 80 81 return 0; 82}

Go to: