Skip to main content
gamedev.net
🔒 Locked

texture pixel numbering

Started by Endar 2 replies 450+ views
Original Post
Endar
Endar
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:

/**
 * 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;
}


Have I missed something, or is this how it should be?
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
relsoft
relsoft
BMP's are stored y-reversed.
Hi.
Endar
Endar
Do you know about TGA files?
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
Brother Bob
Brother Bob
TGA images are stored either bottom up or top down depending on the header. Check some file format documentation, there is a bit indicating where the origin is located. Checked quick myself and seems to be the 5:th bit of the 19:th byte.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.