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:
However if I use the same code in the ViewPort 2.0 then the arrows are following camera movements:
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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With