Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Order of initializing matrices

  1. #1
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    2

    Question Order of initializing matrices

    The meaning of column-major in opengl has confused me.

    A 4x4 matrix looks like this with the numbers representing the sequential order of each number,
    Code :
    1    5    9    13
    2    6    10   14
    3    7    11   15
    4    8    12   16
    Correct? So 1 - 4 might represent the x, y, z, and w of some vector...

    Would I initialize a float array or a mat4 like this:
    Code :
    mat4(   1,  2,  3,   4,
            5,  6,  7,   8,
            9,  10, 11, 12,
            13, 14, 15, 16);

    or like this?

    Code :
    mat4(   1, 5, 9,  13,
            2, 6, 10, 14,
            3, 7, 11, 15,
            4, 8, 12, 16);

    Thanks for any help.

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,170
    It's simply a convention. You can use which ever convention suits you and your code base - but be consitent!
    When you upload a matrix as a uniform, there are options to transpose or you could work with the Column-Major OpenGL convention in the first place.
    Personally, I stick with the OpenGL column major approach which then makes interaction with any OpenGL matrix seamless.
    To answer your last question, it depends on the approach you want to take. If you want column major, then
    mat4( 1, 5, 9, 13,
    2, 6, 10, 14,
    3, 7, 11, 15,
    4, 8, 12, 16);
    is the way to do it and elements 13,14,15 represent the Translate (X,Y,Z) portion of the Matrix (eg when using glTranslatef command ).

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,224
    Quote Originally Posted by BionicBytes View Post
    It's simply a convention. You can use which ever convention suits you and your code base - but be consitent!
    When you upload a matrix as a uniform, there are options to transpose or you could work with the Column-Major OpenGL convention in the first place.
    Personally, I stick with the OpenGL column major approach which then makes interaction with any OpenGL matrix seamless.
    OpenGL requires column-major operator-on-the-left order:

    P*V*M * vobj = vclip

    In your C++ code (which uses row-major ordered arrays), it's simplest to use row-major operator-on-the-right order for your matrix storage and math:

    vobj * M*V*P = vclip

    These two changes cancel each other out and you end up storing exactly the same values in exactly the same matrix locations, and there's no need to do matrix transposes when passing matrix values to OpenGL.

  4. #4
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,170
    Yep, totally agree with Dark Photon.
    However, if like me you end up writing your own matrix and vector classes you need to debug them, and that's where matching the OGL convention is so much easier. Once you then endup with something which works it's then hard to justify changing the convention.

  5. #5
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    2
    I see, thats very clear. Thank you.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •