# OpenGL opengl matrices dumb question

This topic is 4994 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm going round in circles and I need someone to help! take an ordinary matrix eg 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 To store in an array in c we use: float mymatrix[4[4]={1,2,3,4}, {5,6,7,8}, ...., {13, 14, 15, 16}} However, opengl is column major so to use the above matrix for opengl we need to have the following: float mymatrix[4[4]={1,5,9,13}, {2,6,10,14}, ...., {4, 8, 12, 16}} Is this correct ? cheers Ade

##### Share on other sites
I always just store my matrices in a single dimension array with 16 elements.
That way [0] through [3] always corresponds to the first row in an opengl matrice.

##### Share on other sites
OpenGL matrices are column major, but it's not worth the effort having to convert them from the single dimentional array they come as.

##### Share on other sites
To the OP: looks like you've got it right. As has been mentioned, OpenGL matrices are column-major, so are laid out like this:

0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15

With a 2d array, the i-j inidices are:

00 01 02 03
10 11 12 13
20 21 22 23
30 31 32 33

So you can see how the 1d array maps to the 2d array. Aside from the 1-based indexing, this is what you had in your original post.

Remember also that OpenGL uses column vectors rather than row vectors, so regardless of whether the matrix is column or row major, the axes and translation are arranged in the matrix like this:

xx yx zx tx
xy yy zy ty
xz yz zz tz
0 0 0 1

1. 1
Rutin
34
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633331
• Total Posts
3011399
• ### Who's Online (See full list)

There are no registered users currently online

×