Hi guys..
I have been trying to load dat file in a pack file...but i couldn't able to do it..though..after much fiddling..i could able to load a bitmap in packfile..so..could you guys..please tell me how to load dat file in a packfile..
1 | |
2 | #include <allegro.h> |
3 | |
4 | PACKFILE *pf; |
5 | BITMAP *bmp; |
6 | |
7 | void set_graphic(); |
8 | void make_memory(); |
9 | void load_file_pf(); |
10 | void load_pf_bmp(); |
11 | void show_bmp(); |
12 | void free_memory(); |
13 | |
14 | int main(int argc, char *argv[]) |
15 | { |
16 | allegro_init(); |
17 | install_keyboard(); |
18 | |
19 | set_graphic(); |
20 | |
21 | make_memory(); |
22 | |
23 | load_file_pf(); |
24 | |
25 | load_pf_bmp(); |
26 | |
27 | show_bmp(); |
28 | |
29 | free_memory(); |
30 | |
31 | return 0; |
32 | } |
33 | END_OF_MAIN() |
34 | |
35 | void set_graphic() |
36 | { |
37 | set_color_depth(32); |
38 | set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); |
39 | |
40 | } |
41 | |
42 | void make_memory() |
43 | { |
44 | bmp = create_bitmap(SCREEN_W, SCREEN_H); |
45 | clear(bmp); |
46 | } |
47 | |
48 | void load_file_pf() |
49 | { |
50 | pf = pack_fopen ("frog.bmp", F_READ); |
51 | if(!pf) { |
52 | allegro_message("could not read bitmap file!"); |
53 | exit(1); |
54 | } |
55 | } |
56 | |
57 | void load_pf_bmp() |
58 | { |
59 | bmp = load_bmp_pf(pf, NULL); |
60 | if(!bmp) { |
61 | allegro_message("Error in loading pf into bmp!"); |
62 | exit(2); |
63 | } |
64 | } |
65 | |
66 | void show_bmp() |
67 | { |
68 | vsync(); |
69 | blit(bmp, screen, 0, 0, 100, 100, SCREEN_W, SCREEN_H); |
70 | readkey(); |
71 | } |
72 | |
73 | void free_memory() |
74 | { |
75 | pack_fclose(pf); |
76 | destroy_bitmap(bmp); |
77 | } |
You could simply put the bitmap in a datafile and use global compression.
Regards
You seriously need to read the manual. It looks like you have no idea what you're talking about. I have neither but if I made a wild guess, I'd say you're looking for this function: DATAFILE *load_datafile_object(const char *filename, const char *objectname);
You use it like this (probably):
DATAFILE *object = load_datafile_object("datafile.dat", "MYBITMAP"); if (object != 0) { BITMAP *bmp = (BITMAP *)object->dat; }
Of course I could be wrong and this is not what you're asking about. It's hard to tell from your post...
hi guys..
i already know how to put bitmap into dat file and know how to load object of dat file...but only thing i am looking for is some specific PACKFILE routines from where you can load dat file and blit it. For example..in my code i used:
pf = pack_fopen ("frog.bmp", F_READ);
which i guess..reads a bitmap file from disk and puts it into compressed packfile..rite..so..like that..i am looking for packfile routine..which loads a datfile...assuming..there must be a PACKFILE routine for such thing...!
Miran:
i guess.urs code only loads object of datfile and puts it into bmp..and then blit it..rite...so there is no mention of any PACKFILE routines...hope you guys know what i am looking for in particular....
Regards
hope you guys know what i am looking for in particular....
No.
But why is load_bitmap() not good enough for you?
EDIT: Or you could use BITMAP *load_bmp_pf(PACKFILE *f, RGB *pal);
When I said you seriously need to read the manual, I was serious. This is all in there.
EDIT: Or you could use
BITMAP *load_bmp_pf(PACKFILE *f, RGB *pal);
He does. He's asking for something similar for datafiles.
The answer is, there's no need. pack_fopen doesn't load the file into memory. It buffers a small bit of the file (about 4K) for slightly quicker access, but it's still read from disk as-needed. Given your code, there's no reason not to use load_bitmap, or load_datafile[_object].
When I said you seriously need to read the manual, I was serious. This is all in there.
i have been reading manual very carefully...Before coming here..i always..reads manual...n..if i couldn't able to understand it..then i come here for you guys help..
load_bitmap()
it is good enough for me...however..i just wanted to learn PACKFILE concept..so..i wrote the code to load bitmap using PACKFILE..and when i tried to load datfile using PACKFILE...i am finding hard to find any PACKFILE ROUTINE to load datfile...now..it seems like there aren't any PACKFILE ROUTINE to load datfile...disappointed...!
BITMAP *load_bmp_pf(PACKFILE *f, RGB *pal);
i already used it in my first post...you can find it in the function
void load_pf_bmp() in my code...
thanks anyway....
Ah, now I get it. Well, the load_datafile() function as far as I know internally uses the packfile routines, so what you're looking for wouldn't really make much sense.
and when i tried to load datfile using PACKFILE...i am finding hard to find any PACKFILE ROUTINE to load datfile...now..it seems like there aren't any PACKFILE ROUTINE to load datfile...disappointed...!
Because, again, there's no need for them, if you need a compressed datafile, just create a compressed one with grabber and load it normally with load_datafile.
Do you understand what a packfile really is? Basically, it's just a plain vanilla libc FILE*, with a few extra features:
- PACKFILE supports endian-safe reading across all supported platforms. Using pack_mgetw() for example will correctly load a Motorola-aligned short from the same file on all platforms.
- PACKFILE supports compressed file i/o, using a special "magic" byte sequence at the start of a file, and the appropriate flag when opening a file. After opening a compressed file, the PACKFILE* pointer will behave like a normal one, except that the data is compressed on disk.
A DATAFILE is allegro's implementation of a resource file. It is organized in chunks, each of which can hold an object of various types. The datafile routines internally use the packfile API for i/o, but you don't need to know this.
So for all datafiles (files that you created using grabber or dat), use the datafile api. For all other files, use the packfile api.