Hi Robert,
Thanks for the reply.
Basically, we have a big QT based application with 2D visuals which appear
in normal QT widgets and 3D visuals which we draw using OSG inside
QGLWidgets. However, ultimately we would like to be able to draw the 2D
visuals directly over the 3D scene.
We are using QT 4.3.0 and OSG 1.2.
My update camera method just sets the view matrix based on some current
dolly and rotation parameters.
void Viewer::updateCamera()
{
qDebug() << "Update Camera";
osg::Matrix vm = osg::Matrix::translate( -orbitCentre );
vm *= osg::Matrix::rotate( cameraR.conj() );
vm.setTrans( vm.getTrans() + osg::Vec3( 0., 0., -dolly ) );
m_scene->setViewMatrix( vm );
}
The resizeGL method updates the viewport and projection matrix.
void Viewer::resizeGL( int w, int h)
{
qDebug() << "ResizeGL: " << w << " " << h;
m_scene->setViewport( 0, 0, w, h );
const float VFOV = 30.f;
const float ASPECT_RATIO = static_cast< float >( w ) /
static_cast< float >( h );
const float Z_N = 0.002f;
const float Z_F = 1.000f;
osg::Matrix projection;
projection.makePerspective( VFOV, ASPECT_RATIO, Z_N, Z_F );
m_scene->setProjectionMatrix( projection );
}
The m_scene variable in the paint event method is a osgUtil::SceneView which
is set up in the initializeGL method.
void Viewer::initializeGL()
{
m_scene = new osgUtil::SceneView;
m_scene->setDefaults();
m_scene->setClearColor( osg::Vec4( 247.0 / 255.0, 150.0 / 255.0, 150.0 /
255.0, 1.0) );
m_scene->getState()->setContextID(
osg::GraphicsContext::createNewContextID() );
m_scene->setNearFarRatio( 0.02f );
m_scene->setSceneData( new osg::Group );
updateCamera();
}
If the drawLine command is commented out of the paintEvent everything works
otherwise as I said the 3D mesh only appears to be drawn on the first paint
event after it is loaded then on the next paint event it disappears.
The mesh is added to the scene view using:
m_scene->getSceneData()->asGroup()->addChild( mesh );
Thanks for any help / suggestions,
Pete.
On 6/12/07, Robert Osfield <[EMAIL PROTECTED]> wrote:
Hi Peter,
What be hidden inside the updateCamera() call???
Why use overpainting? What effect are you after?
Robert.
On 6/11/07, Peter O <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm trying to adapt the QT overpainting example ( drawing 2D primitives
and
> text over a 3D scene ) to use osg instead of raw openGL. However, the
mesh
> I'm drawing only appears for the first paintEvent and then disappears
from
> the view. If I comment out any qpainter draw commands the mesh is
correctly
> redrawn and can be rotated etc.
>
> Has anyone managed to get overpainting to work with osg?
>
> Here is my paintEvent method in case anyone can spot any obvious errors:
>
> void Viewer::paintEvent( QPaintEvent * )
> {
> qDebug() << "PaintEvent";
>
> QPainter painter;
> painter.begin(this);
> painter.setRenderHint(QPainter::Antialiasing);
> painter.setBrush( Qt::red );
>
> // Preserve the current GL state.
> glPushAttrib( GL_ALL_ATTRIB_BITS );
> glMatrixMode(GL_PROJECTION);
> glPushMatrix();
> glMatrixMode(GL_TEXTURE);
> glPushMatrix();
> glMatrixMode(GL_MODELVIEW);
> glPushMatrix();
>
> // Do our OSG stuff...
> /resizeGL( width(), height() );
> updateCamera();
>
> m_scene->update();
> m_scene->cull();
> m_scene->draw();
>
> // Restore the old GL state.
> glMatrixMode(GL_TEXTURE);
> glPopMatrix();
> glMatrixMode(GL_PROJECTION);
> glPopMatrix();
> glMatrixMode(GL_MODELVIEW);
> glPopMatrix();
> glPopAttrib();
>
> painter.drawLine( 0, 0, width(), height() );
>
> painter.end();
>
> }
>
> Thanks in advance for any tips or help.
>
> Pete.
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://openscenegraph.net/mailman/listinfo/osg-users
> http://www.openscenegraph.org/
>
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/