packaging textures
Ive just written a racing game in C++/OpenGL, At the moment the finished game consists of the exe and a shedload of tga files which doesnt look too professional.
Does anyone know of a way to make the image files as part of the exe, or as some kind of single resource file.
Thanks for any help
ps
I am using Visual C++
I was having similar thoughts with my game... Of course lots of professional games, such as Civilisation II, just use bitmap''s totally undisguised. Others have lots of .dat files which are really disguised bitmaps. So you could rename your tga''s to cryptic 1203.dat, etc. files. Alternatively - don''t worry about it!
Brian
Brian
Thanks for the reply,
Yeah I guess it isnt so bad, still I think maybe Ill resort to creating one large tga file (cut & paste... cant wait), this is maybe more efficient too...
Later
Yeah I guess it isnt so bad, still I think maybe Ill resort to creating one large tga file (cut & paste... cant wait), this is maybe more efficient too...
Later
The way I do that sort of thing, is to package all the data into a single file (usually i call it ".dat"). The simplest way to do this, without having to change any of your loading routines, is to simply copy the files in exactly as they are, and just append one after another. In the beginning of your data file, you may want to indicate the offsets that each of the respective files appear at.
Now all you have to do is load up the data file, find out the offset of the image file within it, read it into a buffer, and pass the data to your image loader.
If your image loader accepts a handle to a file as opposed to the buffer of data, you may want to modify it. I find that it is more convienient to be able to pass a buffer and length to my image loaders, as it is more flexible. (the image data can come from anywhere, even say a copy of the file in memory).
I hope this helps give you ideas.
I would not reccommend the cut and past approach. It would be to your advantage to explore some of the other alternatives.
Now all you have to do is load up the data file, find out the offset of the image file within it, read it into a buffer, and pass the data to your image loader.
If your image loader accepts a handle to a file as opposed to the buffer of data, you may want to modify it. I find that it is more convienient to be able to pass a buffer and length to my image loaders, as it is more flexible. (the image data can come from anywhere, even say a copy of the file in memory).
I hope this helps give you ideas.
I would not reccommend the cut and past approach. It would be to your advantage to explore some of the other alternatives.
Seems so obvious now, this is a great idea, and will be very easy to implement.
Many Thanks
hw
Many Thanks
hw
I did this too... I made a .wad (my name for a .dat) maker that in addition to packing files, adds a small wrapper so you can have some file details which makes managing all your art a little easier. When I get it all finished (do these things ever get finished??), I''ll release it because I think it is a much better way of doing this... but anyway, that is off topic! The problem with a .wad file is that I cant get Windows to recognize the bitmaps. The function''s I''ve seen want you to use a BITMAP struct, but the way I was shown to load a bitmap is different. First you read in these 2 structs:
BITMAPFILEHEADER and
BITMAPINFOHEADER
Then check the bit depth and read in the pallette if necessary. And of course, read in the bitmap data after that... So if you want to use LoadImage(), which is the only way I know how to load a bitmap from a file and have Windows know how to use it, dont use a .wad,.dat,.whatever file!! Or you can tell me what I''m doing wrong! If you need more info, see my thread titled "bitmap hell". Thanks!
BITMAPFILEHEADER and
BITMAPINFOHEADER
Then check the bit depth and read in the pallette if necessary. And of course, read in the bitmap data after that... So if you want to use LoadImage(), which is the only way I know how to load a bitmap from a file and have Windows know how to use it, dont use a .wad,.dat,.whatever file!! Or you can tell me what I''m doing wrong! If you need more info, see my thread titled "bitmap hell". Thanks!
There is no spoon.
well like i said im using opengl, so maybe this is completely irrelevant but here is my tga reading code, if it is any use...
void loadTGA (char *name, GLint id)
{
unsigned char info[-7-], *imageData, tmp;
GLint imageWidth, imageHeight, size, i;
FILE *fp;
/* Open the file. */
fp = fopen (name, "r+bt");
/* Skip past irrelevent header info. */
fseek (fp, 12, SEEK_SET);
/* Read in important header info. */
fread (&info, sizeof (char), 6, fp);
/* Calculate image dimensions. */
imageWidth = info[-0-] + info[-1-] * 256;
imageHeight = info[-2-] + info[-3-] * 256;
size = imageWidth * imageHeight;
/* Allocate the correct amount of memory. */
imageData = (unsigned char *)malloc(size * 4);
/* Read in the image data. */
fread (imageData, sizeof (unsigned char), size * 4, fp);
for (i=0 ; i '<' size * 4 ; i+=4)
{
/* Switch the BGR stored TGA data to RGB format. */
tmp = imageData[-i-];
imageData[-i-] = imageData[-i+2-];
imageData[-i+2-] = tmp;
}
/* Close the file. */
fclose (fp);
/* Bind the texture to its id. */
glBindTexture (GL_TEXTURE_2D, id);
/* Set the S and T wrapping properties for this texture.*/
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
/* Set the magnification and minification filters for this texture. */
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
/* Set the overlay fuctionality for this texture. */
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
/* Set the image properties for this texture.*/
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, imageWidth, imageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
/* Free imagedata, as it is no longer required, as we have our texture object. */
free (imageData);
}
i realise this may be bad code or whatever, but i never said i was any good at this
later
note sq brackets have [-whatever-] structure to avoid the board getting confused thinking they are style codes, and < has quotes round to avoid html confusion.
Edited by - heywhatever on August 24, 2000 5:21:13 AM
Edited by - heywhatever on August 24, 2000 5:23:34 AM
void loadTGA (char *name, GLint id)
{
unsigned char info[-7-], *imageData, tmp;
GLint imageWidth, imageHeight, size, i;
FILE *fp;
/* Open the file. */
fp = fopen (name, "r+bt");
/* Skip past irrelevent header info. */
fseek (fp, 12, SEEK_SET);
/* Read in important header info. */
fread (&info, sizeof (char), 6, fp);
/* Calculate image dimensions. */
imageWidth = info[-0-] + info[-1-] * 256;
imageHeight = info[-2-] + info[-3-] * 256;
size = imageWidth * imageHeight;
/* Allocate the correct amount of memory. */
imageData = (unsigned char *)malloc(size * 4);
/* Read in the image data. */
fread (imageData, sizeof (unsigned char), size * 4, fp);
for (i=0 ; i '<' size * 4 ; i+=4)
{
/* Switch the BGR stored TGA data to RGB format. */
tmp = imageData[-i-];
imageData[-i-] = imageData[-i+2-];
imageData[-i+2-] = tmp;
}
/* Close the file. */
fclose (fp);
/* Bind the texture to its id. */
glBindTexture (GL_TEXTURE_2D, id);
/* Set the S and T wrapping properties for this texture.*/
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
/* Set the magnification and minification filters for this texture. */
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
/* Set the overlay fuctionality for this texture. */
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
/* Set the image properties for this texture.*/
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, imageWidth, imageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
/* Free imagedata, as it is no longer required, as we have our texture object. */
free (imageData);
}
i realise this may be bad code or whatever, but i never said i was any good at this
later
note sq brackets have [-whatever-] structure to avoid the board getting confused thinking they are style codes, and < has quotes round to avoid html confusion.
Edited by - heywhatever on August 24, 2000 5:21:13 AM
Edited by - heywhatever on August 24, 2000 5:23:34 AM
Nope, not helpful at all! =) But you are using TGA and I am using BMP. If you still want help feel free to ask, I think the tut on making your own tileset by Dino Gambione in the referrence section would help you a lot. I used his model, but I added a bit to it where I felt it was incomplete.
There is no spoon.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement