Since the size is known in advance, you will need to convert the entire array to a 1D array (for OpenGL), why not create a class for it? I created a three-dimensional array based on the template, which I hope will be useful to you.
Using:
typedef Array3D<double, 3, 3, 3> DoubleArray333; DoubleArray333 array; Double val = 0.0; for (size_t i = 0; i < DoubleArray333::SizeX; ++i) { for (size_t j = 0; j < DoubleArray333::SizeY; ++j) { for (size_t k = 0; k < DoubleArray333::SizeZ; ++k) { array(i, j, k) = val++; } } } for (size_t i = 0; i < DoubleArray333::ArraySize; ++i) { std::cout<<array[i]<<" "; }
Array3D File Header:
#pragma once
You can also get a pointer to an array as 1D using the function:
double* double_array = array.getArray();
EDIT: Usage has changed to show it using double, not int.
source share