I want to store the byte value of aFloat in pixelsArray for each 3D coordinate, in a 1D array:
float aFloat = 1.0;
unsigned char* pixelsArray = new unsigned char[HEIGHT*WIDTH*3];
for (int i = 0; i < HEIGHT; i++)
{
for (int j = 0; j < WIDTH; j++)
{
for (int k = 0; k < 3; k++)
{
pixelsArray[?] = aFloat;
}
}
}
What would go in the ?? I think it also needs to have + sizeof(float)
somewhere in the index if I'm not mistaken.
Your inside line needs to be:
This should give you an all-white image.
Make sure your target is really three bytes per pixel and not four (alpha channel or padding); if it is four, you'll just need to change the
3
above to a4
.Let's do this with a 2-dimensional array first:
So you would accesss this with
In your 3-dimensional array, you'd use
You do not need a
sizeof(float)
anywhere, though you probably need the value conversion that Mike DeSimone suggests.