6

I have cpp code that displays simple OpenGL shapes in Maya. If the legacy viewport is used, then I have precisely what I want : arrows going along the x axis:

enter image description here

However if I use the same code in the ViewPort 2.0 then the arrows are following camera movements:

enter image description here

enter image description here

This is happening only if I apply the glTranslatef (which I will need to use).

This is the piece of code:

 for (int i=0;i<10;i++)
 {
    glPushMatrix();
    glTranslatef(i,0,0);
    glBegin(GL_LINES);
    // Arrow
    glVertex3f(0,  y,  z); 
    glVertex3f(1,  y,  z);

    glVertex3f(1,  y,  z);
    glVertex3f(0.5,  y,  z+0.5);

    glVertex3f(1,  y,  z);
    glVertex3f(0.5,  y,  z-0.5);

    glEnd();
    glPopMatrix();
}

How can I have proper behavior in the "new" Maya viewport ?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89
  • Part of me feels like you're missing a `glLoadIdentity()` after that `glPushmatrix()`, the other feels like that's too easy to be true. – Borgleader Jun 30 '15 at 20:39
  • The other part unfortunately is right. Thanks for the proposal anyway :-) – Laurent Crivello Jun 30 '15 at 20:54
  • The strange matrix behaviour makes me wonder if the different viewports have different matrix stacks bound, and in the latter case, you're applying a transform to the projection matrix rather than the modelview, or something... – JasonD Jul 01 '15 at 17:49

1 Answers1

2

Following up on my comment, this looks like the translate is happening in a different coordinate frame to the rendering, which suggests to me that a different matrix stack is bound.

So in the old viewport (where your result is 'correct') you are concatenating a translation onto the modelview matrix, but in the 2.0 case, you are perhaps concatenating a translation onto the projection matrix - which would result in the translation appearing to be relative to the screen, rather than the view.

I would recommend ensuring that all relevant state is set up correctly in your render call, such as setting the desired glMatrixMode() before messing with the matrix stack, etc.

JasonD
  • 16,464
  • 2
  • 29
  • 44