Re: [osg-users] osgQt + OSG 3.6.2 Status

2018-07-18 Thread Stuart Mentzer
Thanks for the outline. I will work through this and experiment with my code. 
If I learn anything interesting/useful I'll post it.

Cheers,
Stuart

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74360#74360





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgQt + OSG 3.6.2 Status

2018-07-18 Thread James Davis
I'm no code guru (more like a hacker), but I'll post what I do if it makes 
sense and helps.  Had to hand-type this as my code is on a different PC and I 
couldnt copy.  You'll probably see some typos and short cuts.   

My setup is in a class called OSGDataViewer which double inherits a view base 
class (pretty much a QMainWindow) and a CompositeViewer.

I define a osgQt::GraphisWindowQt* m_gw member along with all my manipulators, 
rootnode hud etc in this OSGDataViewer class.

In my constructor, I call a method initializeOSG() which does the following:

setThreadModel(osgViewer::Viewer::SingleThreaded);
osg::ref_ptr cam0 = this->createCamera(x(), y(), height(), "Main 
Camera", false); //more on createCamera in a bit.  x,y,width,height comes from 
qmainwindow

QWidget* GLWidget = m_gw->getGLWidget();

//finally set my central widget
this->setCentralWidget(GLWidget);

I then setup a cam1 which is my hud camera.  I'll post if you want to see it.

Next I set up my root node, depthPartitionNode, and others.

finally, I'll call another local method:
addNewView(cam0.get(), rootnode.get(), "MainView") //i'd call this with cam1 
also.  This method is described below also

finally, my difference scene manipulators are created  and i'd do something 
like the following:

this->getView(0)->setCameraManipulator(m_keyswitchManipulator.get())

I'd also setup callbacks as example:
this->getView(1)->getCamera()->setFinalDrawCallbac(w_WinCapCallback.get())


here is my createCamera method:
osg::Camera* OSGDataViewer::createCamera(int x, y, w, h, name...)
osg::ref_ptr ds = osg::DisplaySettings::instance();
ds->setMaxNumberOfGraphicContext(20)
osg::ref_ptr traits = new 
osg::GraphicsContext::Traits;
traits->readDISPLAY
if (traits->displayNum<0) traigs->displayNum=0;

traits->windowName = name
traits->.
  x=x
  y=y
  width=w
  alpha = ds->getMinimumNumberAlphaBits
  stencil = ds->getMinimumNumStencilBits()
  windowDecoration = false
  doubleBuffer = true;
  sampleBuffers = ds->getMultiSamples
  samples = ds->getNumMultiSamples

  traits->inheritedWindowData = new 
osgViewer::GraphicsWindowWin32::WindowData((HWND)QWidget::winID());
osgQt::GraphicsWindowQt *GWQ;

if (!m_gw)
  traits->sharedContext = 0;
   GWQ = new osgQt::GraphicsWindowQt(traits.get())
   GWQ->createNewContextID
else
   traits->sharedContext = m_gw
   GWQ = new osgQt::GraphicsWindowQt(traits.get())
   GWQ->createNewContextID();

GWQ->setName(name)
osg::ref_ptr camera = new osg::Camera()
camera->setGraphicsContext(GWQ);

QWidget* GLWidget = GWQ->getGLWidget();
GLWidget->setAttribute(Qt::WA_PaintOnScreen)
   . WA_NoSystemBackground
 WA_OpaquePaintEvent
 WA_DeleteOnClose
GLWidget->setAttribute(Qt::ClickFocus)

camera->setClearColor(...
camera->setViewPort(new osg::Viewport(0, 0, traits->width, traits->height))
camera ->setLODScale(3.0)
camera->setProjectionMatrixAsPerspective(..
osg::StateSet* stateset = camera->getOrCreateStateSet()
stateset->setGlobalDefaults()
return camera.release()



here is my addNewView method:
void OSGDataViewer::addNewView(osg::Camera* camera, osg::Node* scene, string 
viewname)

osgVIewer::View* view = new osgVIewer::View;
view->setCamera(camera)
view->adddEventHandler(new 
osgGA::StateSetManipulator(view->getCamera()->getOrCreateStateSet()))
view->addEventHandler(new osgVIewer::ThreadingHandler)
  ::WindowSizeHandler)
  ::StatsHandler)
view->setLightingMode(osg::View::SKY_LIGHT)
view->getDatabasePaer()->setUnrefImageDataAfterApplyPolicy(true, valse)

this->addView(view)

view->setSceneData(scene);

Hope this is as clear as mud!

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74359#74359





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgQt + OSG 3.6.2 Status

2018-07-18 Thread Stuart Mentzer
Hi Robert,

Yes, I'm aware of the examples and osgQtWidgets runs fine with my builds. But 
none of them match how we have used osgQt in the past with a single-view class 
derived from osgQt::GLWidget and osgViewer and a GraphicsWindowQt. And there 
are no examples for the new osgQOpenGL approach.

My viewer code works fine in OSG 3.4.1 on Windows and Linux but doesn't work 
with 3.6.2 and the current osgQt master, and I'm not sure where the problem 
lies.

Cheers,
Stuart

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74358#74358





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] strange behaviour with osgText::Text

2018-07-18 Thread Christoph Dohmen
Hi,

I have a strange effect with osgText::Text. My original goal was to have a 
constant pixel-sized Text close to the starting point of a line. Using dummy 
values everthing is fine. But using real values the textsize changes!

See the attached source. The wrong behaviour could be seen by setting 
USE_WRONG_VALUES to 1 and the right behaviour could be seen by setting it to 0.

