Hello Alexander,

On 11/02/2012 08:12 AM, Alexander Lang wrote:
i noticed that the protected member function initializeGL() of my
subclasses of OSGQGLWidget is never called. This is weird as within that
function i call init() on the instance of OSG::Qt4Window, therefore
calling that function seems not be be necessary?

for the usual case [1] Window::init() mostly sets up some OpenGL state in the way OpenSG expects it, so it depends a bit on your application (i.e. what OpenGL state it uses) whether the call is critical or not.

resizeGL() and paintGL()
are correctly called. Any idea?

partially ;)
OSGQGLWidget intercepts the virtual functions of QGLWidget that normally call initializeGL() (those seem to be: resizeEvent(), paintEvent(), glDraw()).

Gerrit: do you recall why you've overridden those functions? In a quick test it seems to work to not override them and remove the assert in OSGQGLWidget::GLContext::makeCurrent(). This makes sure initializeGL() gets called again, which seems useful as it makes our OSGQGLWidget behave more like the base QGLWidget.
How about the attached patch that implements this?

        Cheers,
                Carsten
diff --git a/Source/WindowSystem/QT4/OSGQ4GLWidget_qt.cpp b/Source/WindowSystem/QT4/OSGQ4GLWidget_qt.cpp
index 5c478a5..4f39eab 100644
--- a/Source/WindowSystem/QT4/OSGQ4GLWidget_qt.cpp
+++ b/Source/WindowSystem/QT4/OSGQ4GLWidget_qt.cpp
@@ -52,11 +52,15 @@ OSGQGLWidget::GLContext::GLContext(const QGLFormat & format) :
     QGLContext(format)
 {
 }
- 
- // on makeCurrent() just do pretty nothing
+
 void OSGQGLWidget::GLContext::makeCurrent(void)
 {
-    OSG_ASSERT(false);
+    // on makeCurrent() just do pretty nothing
+}
+
+void OSGQGLWidget::GLContext::doneCurrent(void)
+{
+    // on doneCurrent() just do pretty nothing
 }
 
 void OSGQGLWidget::GLContext::doMakeCurrent(void)
@@ -157,36 +161,6 @@ void OSGQGLWidget::swapBuffers(void)
 {
 }
 
-bool OSGQGLWidget::event(QEvent *pEvent)
-{
-#if defined(Q_WS_X11)
-    if(pEvent->type() != QEvent::Hide &&
-       pEvent->type() != QEvent::ParentChange) 
-    {
-        return Inherited::event(pEvent);
-    }
-
-    return true;
-#else
-    return Inherited::event(pEvent);
-#endif
-}
-
-void OSGQGLWidget::resizeEvent(QResizeEvent *) 
-{
-    resizeGL(width(), height()); 
-}
-
-void OSGQGLWidget::glDraw(void) 
-{
-    paintGL();
-}
-
-void OSGQGLWidget::paintEvent(QPaintEvent *) 
-{ 
-    paintGL(); 
-};
-
 void OSGQGLWidget::doMakeCurrent(void)
 {
     GLContext *pContext = 
diff --git a/Source/WindowSystem/QT4/OSGQ4GLWidget_qt.h b/Source/WindowSystem/QT4/OSGQ4GLWidget_qt.h
index d7b91b1..4c722c3 100644
--- a/Source/WindowSystem/QT4/OSGQ4GLWidget_qt.h
+++ b/Source/WindowSystem/QT4/OSGQ4GLWidget_qt.h
@@ -78,6 +78,7 @@ class OSG_WINDOWQT4_DLLMAPPING OSGQGLWidget : public QGLWidget
         GLContext(const QGLFormat &format);
 
         virtual void makeCurrent(void);
+        virtual void doneCurrent(void);
 
       protected:
 
@@ -138,11 +139,6 @@ class OSG_WINDOWQT4_DLLMAPPING OSGQGLWidget : public QGLWidget
     virtual void initializeGL(void);
     virtual void paintGL     (void);
     virtual void resizeGL    (int w, int h);
-    virtual void glDraw      (void);
-
-    virtual bool event       (QEvent       *pEvent);
-    virtual void resizeEvent (QResizeEvent *pEvent);
-    virtual void paintEvent  (QPaintEvent  *pEvent);
 
     /*! \}                                                                 */
     /*---------------------------------------------------------------------*/
diff --git a/Source/WindowSystem/QT4/testWindowQT4SSM_qt.cpp b/Source/WindowSystem/QT4/testWindowQT4SSM_qt.cpp
index 6d748c0..e8dccfe 100644
--- a/Source/WindowSystem/QT4/testWindowQT4SSM_qt.cpp
+++ b/Source/WindowSystem/QT4/testWindowQT4SSM_qt.cpp
@@ -32,6 +32,7 @@ class MyOSGQGLWidget : public OSG::OSGQGLWidget
     
   protected:
 
+    virtual void initializeGL     (void          );
     virtual void paintGL          (void          );
     virtual void resizeGL         (int w, 
                                    int          h);
@@ -69,13 +70,10 @@ MyOSGQGLWidget::~MyOSGQGLWidget(void)
     m_manager = NULL;
 }
 
-#if 0
 void MyOSGQGLWidget::initializeGL ( void )
 {
     m_manager->getWindow()->init();       // create the context
-//    m_manager->getWindow()->activate();   // and activate it
 }
-#endif
 
 void MyOSGQGLWidget::paintGL(void)
 {
@@ -88,7 +86,7 @@ void MyOSGQGLWidget::paintGL(void)
 void MyOSGQGLWidget::resizeGL(int w, int h)
 {
     m_manager->resize(w, h);
-    repaint();
+    update();
 }
 
 void MyOSGQGLWidget::mousePressEvent(QMouseEvent *me)
@@ -115,7 +113,7 @@ void MyOSGQGLWidget::mousePressEvent(QMouseEvent *me)
 
     m_manager->mouseButtonPress(but, me->pos().x(), me->pos().y());
 
-    repaint();
+    update();
 }
 
 void MyOSGQGLWidget::mouseReleaseEvent(QMouseEvent *me)
@@ -141,14 +139,14 @@ void MyOSGQGLWidget::mouseReleaseEvent(QMouseEvent *me)
     }
 
     m_manager->mouseButtonRelease(but, me->pos().x(), me->pos().y());
-    repaint();
+    update();
 }
 
 void MyOSGQGLWidget::mouseMoveEvent(QMouseEvent *me)
 {
     m_manager->mouseMove(me->pos().x(), me->pos().y());
 
-    repaint();
+    update();
 }
 
 
@@ -160,7 +158,7 @@ void MyOSGQGLWidget::keyPressEvent(QKeyEvent *ke)
     }
     else
     {
-        repaint();
+        update();
     }
 }
 
@@ -216,8 +214,6 @@ int main(int argc, char **argv)
         glWidgets[i]->m_manager->setRoot( scene );
         glWidgets[i]->m_manager->showAll();
 
-        win->init();
-
         a->processEvents();
 
         glWidgets[i]->show();
------------------------------------------------------------------------------
LogMeIn Central: Instant, anywhere, Remote PC access and management.
Stay in control, update software, and manage PCs from one command center
Diagnose problems and improve visibility into emerging IT issues
Automate, monitor and manage. Do more in less time with Central
http://p.sf.net/sfu/logmein12331_d2d
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to