Question

openGL with maya

I made a openGL View with QGLWidget. It has a problem when work with Maya. As you see in video, when I click and move on a modelPanel within Maya, the QGLWidget get broken. And I found that the marquee rectangle is shown on my QGLWidget, not Maya. Why this problem happend?

To datenwolf

I tried to edit my code as you suggested. But... it doesn't call makeCurrent() and doneCurrent() at all. I expected that when I clicked on my maya modelPanel it could send me the message, but it didn't. What did I miss? Sorry for that.

def makeCurrent(self):
    import OpenGL.WGL as wgl
    print "MAKE CURRENT!!!"
    self.prevHDC = wgl.wglGetCurrentDC()
    self.prevHRC = wgl.wglGetCurretnContext()
    super(GLWidget, self).makeCurrent()
        
def doneCurrent(self):
    import OpenGL.WGL as wgl
    print "DONE CURRENT!!!"
    super(GLWidget, self).doneCurrent()
    wgl.wglMakeCurrent(self.prevHDC, self.prevHRC)

I wrote just like above. But it never even show the "MESSAGE".

Was it helpful?

Solution

Most likely Qt and Maya's event loop are battling for processing event. Qt's paintGL does the right thing and makes the OpenGL context current whenever it is called. Maya however does not and so drawing commands of Maya end up in your OpenGL context.

Playing along with Maya is going to be tricky, because it requires storing which OpenGL/DC context was active before switching and restoring that once finished with one own's operations. You'll probably have to subclass QGLWidget and QGLContext to do this.

Update due to comment

Derive from QGLWidget, add two members HDC m_prevHDC and HRC m_prevHRC, override makeCurrent and doneCurrent

void QMyGLWidget::makeCurrent()
{
    this->m_prevHDC = wglGetCurrentDC();
    this->m_prevHRC = wglGetCurrentContext();

    QGLWidget::makeCurrent();
}

void QMyGLWidget::doneCurrent()
{
     QGLWidget::doneCurrent();

     wglMakeCurrent(this->m_prevHDC, this->m_prevHRC);
}

Then derive your actual GLWidget from this intermediary class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top