PDA

View Full Version : Using OpenGL in Maya API command


jackinoob
06-08-2006, 06:48 PM
Hi all. I am trying to create a window in MEL, then call a plugin to draw a rectangle in that window using OpenGL. The following plugin loads and runs correctly, no errors, except it does not draw my OpenGL rectangle. I may be doing this completely wrong, any ideas would be appreciated. Thanks in advance!

Here is what I have in MEL:
---------------------------
window mywin;
columnLayout;
api_gl; //calling the plugin
showWindow mywin;
---------------------------


And here is my plugin:
---------------------------
#include <windows.h>
#include <maya/MSimple.h>
#include <maya/MPxCommand.h>
#include <maya/MGlobal.h>
#include <maya/MFnPlugin.h>

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

class mayaAPI_GL : public MPxCommand
{
public:
virtual MStatus doIt ( const MArgList& );
static void *creator() { return new mayaAPI_GL; }
};


MStatus mayaAPI_GL::doIt( const MArgList& args )

{
MStatus stat = MS::kSuccess;

MGlobal::displayInfo( "Hello ");

glColor3f(0.0, 0.0, 1.0);
glRectf(-5.0, 5.0, 5.0, -5.0); //draw the rectangle

setResult( "mayaAPI_GL hello command executed!\n" );

return stat;
}

MStatus initializePlugin( MObject obj )
{
MFnPlugin plugin( obj, "first_try", "1.0" );

MStatus stat;
stat = plugin.registerCommand( "api_gl", mayaAPI_GL::creator );
if ( !stat )
stat.perror( "registerCommand failed");

return stat;
}

MStatus uninitializePlugin( MObject obj )
{
MFnPlugin plugin( obj );

MStatus stat;
stat = plugin.deregisterCommand( "api_gl" );
if ( !stat )
stat.perror( "deregisterCommand failed" );

return stat;
}
---------------------------

tciny
06-08-2006, 11:10 PM
You'd have to use M3dView to get the active view port and then call beginGL afaik. I'm not sure tho this will be much good as everything you do will be lost once maya refreshes the viewport. I'm not even sure you can just perform OGL calls in an MPxCommand...
Depending on what you're trying to do I'd suggest to either derive from MPxLocatorNode and overload it's draw function (for objects you'd like to always draw, in all viewports) or from MPxContext if you're trying to create a tool. Rob Bateman has some very nice examples on that on his website.

jackinoob
06-09-2006, 01:23 AM
Thanks tciny!

I played around with Rob Bateman's locator examples and set it up in Maya.

What I am trying to do is to create very nice graphic and interactive GUIs in Maya, and allow the user to go from one layout to another in the same window, much like we browse the web. I havn't found the mel buttons, layouts, and scrolls to give me the degree of flexibility. I thought I'd give openGL a try.

Is it possible to draw, gather events, and change the content of the window based on those events with opengl?

Rob's example used MPxLocator to draw with openGL, but it was not in a window,

tciny
06-09-2006, 01:52 PM
You should give the Maya Browser combined with mel:// urls a try, I think it'll fit your needs a lot better than OpenGL.

jackinoob
06-09-2006, 02:18 PM
That helps a lot! I had no idea about the maya browser capabiliites. thanks :)

CGTalk Moderation
06-09-2006, 02:18 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.