How to include things as resources in your project

Started by
3 comments, last by deadlydog 19 years, 10 months ago
Hi there, I''m making a game and currently you need to have the Data folder in the same directory as the .exe for it to work. The Data folder contains all of the pictures and everything else for the game. I''m pretty sure you can include these as resources into the project so they''re loaded right into the .exe, but I''m not sure how to do this. I''m using Microsoft Visual C++ 6. Can anyone help me out? - God is my favorite fictional character
-Dan- Can't never could do anything | DansKingdom.com | Dynamic Particle System Framework for XNA
Advertisement
Okay, I figured out how to actually import images and stuff into the project, but I''m not sure how to actually use them in my program. This is basically what my Programming RPG in Windows with DirectX tells me to use, where IDB_TITLE is the name I gave to the resource, and it is in under the folder Bitmap.

cpTitle = (char*)LockResource(LoadResource(GethInst(), FindResource(GethInst(), "IDB_TITLE", "Bitmap")));

But now how do I use cpTitle? I tried simply replacing the filename (Data/Title.bmp) with cpTitle, but that did not work. Can anyone tell me how I''m supposed to use cpTitle so that I can load a Texture from it?

- God is my favorite fictional character
-Dan- Can't never could do anything | DansKingdom.com | Dynamic Particle System Framework for XNA
cpTitle now is a pointer to the content of the bitmap..

normally you would have a function that would load a bitmap from a file like this : (pseudocode)

bool bmp.loadfile (char* filename)
{
f = fopen(filename);
char* buf = new char[filesize];
fread(f,buf);

BITMAPHEADER* bh = (BITMAPHEADER) buf;
//etc...
}

now the cpTitle is the same as buf after you read in the file.

This is just a general way of accessing resources, there is a function that returns a bitmap handle directly given a resource, but i cant remember, since i tend to avoid windows resources due to portability issues

Good luck!

Willem
So then would it even be better to load all of my data as resources? What are the pro''s and con''s of using/not using resources then?

- God is my favorite fictional character
-Dan- Can't never could do anything | DansKingdom.com | Dynamic Particle System Framework for XNA
The bad thing about resources is they all go in the EXE. You might think that is a great thing, but it means if you ever need to release an update, you''d have to include all the resources too (unless you find a really nice exediff tool), so your update will be the same size as the whole game. If you put the data somewhere else (in a seperate file like quake does with .pak files, in a data directory, etc) you can then make an update only updates exactly the parts that need to be updated (usually the exe and maybe a level with a bug in it or somesuch).

When data is seperated, it is much easier to make a demo version or the like (if you want to do it the ''limited content'' way) - you just ship the full exe (with a few minor code changes enclosed in #ifdef type things) and a seperate content package. With resources, you''d need to have 2 seperate projects or something like that to use the same code but include different resources.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk

This topic is closed to new replies.

Advertisement