using glGenTextures with multidimensional array

I’d like to use a multidimensional array to store my textures, but I seem to have some trouble getting glGenTextures to work with it. I have a global variable

GLuint myTextures[8][30];

and down in my texture loading I call

glGenTextures( 8 * 30, myTextures );

however, when I try to compile it I get the error

cannot convert from ‘unsigned int [8][30]’ to ‘unsigned int’

It works fine with one dimensional arrays, and since there’s only 8 of the first one I made 8 seperate one dimensional arrays and it works fine. It would be a lot easier and cleaner, however, if I could use the multidimensional array. Can anyone give me some ideas on how to do this? Thanks in advance

Using multidimensional arrays is not safe. By default there is no guarantee that the array memory will be contiguous and non-padded. I would convert the multidimensional array to a single dimensional array, and then do your own two dimensional addressing math to index the array.

Thanks for the suggestion, I did notice that a few of the textures seemed to be randomly wrong ( ie wrong texture in the wrong spot at the element even tho the code was right ). I guess that might be a result of the memory problems you referred to. Anyway, I moved it into one array and just came up with a formula to calculate which element i needed, and now it works great. Thanks for the help

Originally posted by DFrey:
[b]Using multidimensional arrays is not safe. By default there is no guarantee that the array memory will be contiguous and non-padded.B]

Nonsense.

Contiguous memory allocation is required by C/C++ standard.

btw, check this: Problem in Beginner Board

Originally posted by valtrain:
[b]I’d like to use a multidimensional array to store my textures, but I seem to have some trouble getting glGenTextures to work with it. I have a global variable

GLuint myTextures[8][30];

and down in my texture loading I call

glGenTextures( 8 * 30, myTextures );

however, when I try to compile it I get the error

cannot convert from ‘unsigned int [8][30]’ to ‘unsigned int’
[/b]

Correct.
This code is wrong - ‘unsigned int [8][30]’ cannot be used as ‘unsigned int*’ without a type conversion.

glGenTextures( 8 * 30, myTextures[0] );
// or
glGenTextures( 8 * 30, (GLuint*)myTextures );

[b]Nonsense.

Contiguous memory allocation is required by C/C++ standard.

[/b]

And since when did all compilers meet such standards? I know for a fact I have been by a similar bug. The array memory was contigous, but the elements were also padded.

While it is true that a multidimensional array will more than likely use contigous memory (assuming it adheres to the standard) for arrays whose dimensions are given at compile time, the same is not true of multidimensional arrays allocated dynamically. So because of the asymmetric behavior, I personally avoid using them when I need to pass the array to a function that does not expect a multidimensional array.

[This message has been edited by DFrey (edited 02-19-2001).]