Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different OpenGL behaviors depending on Maya's viewport used

Tags:

c++

opengl

maya

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 ?

like image 724
Laurent Crivello Avatar asked Jun 30 '15 20:06

Laurent Crivello


1 Answers

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.

like image 55
JasonD Avatar answered Oct 31 '22 18:10

JasonD