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: Load the current Matrix

  1. #1
    Newbie Newbie
    Join Date
    Sep 2017
    Posts
    2

    Load the current Matrix

    I can update the current Matrix using an array with the function:

    glLoadMatrixf(myArray);

    But how can I do the inverse?
    I mean how can I load the current Matrix in a array to view / edit it?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,728
    Code :
    float myArray[16];
    glGetFloatv (GL_MODELVIEW_MATRIX, myArray);
    Reference: https://www.khronos.org/registry/Ope...html/glGet.xml

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,522
    While mhagain's answer is technically accurate, an arguably-better answer is "don't do that".

    If you need to access the matrix' contents from client code, just keep a copy of the matrix in client memory. That means using e.g. GLM to construct the matrix rather than the legacy matrix operations (glRotate, glTranslate, etc). This is a large part of the reason why those functions have been removed from later versions of OpenGL.

    Note that using glGet* can cause a pipeline stall, resulting in a significant performance hit. Ideally, it shouldn't be used outside of initialisation code.

  4. #4
    Newbie Newbie
    Join Date
    Sep 2017
    Posts
    2
    Thank you people, my problem is solved.

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,728
    It should be added however that because the legacy matrix stack is most likely going to be implemented in software, this particular glGet probably won't involve a round trip to the GPU and the associated pipeline stall. So yes, glGet calls for current state are in the general case a bad idea, but special case exceptions may exist.

Posting Permissions

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