Using OpenGL to draw in a MPxContext?

Using OpenGL to draw in a MPxContext?

Anonymous
Not applicable
1,053 Views
4 Replies
Message 1 of 5

Using OpenGL to draw in a MPxContext?

Anonymous
Not applicable

Hello,

 

I am using the Maya API in C++. I would like to do something very simple, but I cannot manage to make it work: draw a line in Maya, using openGL.

 

In my class "MyClass", which inheritate from "MPxContext", I redefine the function "doDrag". And I would like to draw a line in this function.

A version that works is the following one:

MStatus MyClass::doDrag(MEvent &event, MHWRender::MUIDrawManager &drawMgr, const MHWRender::MFrameContext& context)
{
        MColor red(1.0f, 0.0f, 0.0f);
        drawMgr.beginDrawable();
        drawMgr.setColor(red);
        drawMgr.line(MPoint(0, 0, 0), MPoint(10, 10, 10));
        drawMgr.endDrawable();

 

         return MS::kSuccess;
}

 

But I would like to use OpenGL instead, because later I will have to do more complicated stuff. So if something like that would work, it would be great:

MStatus MyClass::doDrag(MEvent &event, MHWRender::MUIDrawManager &drawMgr, const MHWRender::MFrameContext& context)
{
        drawMgr.beginDrawable();
        glBegin(GL_LINES);
        glColor3f(1.0f, 0.0f, 0.0f);
        glVertex3d(0.0, 0.0, 0.0);
        glVertex3d(10.0, 10.0, 10.0);
        glEnd();
        drawMgr.endDrawable();

 

         return MS::kSuccess;
}

 

Does anyone has an idea how to do that? I spent hours searching a solution on the web, I really need your help.

Thanks a lot.

0 Likes
Accepted solutions (1)
1,054 Views
4 Replies
Replies (4)
Message 2 of 5

cheng_xi_li
Autodesk Support
Autodesk Support
Accepted solution

Hi loic,

 

I am afraid you can't do that in VP2 MPxContext. MUIDrawManager must be used for any viewport drawing done in this method. Direct calls to OpenGL or DirectX are unsupported and may result in instability or unpredictable behavior.

 

Yours,

Li

0 Likes
Message 3 of 5

Anonymous
Not applicable

Hi Li,

 

Thank you for your answer. It is really too bad that it is not possible to do that in VP2...

Is there a solution to draw with OpenGL in another viewport (Legacy viewport)?

 

Best,

Loic

0 Likes
Message 4 of 5

cheng_xi_li
Autodesk Support
Autodesk Support

Hi loic,

 

Yes, you can use OpenGL in legacy viewport.

 

MPxContext::doDrag (MEvent &event) is called in legacy viewport. You can use OpenGL to draw items in function above.  The helixTool sample in our devkit is one of the samples for using OpenGL in Legacy Viewport to create an interactive tool.

 

Yours,

Li

 

 

 

0 Likes
Message 5 of 5

Anonymous
Not applicable

Okay.

Thank you for your help Li!

Best.

0 Likes