I use OSG 3.6.1 under opensuse.

Thank you!

Cheers,
Christoph

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74356#74356



#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

static const char * vLineShader = {
"#version 330 core\n"
"in vec4 osg_Vertex;\n"
"in vec4 osg_Color;\n"
"uniform mat4 osg_ModelViewProjectionMatrix;\n"
"out vec4 vertexColor;\n"
"void main(void)\n"
"{\n"
"gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex;\n"
"vertexColor = osg_Color; \n"
"}\n"
};

static const char * fLineShader = {
"#version 330 core\n"
"in vec4 vertexColor;\n"
"void main(void)\n"
"{\n"
"gl_FragColor = vertexColor;\n"
"}\n"
};

#define USE_WRONG_VALUES 1

osg::ref_ptr buildLine()
{
osg::ref_ptr geometry = new osg::Geometry;
geometry->setUseDisplayList(false);

osg::ref_ptr vertices = new osg::Vec3Array;
#if defined( USE_WRONG_VALUES ) && USE_WRONG_VALUES
vertices->push_back( osg::Vec3( 7300.0, 1300.0, 0.0 ) );
vertices->push_back( osg::Vec3( 7400.0, 1400.0, 0.0 ) );
vertices->push_back( osg::Vec3( 7500.0, 1400.0, 0.0 ) );
#else
vertices->push_back( osg::Vec3(  0.0,  0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 10.0, 10.0, 0.0 ) );
vertices->push_back( osg::Vec3( 20.0, 10.0, 0.0 ) );
#endif

geometry->setVertexArray( vertices );


osg::ref_ptr drawElements = new osg::DrawElementsUInt( osg::PrimitiveSet::LINE_STRIP, 0 );
drawElements->push_back( 0 );
drawElements->push_back( 1 );

geometry->addPrimitiveSet( drawElements );


osg::ref_ptr color( new osg::Vec4Array );
color->push_back( osg::Vec4( 1.0, 0.0, 0.0, 1.0 ) );

geometry->setColorArray( color, osg::Array::BIND_OVERALL );


geometry->getOrCreateStateSet()->setAttributeAndModes( new osg::LineWidth( 10 ), osg::StateAttribute::ON );


osg::ref_ptr program = new osg::Program;
program->addShader(new osg::Shader(osg::Shader::VERTEX, vLineShader));
program->addShader(new osg::Shader(osg::Shader::FRAGMENT, fLineShader));
geometry->getOrCreateStateSet()->setAttributeAndModes(program, osg::StateAttribute::ON);

return geometry;
}

osg::ref_ptr buildText()
{
osg::ref_ptr textItem = new osgText::Text;

textItem->setFont( "/home/chris/SOURCEN/OpenSceneGraph-TrainingMaterials-CAE/Data/OpenSceneGraph-Data/fonts/times.ttf" );
textItem->setColor( osg::Vec4( 0.0, 1.0, 0.0, 1.0 ) );
textItem->setText( "FOO" );
textItem->setAxisAlignment( osgText::Text::SCREEN );
textItem->setFontResolution( 40, 40 );
textItem->setCharacterSize( 32 );
textItem->setCharacterSizeMode( osgText::Text::SCREEN_COORDS );
textItem->setDrawMode( osgText::Text::TEXT | osgText::Text::BOUNDINGBOX );
textItem->setAlignment( osgText::TextBase::CENTER_CENTER );
#if defined( USE_WRONG_VALUES ) && USE_WRONG_VALUES
textItem->setPosition( osg::Vec3( 7300.0, -1500.0, 0.0 ) );
#else
textItem->setPosition( osg::Vec3( -5.0, -5.0, 0.0 ) );
#endif
return textItem;
}

osg::ref_ptr buildIt()
{
osg::Group * group = new osg::Group;

group->addChild( buildLine() );

group->addChild( buildText() );

return group;
}

int main ( int argc, char **argv )
{
// constrcut the viewer.
// use an ArgumentParser object to manage the program arguments.
osg::ArgumentParser arguments( , argv );
osgViewer::Viewer viewer( arguments );

viewer.setSceneData( buildIt() );

viewer.realize();

osg::DisplaySettings::instance()->setTextShaderTechnique( "NONE" );


osg::State * state = viewer.getCamera()->getGraphicsContext()->getState();
if ( 0 == state )
{
state = new osg::State;
}

state->setUseModelViewAndProjectionUniforms( true );
state->setUseVertexAttributeAliasing( true ) ;
viewer.getCamera()->getGraphicsContext()->setState( state );

viewer.getCamera()->getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON );
viewer.getCamera()->getOrCreateStateSet()->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
viewer.getCamera()->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );

// run the viewers main loop.
return viewer.run();
}
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgQt + OSG 3.6.2 Status

2018-07-18 Thread Robert Osfield
Hi Stuart,

On Tue, 17 Jul 2018 at 23:14, Stuart Mentzer  wrote:
> Thanks for the info @davisjamesf. I wish I knew what secret sauce was needed 
> to get this running. I'll keep trying and maybe I'll have luck with some 
> future osgQt release.
>
> If you or anyone have some example code for a single view class derived from 
> osgQt::GLWidget and osgViewer (or a better design) that can display a scene 
> using current osgQt + OSG 3.6.2 that should get me started.

There are examples in osgQt:

$ ls osgQt/examples/

   osgqfont  osgQtBrowser  osgQtWidgets  osgviewerQt

I have just test osgQt master against OpenSceneGraph-3.6 branch (same
as 3.6.2) and it works OK for me.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org