|
VS2010:how to put bmps in rcs and use them |
jhetfield21
Member #12,379
November 2010
|
Hi, Can sb help me?If there's another way to embed packaged data(the bmps) in the final exe it would be also be good. EDIT 1:I've also made a .resx file if that helps(so far it hasn't helped me but you never know).
|
LennyLen
Member #5,313
December 2004
|
I've attached code for loading BMPs from .exe files, provided you know the ID number of the BMP. I've only ever used it with MinGW, but it should compile fine with MSVC as well. It's pretty straightforward to use: 1#include <allegro.h>
2#include <load_PE_bmp.h>
3
4int main() {
5
6 allegro_init();
7 install_keyboard();
8
9 set_color_depth(32);
10 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
11
12 BITMAP *test = load_PE_bmp("program.exe", 108);
13 if (!test) {
14
15 allegro_message("%s", load_PE_bmp_error());
16 return -1;
17
18 }
19
20 blit(test, screen, 0, 0, 100, 100, test->w, test->h);
21
22 while (!key[KEY_ESC]) {}
23
24 return 0;
25
26}
27END_OF_MAIN()
The version I attached is for Allegro 4. I did write a version for A5, but it no longer compiles, and I haven't had a chance to see what changes need to be made to get it to compile with the new RC1 release. I can still provide the code if you want to attempt to update it yourself. I still haven't added 8bit (or less) BMP support either, so it only works for 16, 24 and 32 bit images.
|
jhetfield21
Member #12,379
November 2010
|
well tried load_PE_bmp lib but failed.
|
LennyLen
Member #5,313
December 2004
|
jhetfield21 said: Since I can't put the bmps inside the program's exe I wanted to put them into an .rc or a .resx that VS supports and load them from that file into the application. I can't help you there then sorry, it's not something I ever wanted to do.
|
Thomas Fjellstrom
Member #476
June 2000
|
The point of .rc files is to embed resources into exe's or DLLs. Not doing so, is a bit strange. -- |
KnightWhoSaysNi
Member #7,339
June 2006
|
Why not just make an allegro program to get the colors of each pixel and then save it how a 2d array would be written in whatever language you're using. You can put this in a source file and then convert the 2d array to a bitmap. |
jhetfield21
Member #12,379
November 2010
|
Knight if you could provide an example nothing fancy cause at this point I'm out of ideas. Also Thomas I know that the point of rcs are to be embedded what I meant by cant embed the bmps was as they were without packaging them.My problem is that after putting them into a resource file(be it a rc or a resx) I can't figure out how to load the bmps from it.
|
Thomas Fjellstrom
Member #476
June 2000
|
jhetfield21 said: Also Thomas I know that the point of rcs are to be embedded what I meant by cant embed the bmps was as they were without packaging them.My problem is that after putting them into a resource file(be it a rc or a resx) I can't figure out how to load the bmps from it. Load the resource bitmap as a windows bitmap, and call convert_hbitmap_to_bitmap on it to get an Allegro BITMAP. I assume you'd use the win32 LoadBitmap function to load the hbitmap, but its been a while since I used the win32 api. -- |
jhetfield21
Member #12,379
November 2010
|
well i tried that way and if i remember well ,it couldn't find that function.or at least it had a problem in the type of bitmap the loaded resource was.i dont really remember which of the two problems it was.but i did use that way and came to a dead end.i'll try it again though and will tell you what problem i had exactly. EDIT 1:What file do i have to include to use convert hbitmap to bitmap?i've searched the ones on platform folder since it's supposed to be platform spesific but nada.And I image the winalleg.h is from A4.
|
KnightWhoSaysNi
Member #7,339
June 2006
|
jhetfield21 said: Knight if you could provide an example nothing fancy cause at this point I'm out of ideas. I don't have allegro installed right now, I'm going to install allegro 5 soon though. Here's how I would go about doing it, I'm not sure about the correct function names though. int data[BITMAP_HEIGHT][BITMAP_WIDTH]; for (int j = 0; j < bmp->h; j++) { for (int i = 0; i < bmp->w; i++) { data[j][i] = getpixel(bmp, i, j); } } and then save it to a txt file called mybitmap.h where the output would look something like. (This will be larger in order to store all of the pixels of the bitmap). #ifndef MY_BITMAP_H #define MY_BITMAP_H data[BITMAP_HEIGHT][BITMAP_WIDTH] = { { 155645, 1212321, 15648684 }, { 155645, 1213321, 15648684 }, { 155645, 1212321, 15648684 }}; #endif and then make a blank bitmap using create_bitmap(BITMAP_WIDTH,BITMAP_HEIGHT) and fill it with the values from the data 2d array using putpixel(BITMAP *bmp, int x, int y, int color) where color is the number in the data array. |
Thomas Fjellstrom
Member #476
June 2000
|
jhetfield21 said: EDIT 1:What file do i have to include to use convert hbitmap to bitmap?i've searched the ones on platform folder since it's supposed to be platform spesific but nada.And I image the winalleg.h is from A4. Indeed, convert_hbitmap_to_bitmap is also allegro 4. I don't believe Allegro 5 has any helper functions for that. -- |
jhetfield21
Member #12,379
November 2010
|
I think I'm gonna abandon the whole resource file thing.Yesterday I wasted 6 hours trying to connect them to the code.And it wouldn't even find the damn resource inside the resource file let alone convert it.Is it possible to do the same thing but with a dll?Hide the bitmaps without embedding them to the executable? What pisses me off the most is that while there is support for usage(supposedly) there is hardly any documentation out there.I've searched for hours the last couple of days and I've only found some worthy articles that don't resemble that much what I want to do which is quite simple imo. EDIT:thx for all the replies though EDIT 2:Don't answer this,I just saw the other thread(http://www.allegro.cc/forums/thread/605608) .If anything,answer there since it's already asked.
|
type568
Member #8,381
March 2007
|
Append:
|
jhetfield21
Member #12,379
November 2010
|
i didn't want to have file dependencies for sth to work.More so because it was small.So I wanted to embed them in the executable.
|
BAF
Member #2,981
December 2002
|
type568 said: Why reinvent the wheel? This is... what resource files are meant for. So it's not reinventing the wheel. In the interest of remaining as platform agnostic as possible, you'd be better off using data files or whatever. You can also embed them in the executable as well, at least with Allegro 4. |
jhetfield21
Member #12,379
November 2010
|
@type568:the meaning of resource files as in .rc or .resx is to embed them to the executable and not have to give the actual resources as in bitmaps texts etc given along with the executable.It's not a question of organisation or overhead.It's a question of file dependency and hidden resources(again bitmaps and the rest).Some don't like to have the resources out there for everyone to take and manipulate.Also it isn't the best to have file dependencies cause if you forget to send them along the exe or for some reason they don't end up in the same directory as the executable in the end user pc. @BAF:yeah i was thinking about dat files.i'try them at some point when i'll have free time. Does anyone know if there is or will be support for datafiles in A5?
|
LennyLen
Member #5,313
December 2004
|
jhetfield21 said: Some don't like to have the resources out there for everyone to take and manipulate. Embed them in the executable that way, and I can get to them with two lines of code.
|
Arthur Kalliokoski
Second in Command
February 2005
|
jhetfield21 said: Does anyone know if there is or will be support for datafiles in A5? You have the PhysFS addon now. They all watch too much MSNBC... they get ideas. |
jhetfield21
Member #12,379
November 2010
|
yeah i know now after all that search for rcs but thats why i said not everyone.anyway doesn't matter most commercial games if you see don't exactly have the resources they use lying around.Those resources being backgrounds and textures etc..Though they might not use bitmap based graphics i don't know,but those that do have the resources in their original format only in cases of artwork that you gain after doing something ingame, as a reward. EDIT:arthur in the physfs site it doesn't say anything about dat files in what works.
|
Thomas Fjellstrom
Member #476
June 2000
|
jhetfield21 said: EDIT:arthur in the physfs site it doesn't say anything about dat files in what works. Uh, yes it does. Just not allegro's old dat format. Theres plenty of other data file formats that it supports. Like zip files. -- |
type568
Member #8,381
March 2007
|
Okay..
|
|