Hi J-S,

Try this:

void  QOsgScene::drawBackground ( QPainter * painter, const QRectF & rect )
{
        if (m_redrawEnabled == false){
                return;
        }

        emit aboutToDraw();

        // Only works with OpenGL
        if( painter->paintEngine()->type() == QPaintEngine::OpenGL )
        {
                GLenum errorNo;

                // Qt OpenGL State Initialization takes
                // place before we get here, on every frame.
                // We can assume that OpenGL state is reset to
                // default on every frame.

                // Push initialized state onto the stack so that we can
                // Recover it later for further Qt Drawing.
                glPushAttrib(GL_ALL_ATTRIB_BITS);
                glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);

                // Fixup stuff that Qt Modifies from default state that
                // OSG expects.
                glShadeModel(GL_SMOOTH);

                // Push matricies
                glMatrixMode(GL_TEXTURE);
                glPushMatrix();
                glLoadIdentity();
                glMatrixMode(GL_PROJECTION);
                glPushMatrix();
                glLoadIdentity();
                glMatrixMode(GL_MODELVIEW);
                glPushMatrix();
                glLoadIdentity();

                // Make sure that OSG's state is prepared based on the last 
state
                // recorded (if available).  The first frame is different.
                osg::State *state = 
getCamera()->getGraphicsContext()->getState();
                state->reset();
                state->apply(m_lastStateSet.get());

                // Run a frame: this is where the action happens.
                frame();

                // Store the OSG state for restoration in the next frame.
                
getCamera()->getGraphicsContext()->getState()->captureCurrentState(*m_lastStateSet);

                // Pop matricies.
                glMatrixMode(GL_PROJECTION);
                glPopMatrix();
                glMatrixMode(GL_TEXTURE);
                glPopMatrix();
                glMatrixMode(GL_MODELVIEW);
                glPopMatrix();

                // Pop Attribs, now we're ready to continue
                // Drawing with OpenGL.
                glPopAttrib();
                glPopClientAttrib();

                errorNo = glGetError();
                if (errorNo!=GL_NO_ERROR)
                {
                        LOG_MSG(logERROR) <<"Post-Frame: Detected OpenGL error 
(frame " <<
m_frameNo << ") '" <<gluErrorString(errorNo) << "'";
                }

                ++m_frameNo;
        }
        else
        {
                qWarning("QOsgScene: drawBackground needs a QGLWidget to be set 
as
viewport on the graphics view.");
        }
}
_________________________________________________________
Sean Spicer
Executive Vice President & Chief Technology Officer
Aqumin (www.aqumin.com)
Office....+1.281.466.4848
Mobile...+1.713.447.2706
Fax.......+1.281.466.4849



On Tue, Apr 21, 2009 at 1:28 PM, Jean-Sébastien Guay
<[email protected]> wrote:
> Hello Christian,
>
>> I have run into another problem. With my current approach the scene
>> loses all lighting after
>> the first frame has been drawn. All polygons appear in flat shading. I
>> have currently no idea what is causing this. At first I was not
>> noticing this because I rendered cow.osg which uses a metallic effect
>> (environment maps?). But on other scenes the loss of lighting is
>> apparent.
>
> This suggests that when pushing and popping state in order for Qt to draw
> its widgets, something is not pushed/popped correctly, probably GL_LIGHTING,
> GL_LIGHT0-GL_LIGHT7 or something like that? Perhaps glShadeModel? ...
>
> Just a possible avenue for investigation. I know it sounds obvious, but the
> error is obviously caused by something you overlooked, so listing things
> that should not be overlooked seems like the only way I can help... :-)
>
> J-S
> --
> ______________________________________________________
> Jean-Sebastien Guay    [email protected]
>                               http://www.cm-labs.com/
>                        http://whitestar02.webhop.org/
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to