Archived

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

Roof Top Pew Wee

Can Direct Draw Surfaces be saved??

Recommended Posts

I''m writing a program which creates packages (a bunch of bitmaps ordered in a certain way) for a map maker I''m also programming. I originally planned on making an object that had an array of strings which were the file names for the different bitmaps, but I thought it might be faster to just have the object have a number of surfaces in it and just save that. That way, the surfaces don''t have to be loaded and I don''t have to bother saving more things than necessary. Here''s my code for saving the surfaces: void savePackage(char* fileName) { char* extention = ".LTP"; strcat(fileName, extention); ofstream outfile(fileName, ios::binary); outfile.write(reinterpret_cast(this), sizeof(*this)); } This is located in my terrainPackage class. Here''s the problem. The terrainPackage object contains an object called terrainSurfaces which is mostly made up of surfaces (84 to be exact). I know that these surfaces are actually full, because I blit from them during the program, but when I save the program, I get a file that is only 432 bytes. The size stays static no matter how many surfaces I fill, so I''m guessing that the surfaces aren''t being saved. Does anyone know the reason for this? It''s not possible for 84 surfaces to be that small. Thanks for any help. --Vic-- PS. Could this have anything to do with the fact that I''m using an array of LPDIRECTDRAWSURFACE''s? I thought maybe it only saves the pointer to the surface and not the surface itself.

Share this post


Link to post
Share on other sites
invective    118
Yes. If you save a class or struct, with write, it literally saves a bitwise copy of what is in the struct, including any pointers and including any empty bytes that are there for alignment purposes. It does NOT save anything pointed to by any of those pointers -- those things are not part of the struct, just pointed to by it. If you want to save a surface, you need to explicitly lock it and write out all of the bits yourself.

Its generally pointless to save pointers, because the data will not likely be at the same adress next time you load the program. If you want to be able you save your class, you need to write a function or overload << to save the relavant data, and dereference all the pointers and save their appropriate data. You probably also need to save meta information, like the size of each surface, so you will be able to reload it correctly. You don''t need to save your pointers.

Share this post


Link to post
Share on other sites
I see. Well, I'm new to working with these surfaces, at least in terms of saving them. My only idea would be to go through each surface pixel by pixel and create an array of these pixels and save these values. Is this the best way? Can anyone help or does anyone know of any tutorials to help me learn to save these graphics. I've also read that it can be beneficial to create an alternative file format for graphics. If anyone could help, I would really appreciate it. Thanks.

--Vic--

Edited by - Roof Top Pew Wee on November 12, 2001 11:21:03 PM

Share this post


Link to post
Share on other sites
invective    118
I don't have the directx 7 documentation anymore, but you need to lock the surface (look it up). You get back a pointer to the surface and the pitch (distance in bytes between rows). You need to read the surface out row by row, since rows are not always contiguous (Pitch NOT EQUAL Width) because of memory alignment.

  
char destination = new char [width * hieght * bytesPerPixel];
//Call Lock for surface here

for (y=0; y < hieght; y++)
memcpy ((void*)(destination + y*width), (void*) (source + y*pitch), bytesPerPixel * width);
//Call Unlock

file.write (destination, width * hieght * bytesPerPixel)
delete [] destination;


Edited by - invective on November 13, 2001 4:00:29 PM

Share this post


Link to post
Share on other sites
Remnex    122
Drop me an email or contact me on ICQ later tonite. If I understand you right you want to save the surface to a bitmap file. If you do, I have two routines I wrote for my DirectX lib that save surfaces to bitmaps, RAW, or soon Zsi files.

If that''s what you need I can help ya out.



------------------------------
"I''m a decorated astronaut, I don''t make those kind of mistakes."
"Oh now wait a minute. Look I''ll show ya. I''ll enter the same calculations using what we like to call ''The Right Way''."

-Rem
Zirem Software

Share this post


Link to post
Share on other sites