Jump to content
  • Advertisement
Sign in to follow this  

trouble with loading .tga files (*solved*)

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

After taking a deep breath I've rewritten the piece of code and everything works now. I can't delete this post (deleting time is expired) and I don't think this topic is useful for anybody so I think it can be deleted. maby it can be useful if I tell what I did wrong: this was my FlipVertical function:
void TgaImage::FlipVertical()
        if (myValid == false)

        unsigned int RowDataSize = myWidth * myBpp;
        byte* Temp = new byte[RowDataSize];
        unsigned int Top;
        unsigned int Bottom;

        for (int i = 0 ; i < (myHeight / 2) ; ++i)
            Top = i * RowDataSize;
            Bottom = (myHeight * RowDataSize) - (i * RowDataSize);

            memcpy(Temp, &myData[Top], RowDataSize);
            memcpy(&myData[Top], &myData[Bottom], RowDataSize);
            memcpy(&myData[Bottom], Temp, RowDataSize);

        delete [] Temp;
what I did wrong is: (myHeight * RowDataSize) gives the end of the data. When i = 0 (i * RowDataSize) = 0 too. so myData[Bottom] will be pointing behind the boundaries of myData. To solve this I needed to do something like:((myHeight - 1) * RowDataSize) - (i * RowDataSize). [Edited by - flammable on March 18, 2009 9:51:38 AM]

Share this post

Link to post
Share on other sites
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!