are you looking for a way to create your own file format, to hold all the data you want (like "MyOwnFile.MYFORMAT", where MyOwnFile is the file name and MYFORMAT is the format )? or trying to read some other format?
if you are trying to read someone else format, you gotta do one of two:
either ask the creator of this format, how are data stored in it
or open it up (in notepad or whatever) and read it, then try to figure out how it works (most of the times you won't figure it out, unless it's a very simple, self-explained format).
but if you are trying to create your own format, then just some info you gotta keep in mind:
your own file with it's format is just a text file! but data are written in it in some way that only those who knows how can read it (well depends on what you want, might be a public format, whatever..), the purpose is to protect your media from being "easily" stolen by users (i believe there is always a way to steal media ( thats sad
, but those people somehow find their ways )), so what you want to do is:
from your C++ source, create a file, for example, using C file methods:
FILE* fp = fopen ( "MyOwnFile.MYFORMAT", "w" );
if ( !fp )
{
//handle the error
}
//....
//..write the data
//...
fclose ( fp );
or using fstream:
fstream file;
file.open ( "MyOwnFile.MYFORMAT", ios::out );
if ( file.fail ( ) )
{
//handle the error
}
//...
//..write the data
//...
file.close ( );
and for reading, you do the same thing, but (for C methods) use "r" instead of "w" in fopen, (fstream method) use ios::in instead of ios::out
so only reading/writing left, well it's all up to you! it could look like this: (saving an image)
//C method
for ( UINT y = 0; y < imgHeight; y++ )
for ( UINT x = 0; x < imgWidth; x++ )
fprintf ( fp, "PIXEL(%c%c%c%c)\n", img[y*imgHeight+x].r, img[y*imgHeight+x].g, img[y*imgHeight+x].b, img[y*imgHeight+x].a );
//fstream method
for ( UINT y = 0; y < imgHeight; y++ )
for ( UINT x = 0; x < imgWidth; x++ )
{
file << "PIXEL(";
file.put ( img[y*imgHeight+x].r );
file.put ( img[y*imgHeight+x].g );
file.put ( img[y*imgHeight+x].b );
file.put ( img[y*imgHeight+x].a );
file << ")\n";
}
thats for saving (img is an array of pixels (size = is imgWidth*imgHeight), each pixel contains 4 elements, r/g/b/a (red/green/blue/alpha), and each one got to be 1 byte (BYTE or unsigned char))
same thing with loading, you just read them (line by line or however you wrote it, then make a little parser (which is far from being complex!) and create the image with the info given
well now for the last part, how to tell GDK that our pixels form the image? well that's something im not aware of as i never tried with GDK, but it got to be possible, you can ask here on forums, someone probably knows how
of course, this is just one way, out of millions of other ways, you can just find the way that suits you