Announcement

Collapse
No announcement yet.

OpenGL Architecture

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • OpenGL Architecture

    This comment in a tutorial caught my attention ...

    ...a few lines later glMatrixMode() is called again, this time with GL_MODELVIEW as the argument. This indicates that succeeding transformations now affect the modelview matrix instead of the projection matrix.
    I'm still learning, but the only OpenGL function I've seen so far that applies to all matrices is glLoadIdentity. Instead of requiring code to specify a "current" matrix the architects of OpenGL could have created 2 functions - glLoadModelingIdentity and glLoadProjectionIdentity (well, 4 functions actually as there are 4 matrix types)

    It made me wonder if there's a more general argument why a "current" matrix must be specified? If all (or at least almost all) functions apply only to a given matrix type, then specifying a "current" matrix seems unnecessary.

    Perhaps there are other functions I've just not seen that also can apply to more than one matrix?

    Perhaps the architects just thought it would help maintain code if it could be segmented by statements applying to similar matrices?

    Perhaps the architects thought it would help programmers put the functions in the right order?

    Has anyone read anything that addresses my question?

  • #2
    Gary:

    It would help if you would put the comment into context. Is that during initialization, or somewhere else? And to what tutorial are you referring?
    Walt Decker

    Comment


    • #3
      Originally posted by Gary Beene View Post
      It made me wonder if there's a more general argument why a "current" matrix must be specified? If all (or at least almost all) functions apply only to a given matrix type, then specifying a "current" matrix seems unnecessary.
      My understanding is that all the matrix functions are applicable to any of the matrices, however some matrix operations are not necessarily appropriate for all matrices. The functions are used to only SET the values of a matrix in the pipeline of transformations.

      For example you probably wouldn't want to use gluPerspective, on the ModelView matrix, rather the projection matrix.

      The matrix you want to work on must be specified only when you need to switch from another matrix. I.E. if resizing, you would redefine the perspective matrix, so you must make sure it's the current matrix. Once you've set it, you can set the matrix mode back to model view and ALL subsequent operations will be performed on the modelview matrix. OpenGL is state based, whenever you set a current state, it remains, until you explicitly change it.
      "Show me a young Conservative and I'll show you someone with no heart. Show me an old Liberal and I'll show you someone with no brains." ― Winston Churchill
      "Socialism is the philosophy of failure, the creed of ignorance and the gospel of envy." ― Winston Churchill

      Comment


      • #4
        Hi Walt,

        Here's the source of the quote ...
        OpenGL Programming Guide

        My comment would apply outside of initialization.

        Comment


        • #5
          Hey Doug,
          You've commented on the heart of the question. This is not how I interpreted what I've read ...

          My understanding is that all the matrix functions are applicable to any of the matrices.
          Since applying (for example) gluPerspective to the ModelView matrix would make no sense, I assumed the function would be smart enough not to do that. Not once (in at least a dozen tutorials) have I seen a comment that describes the effect of using a function on the wrong matrix. Perhaps the authors just assume I wouldn't do such a thing! :laugh:

          So if what you say is true, that would explain the need to switch to the appropriate matrix. That approach also prevents functions from somehow having to recognize which matrix is current, as would my assumption.

          Comment

          Working...
          X