Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

dogan

Texture saving

This topic is 5473 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, I''ve been trying for months to write a program that loads textures and then saves them all into one binary file. It couldn''t use MFC, so CFile and CArchive are right out. The only thing I could find was the old c-style fwrite/freaad functions. So far, I have something like: FILE* TextureFile; TextureFile=fopen("Textures.foo","wb"); fwrite(&texture[1],sizeof(GLubyte),1,TextureFile); but it doesn''t work. Any answers?

Share this post


Link to post
Share on other sites
Advertisement
I think there are two errors. The first is that with your fwrite command you only write one byte(sizeof(GLubyte)) not the image. The second error is (I think) that &texture[1] is not the pointer to the image buffer but only to the number that identifies the texture (1,2,3,4..).

If you want to load textures and write them in one file you haven't to use OpenGL, for example you only have to load some bitmaps, that are your textures,and save them in one file.
Here are some examples:

#include "gl/glaux.h"

/* With this function you store the image in a buffer */
AUX_RGBImageRec* LoadBMP(char *file)
{
FILE *f=NULL;
if(!file) return NULL;
f=fopen(file,"r");
if(f)
{
fclose(f);
return(auxDIBImageLoad(file));
}
return NULL;
}

/* AUX_RGBImageRec is a struct:
typedef struct _AUX_RGBImageRec
{
GLint sizeX, sizeY; /*Dimensions of your image*/
unsigned char *data; /*Buffer that contain your texture*/
} AUX_RGBImageRec;
*/

void AppendImageToFile(char* szFile, AUX_RGBImageRec* image)
{
/*You open your file to append your image on it*/
FILE *f=fopen(szFile,"ab");
fwrite(&image->sizeX,sizeof(GLint),1,f);
fwrite(&image->sizeY,sizeof(GLint),1,f);
fwrite(image->data,image->sizeX*image->sizeY*3,1,f); /*for a RGB image the buffer size is 3bytes per pixel and there are sizeX*sizeY pixels*/
fclose(f);
}

I wrote these functions at the moment so they are incomplete and maybe with errors but I hope you'll have an idea of what I mean. ;-)

________________________________________________________
www.wizardofoz.fx.to

[edited by - BioLich on September 24, 2003 6:58:56 PM]

Share this post


Link to post
Share on other sites
Thank you! That works great.
Also, one other thing: Nehe mentioned there was a way to overcome the square bitmap limitation, particularly I need to do it with TGAs. Does anyone know what he is talking about?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I''m sure there are better solutions but you may try this:
Instead of having many textures you could have few but big square textures with more than one bitmap on them.
For example if you have some rectangle textures(A is 128x64, B is 80x64, C is 48x64) you could create a square bitmap of 128x128 pixel, and then you could copy in it your three images like this:
|-------------|
| A 128x128 |
| |
| |
|_____________|
|B80x64|C48x64|
|-------------|
With this method you are sure that your image is load correctly because it is still a square, but now you have no limitations with size of the textures you put in the square.
And you can do this with any image format (BMP,TGA,JPG..).

Share this post


Link to post
Share on other sites
I made a mistake and posted anonimously before.. oops!

The correct scheme is this:

|_____________|
| |
| A 128x128 |
| |
|_____________|
|B80x64|C48x64|
|______|______|


________________________________________________________
www.wizardofoz.fx.to

[edited by - BioLich on September 25, 2003 4:45:48 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!