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: Matrix Multiplication (Open GL behaviour problem)

  1. #1
    Intern Contributor
    Join Date
    Feb 2011
    Posts
    50

    Matrix Multiplication (Open GL behaviour problem)

    Why does Open GL draw my object on the origin the first time round when I place my object?
    Additional info:

    •I have an object which is written/ initialised on the origin? (x = 0, y=0)
    •However I call a matrix transformation just after its in draw(); E.G.: draw_shape(); glMatrixLoad();......
    •Afterwards the following objects are drawn accordingly but I'm annoyed at the first object which ruins the whole function.

    Code :
    for (int letter = 0;letter != strlen(s);letter++)
     
     {
     
     
     
     //draw font in array
     
      qva_Fonts[((int)*s)- 32]-> draw();
     
      s++;
     
     
     
     //loadmatrix Position & Scalling
     
     
      gfaaSca[0] = gfFont_Size;
     
          gfaaSca[5] = gfFont_Size;
     
              gfaaSca[10] = gfFont_Size;
     
                   gfaaSca[15] = gfFont_Size;
     
     
      gfText_PosX += gfFont_Spacing;
     
         gfaaPos[12] = gfText_PosX;
     
      gfaaPos[13] = gfText_PosY;
     
     
     //multiply matrix
     
     
     
      glMultMatrixf(gfaaSca); 
     
      glMultMatrixf(gfaaPos);
     
      glLoadMatrixf(gfaaSca); glLoadMatrixf(gfaaPos);  
     
     }
     
     
     glLoadIdentity();
     
    }

  2. #2
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,008

    Re: Matrix Multiplication (Open GL behaviour problem)

    However I call a matrix transformation just after its in draw(); E.G.: draw_shape(); glMatrixLoad();......
    All OpenGL rendering functions use the state of OpenGL at the time the rendering command was issued. Calling glLoadMatrix after rendering will not affect the rendering of the stuff you called before glLoadMatrix.

    So if you want some matrix functions to affect the rendering of something, call them before rendering that something.

  3. #3
    Intern Contributor
    Join Date
    Feb 2011
    Posts
    50

    Re: Matrix Multiplication (Open GL behaviour problem)

    so basically, its just loading the matrix before multiplying. By the way would it be possible to load it when there is nothing being draw.

    Or would it be a case of drawing then glSwapBuffers();(for clearing the default drawing)at which afterwards you'll redraw the same at the desire location?

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789

    Re: Matrix Multiplication (Open GL behaviour problem)

    I'm not entirely sure what you're trying to accomplish here, but you seem to have misunderstood how matrixes work. The correct order of operation for each object should be:
    • Set up matrix.
    • Load matrix.
    • Draw stuff.
    In your case, as well as getting the order completely backwards, you're calling glLoadMatrix twice - are you aware that the second glLoadMatrix (for gfaaPos) will overwrite the first (for gfaaSca)?

    A SwapBuffers call has nothing to do with clearing stuff; it exchanges the front and back buffers in a double buffered context, and should only be called once per frame and at the end of the frame. glClear is for clearing, and thinking of using SwapBuffers to do it is - to put it bluntly and with no offense intended - a kind of cargo-cult hacking and slashing at code in the desperate hope that something will work.

    I think that you're trying to jump too far ahead of your current level of ability to be honest. You need to step back a little and focus on how transforms actually work, what the correct order of operations actually is, and correct your current misunderstandings first.

  5. #5
    Intern Contributor
    Join Date
    Feb 2011
    Posts
    50

    Re: Matrix Multiplication (Open GL behaviour problem)

    Oh is it.

    All I just wanted to do was to scale my matrix then reposition it (I thought I needed two matrices for it).But, how would I go about doing this?

Posting Permissions

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