Original Post
I'm working on a couple of functions to access the pixel data for a texture. The data was kept when it was loaded so it could be accessed. The thing is, the pixel 0,0 is not where I thought it was going to be. I highlight pixel 0,0 and I get a pixel at the bottom left hand corner of the texture. I've tried this for bitmaps and TGA files. The pixel data is kept in a 1d array, and I calc the offset into that array for the pixels like this: Have I missed something, or is this how it should be?
/**
* Return the offset into the data array for the pixel data.
* \param x The x coord of the pixel
* \param y The y coord of the pixel
* \param components The number of components in the pixel data should be 3 for RGB, 4 for RGBA, but no checking is done (the calling
* function should be checking that.
*/
unsigned int getPixelDataOffset(unsigned int x, unsigned int y, int components) const
{
// We're not worrying about the boundaries of the texture. This is only to do a simple little calcuation to get an offset
// the functions that call this function should be the ones checking boundaries.
return ((y*(unsigned int)m_size.width) + x) * components;
}