Tell me, please, why in the examples on C use a two-dimensional array:

const GLfloat vertex_data[3][3] = { { 0.0, 1.0, 0.0 }, { -1.0, -1.0, 0.0 }, { 1.0, -1.0, 0.0 } }; 

, and in python just stuffed into one list:

 vertex_data = [ 0, 1, 0, -1, -1, 0, 1, -1, 0 ] 

?

  • one
    Most likely due to the fact that in Python create a lot of arrays is expensive. - pank
  • @pank in Python has no arrays at all, lists instead, but even then they are not so expensive to create (if you meant computer resources). - Rishat

1 answer 1

The main reason is the convenience of manipulating and manipulating data. Different languages ​​provide their functionality for data processing. But OpenGL still requires at the input that all buffers (arrays), matrices, etc. were one dimensional.

For example, when multiplying matrices in a program, they are stored in two-dimensional arrays and apply a double indexing a[i][j] (which is much more convenient for most operations), and then, when transferred to OpenGL, is converted into a one-dimensional array (which is the case with static two-dimensional arrays, identical to the transfer of a pointer to the first element, because the elements are "in a row").

  • Thank you very much for the explanation) - Rishat
  • @ Rishat, please mark the answer with a bird as accepted) - ampawd