Reading a raw 3d (256x256x256 cells) texture (8bit) using the following:
f = fopen(file, "rb");
if (f == NULL) return;
int size = width * height * depth;
data = new unsigned char[size*3];
fread(data, 3, size, f);
image = reinterpret_cast<rgb *>(data);
fclose(f);
where image rgba is
typedef unsigned char byte;
typedef struct {
byte r;
byte g;
byte b;
} rgb;
I now want to "slice" the cube in some perpendicular direction and display the data with:
glTexImage2D()
What is a clever way to go about grabbing these slices? I have tried to get my head around how to grab the data using a loop, but I am not exactly sure how the data is orgaanized and I do not find this loop to be trivial.
Could I map the data into a more trivial format so I can use intuitive slice syntax?
It's just a 3D array. Pick two axes to scan in the standard 2D access pattern and vary the third to change slices:
You can get fancier with
Boost.MultiArray
.