Jump to content
  • Advertisement
Sign in to follow this  
mrtie_dye

fun with file i/o

This topic is 4832 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

If you click here, you will be taken to page where you can download the source that pertains to this post. It is a small file, only 291 kb. I don't believe you need to understand 99% of the code to understand my problem. There is only a couple of lines that really relate to this problem. Here is a quick breakdown anyway. In main, just after I turn the cursor off, I initilize an object of type CSpriteBase. I then call writeFile(), then initilize an object of type CSpriteBaseR. The rest is just code for drawing the sprite, which isn't important, becasue it doesn't work anyway... :) The CSpriteBase object holds some info for a simple animation. In writeFile(), this info is written to a binary file. Then, the CSpriteBaseR object reads this info and hands it off to a CSprite object in hopes that it can be drawn. If you compile and run the code as is, you can take a look at stdout.txt and you will notice that everything written in writeFile() matches up with everything read in CSpriteBaseR. Now, go into main.cpp, and uncomment the line found in the following section of code found in writeFile()..
for(int c = 0; c < height; c++)
{
    for(int d = 0; d < width; d++)
    {
        //pixel = ((Uint32*)base.frame[a].image->pixels)[d + c * (base.frame[a].pitch / 4)];
        bFile.write((char*)&pixel, sizeof(Uint32));
    }
}
Compile it and run it now. Take a look at stdout.txt. Everything in writeFile appears to be ok. But what happened when it was read back in? After the first pass through the loop, everything is gobblty gook. Uncommenting that line should not change the way the data is written to the file, nor how it is read. If uncommenting the line turns the variable pixel into crap, it should still be crap that is the size of Uint32. What is going on here? Any help is GREATLY appreciated. Peace Mr. Tie Dye

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • 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!