OpenGL Overlay in Maya Viewports?


#1

Hi,

I was wondering if anyone could suggest the best way of overlaying an OpenGL buffer over standard Maya viewports? (probably using API)>

I’m reasonably sure this is possible (I noticed the MPxGlBuffer class in the API Docs), but could do with some tips as to how to use this in the overlay process?

If possible, perhaps someone could write a simple command which creates a GL overlay, and (say) renders a coloured triangle (or something simple) to the viewport overlay?

Thanks in advance for your help!

Paul.
:hmm:


#2

I’ll have to check some code when I get into work tomorrow, but yeah, it’s pretty easy…

I hacked around with someone’s code to get it to draw black bars around the frame to frame it properly…

I seem to remember that it was as easy as making GL calls…

I’ll check the code and write up some examples…


#3

Thanks, Hugh!


#4

Okay… a brief outline for how to draw to the viewport:

This assumes a member variable: ‘bool drawState’ that is initialised to false in the constructor…


void myNode::draw(M3dView & view, const MDagPath & path, M3dView::DisplayStyle style, M3dView::DisplayStatus status)
{
	double width = view.portWidth();
	double height = view.portHeight();
	
	view.beginGL();

	glPushAttrib(GL_ALL_ATTRIB_BITS);
	glClear(GL_CURRENT_BIT);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
	
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	gluOrtho2D(0.0, (GLdouble)width, 0.0, (GLdouble)height);
	glMatrixMode(GL_MODELVIEW);
	glShadeModel(GL_SMOOTH);
	
	// Do any OpenGL drawing here....

	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();

	if(!drawState)
	{
#ifndef _WIN32
		glXSwapBuffers(view.display(), view.window());
#else
		SwapBuffers(view.deviceContext());
#endif
		
		drawState = true;
	}

	glPopAttrib();
	view.endGL();
}


#5

Thanks, Hugh.

So, is myNode::draw a function which I define? And what’s ‘myNode’? … and where do I call this function from?

Paul.


#6

Ahh - you will want to look into Maya API programming…

In this case, myNode is derived from MPxLocatorNode

draw() is called automatically when the node needs to be drawn…


#7

Okay, thanks Hugh!


#8

Would this page help at all?

http://www.ewertb.com/maya/api/api.php?howto=07

Dan


#9

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.