OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Viewer slaves and RTTs

Goto page 1, 2  Next
 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Steal
User


Joined: 26 Jan 2017
Posts: 56

PostPosted: Fri Feb 17, 2017 7:46 pm    Post subject:
Viewer slaves and RTTs
Reply with quote

Hi,

(Edit: This problem is answered on page 2)

Sorry for one chunky looking post, but it's actually quite coherent. Can I have your short attention it's very appreciated.

I am trying to use viewer slaves with a chain of render-to-textures. I understand this is best done using several cameras.

I've looked at plenty of resources online as well as all the examples.

I am aiming for a postprocessing setup using a main camera and an orthographic camera that renders a quad to the screen.

I have a main camera that renders the scene, attached as
Code:
viewer.addSlave( main, osg::Matrix(), osg::Matrix() );


It is supposed to render the 'scene data' as set by setSceneData. This kind of works... but not without peculiar problems.

And my orthographic camera, with a quad as its child, attached as
Code:
viewer.addSlave(ortho, osg::Matrix(), osg::Matrix(), false);


One problem is that osgViewer has a default camera, and when I override it with mine using
Code:
viewer.setCamera( main )
, the z-ordering goes nuts.

The orthographic is rendering its quad properly though, which has its texture set to the color attachment of the main camera, because my main camera has
Code:
camera->attach( osg::Camera::COLOR_BUFFER, texture, 0, 0, false, 0, 0 );


However, problems remain. I have been outcommenting lines of my code to get nearer to the problem, and random things and unexpected discrepancies are happening as I go.

Code:
viewer.addSlave( camera, osg::Matrix(), osg::Matrix() );
viewer.setCamera( camera ); // unnecessary / messes up z-ordering ...


These two lines of code for example. If I switch these lines, the camera will not render (my texture will be black instead of the scene).

Another odd things, is that whilst I've set the color attachment of main, it is still writing to the screen. Sadly, when I tell it to use an FBO, it goes black completely (apparently neither rendering to my color attachment nor the screen).

So I have things working and not working, but currently I am battling some odd behavior that I cannot best.

Cheers,
Johny


Last edited by Steal on Wed Feb 22, 2017 12:23 pm; edited 1 time in total
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 56

PostPosted: Fri Feb 17, 2017 8:13 pm    Post subject:
Reply with quote

Hi,

I am repurposing the default camera using camera = viewer.getCamera(); and this seems to tackle the z-problem. Everything is in a workable state, but nothing is quite as I want it, e.g. right now I am rendering to both the screen and the color attachment.

Using a render target implementation like Frame Buffer Object just gives me black.

Cheers,
Johny
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10908

PostPosted: Fri Feb 17, 2017 9:31 pm    Post subject:
Viewer slaves and RTTs
Reply with quote

Hi Johny,

The View(er) master Camera has default StateSet assigned to that
initialises OpenGL into an appropriate state for doing typical 3D
rendering via StateSet::setGlobalDefaults(). By replacing the default
Camera my guess is that you aren't assigning your own osg::StateSet
with the appropriate state set to it, so you are just getting OpenGL
defaults which doesn't set up the depth buffer.

Robert


On 17 February 2017 at 19:46, Johny Canes <> wrote:
Quote:
Hi,

Sorry for one chunky looking post, but it's actually quite coherent. Can I have your short attention it's very appreciated.

I am trying to use viewer slaves with a chain of render-to-textures. I understand this is best done using several cameras.

I've looked at plenty of resources online as well as all the examples.

I am aiming for a postprocessing setup using a main camera and an orthographic camera that renders a quad to the screen.

I have a main camera that renders the scene, attached as

Code:
viewer.addSlave( main, osg::Matrix(), osg::Matrix() );




It is supposed to render the 'scene data' as set by setSceneData. This kind of works... but not without peculiar problems.

And my orthographic camera, with a quad as its child, attached as
Code:
viewer.addSlave(ortho, osg::Matrix(), osg::Matrix(), false);




One problem is that osgViewer has a default camera, and when I override it with mine using
Code:
viewer.setCamera( main )

, the z-ordering goes nuts.

The orthographic is rendering its quad properly though, which has its texture set to the color attachment of the main camera, because my main camera has
Code:
camera->attach( osg::Camera::COLOR_BUFFER, texture, 0, 0, false, 0, 0 );



However, problems remain. I have been outcommenting lines of my code to get nearer to the problem, and random things and unexpected discrepancies are happening as I go.


Code:
viewer.addSlave( camera, osg::Matrix(), osg::Matrix() );
viewer.setCamera( camera ); // unnecessary / messes up z-ordering ...



These two lines of code for example. If I switch these lines, the camera will not render (my texture will be black instead of the scene).

Another odd things, is that whilst I've set the color attachment of main, it is still writing to the screen. Sadly, when I tell it to use an FBO, it goes black completely (apparently neither rendering to my color attachment nor the screen).

So I have things working and not working, but currently I am battling some odd behavior that I cannot best.

Cheers,
Johny

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








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 56

PostPosted: Sat Feb 18, 2017 9:04 am    Post subject:
Reply with quote

Hi Robert,

Thanks I'll look.

Cheers,
Johny
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 56

PostPosted: Sat Feb 18, 2017 9:20 am    Post subject:
Reply with quote

Hi,

Here is a screencap where everything works. As I noticed I've already re-purposed the default camera.

If I want to narrow down on the main issue here, is that my main camera renders to both its COLOR_BUFFER0 attachment and to the screen. Setting the render target implementation to FBO will make it apparently render to neither.

Thank you, have tried everything!

Cheers,
Johny
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10908

PostPosted: Sat Feb 18, 2017 10:10 am    Post subject:
Viewer slaves and RTTs
Reply with quote

Hi Jonny,

Please don't multiple post the same content on different threads, and
in particular keep a thread consistent with a single topic. You
complain about the mailing list/forum yet here you are making things
worse for yourself and the rest of us in the community.

Robert.

On 18 February 2017 at 09:05, Johny Canes <> wrote:
Quote:
Hi Robert,

I think the current way of answering to developers is like.. an anthill. You are gratified to see people use your library and most good answers here come from you. I think others forumers are discouraged of helping others because this forum is diluted into a thin stream of non-generic problems which you silently approve or disapprove of. If you don't have a short answer to a topic in general it feels like getting the cold shoulder.

While the examples are amazing, I think the General forum is not very good at being a uh community resource.

Meant absolutely no offense,

Thank you!

Cheers,
Johny

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








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 56

PostPosted: Sat Feb 18, 2017 11:23 am    Post subject:
Reply with quote

It seems you are only using the mailing list. I've since edited.

My problem is quite consistent. It pertains to a camera that renders to both the screen and its color attachment.

Johny Canes
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10908

PostPosted: Sat Feb 18, 2017 11:51 am    Post subject:
Viewer slaves and RTTs
Reply with quote

Hi Johny,

On 18 February 2017 at 11:23, Johny Canes <> wrote:
Quote:
It seems you are only using the mailing list. I've since edited.

My problem is quite consistent. It pertains to a camera that renders to both the screen and its color attachment.

The details you've provide don't give us a clear enough idea what
specifically you are doing in our application to know what you are
doing wrong.

Could you create a small example, or modify an existing OSG example to
illustrate what you are doing. Such an example will avoid any of the
ambiguity about what you are doing.

A high level explanation of the end result are rather than the low
level details of what you implementing would be useful as it may be
that you are tackling the problem in the wrong way.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 56

PostPosted: Sat Feb 18, 2017 12:57 pm    Post subject:
Reply with quote

Okay,

Code:

// window / slave
   camera = new osg::Camera();
   osg::Viewport* viewport;

   /// {
   osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
   traits->x = 300 + 0;
   traits->y = 100 + 0;
   traits->width = nr::width;
   traits->height = nr::height;
   traits->windowDecoration = true;
   traits->doubleBuffer = true;
   traits->sharedContext = 0;
   traits->samples = 4; // MSAA
   traits->vsync = false;

   viewport = new osg::Viewport(0, 0, traits->width, traits->height);

   gc = osg::GraphicsContext::createGraphicsContext( traits.get() );
   gc->getState()->setUseModelViewAndProjectionUniforms( true );
   gc->getState()->setUseVertexAttributeAliasing( true );

   GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;

   camera = viewer.getCamera();
   camera->setName( "Main" );
   camera->setGraphicsContext( gc.get() );

   camera->setClearColor(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
   camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );
   //camera->getOrCreateStateSet()->setTextureAttributeAndModes( 0, texture, osg::StateAttribute::ON );

   camera->setDrawBuffer( buffer );
   camera->setReadBuffer( buffer );
   camera->setRenderOrder( osg::Camera::RenderOrder::PRE_RENDER );
   //camera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );
   
   camera->attach( osg::Camera::COLOR_BUFFER0, texture );
   //camera->attach( osg::Camera::COLOR_BUFFER, texture, 0, 0, false, 0, 0 );

   //viewer.addSlave( camera, osg::Matrix(), osg::Matrix() );

   //viewer.setCamera( camera ); // unnecessary / messes up z-ordering ...

   //camera->addChild( root.get() );
   /// }


This makes a window. I get it that a window is backed by a camera / GC.

So naturally, since I'm using the original camera, my camera, 'Main', will render to its window. It would be ideal to turn this off, and only have this camera render to a hidden buffer (FBO?). Using a pbuffer / pbuffer-rtt is overkill and I'm not sure I understand that approach.

Cheers,
Johny
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10908

PostPosted: Sat Feb 18, 2017 1:28 pm    Post subject:
Viewer slaves and RTTs
Reply with quote

Hi Johny,

Could you do as requested and create a small example, i.e. something
that others can compile and run to see what the problem is?

Extracting code from a wider program sometimes can be enough, but to
compile and test your program I'd need to write the extra code around
it to get a compilable program, I'd have to guess what types you are
using, guess what type of data you are assigning. With each guess
we'd need to make we add an extra variable to takes away from what you
are seeing on screen at your end so less chance of knowing what we see
is what you see.

As I said, the best way is create an example, there are plenty of OSG
examples that you could modify.

Robert.

On 18 February 2017 at 12:57, Johny Canes <> wrote:
Quote:
Okay,


Code:

// window / slave
camera = new osg::Camera();
osg::Viewport* viewport;

/// {
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = 300 + 0;
traits->y = 100 + 0;
traits->width = nr::width;
traits->height = nr::height;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = 0;
traits->samples = 4; // MSAA
traits->vsync = false;

viewport = new osg::Viewport(0, 0, traits->width, traits->height);

gc = osg::GraphicsContext::createGraphicsContext( traits.get() );
gc->getState()->setUseModelViewAndProjectionUniforms( true );
gc->getState()->setUseVertexAttributeAliasing( true );

GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;

camera = viewer.getCamera();
camera->setName( "Main" );
camera->setGraphicsContext( gc.get() );

camera->setClearColor(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );
//camera->getOrCreateStateSet()->setTextureAttributeAndModes( 0, texture, osg::StateAttribute:ShockedN );

camera->setDrawBuffer( buffer );
camera->setReadBuffer( buffer );
camera->setRenderOrder( osg::Camera::RenderOrder::PRE_RENDER );
//camera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );

camera->attach( osg::Camera::COLOR_BUFFER0, texture );
//camera->attach( osg::Camera::COLOR_BUFFER, texture, 0, 0, false, 0, 0 );

//viewer.addSlave( camera, osg::Matrix(), osg::Matrix() );

//viewer.setCamera( camera ); // unnecessary / messes up z-ordering ...

//camera->addChild( root.get() );
/// }




This makes a window. I get it that a window is backed by a camera / GC.

So naturally, since I'm using the original camera, my camera, 'Main', will render to its window. It would be ideal to turn this off, and only have this camera render to a hidden buffer (FBO?). Using a pbuffer / pbuffer-rtt is overkill and I'm not sure I understand that approach.

Cheers,
Johny

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








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 56

PostPosted: Sat Feb 18, 2017 2:36 pm    Post subject:
Reply with quote

Hi,

Here is a test. It loads the image but I can't get either the mainCamera color buffer (gTexture) to render on the quad or the OpenSceneGraph-Data\Images\forestRoof.png.

Ideally, what I wanted is for mainCamera to not(!) draw on the screen, only inside of gTexture. However, in other tests setting the rendertargetimp. to FBO will produce black everything.

Code:
#include "stdafx.h"

#include <osgViewer/Viewer> // includes a lot of things for us
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osg/Material>


osg::ref_ptr<osg::GraphicsContext> gGc;
osgViewer::Viewer* gViewer;
osg::Camera* gCamera;
osg::Texture* gTexture;

osg::Camera* gOrtho;
osg::ref_ptr<osg::Geode> gQuad;

osg::Group* gRoot;

void funcSlave() {
   osg::Texture2D* texture2D = new osg::Texture2D;
   texture2D->setTextureSize(1024, 1024);
   texture2D->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
   texture2D->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
   gTexture = texture2D;

   osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
   traits->x = 300;
   traits->y = 100;
   traits->width = 1024;
   traits->height = 768;
   traits->windowDecoration = true;
   traits->doubleBuffer = true;
   traits->sharedContext = 0;
   traits->samples = 4; // MSAA
   traits->vsync = false;

   gGc = osg::GraphicsContext::createGraphicsContext( traits.get() );
   gGc->getState()->setUseModelViewAndProjectionUniforms( true );
   gGc->getState()->setUseVertexAttributeAliasing( true );

   GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;

   osg::Camera* camera = gViewer->getCamera(); // alternatively: new osg::Camera( viewer->getCamera() );
   camera->setName( "Main" );
   camera->setGraphicsContext( gGc.get() );

   camera->setClearColor( osg::Vec4f(1, 0, 0, 1) );
   camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );

   camera->setDrawBuffer( buffer );
   camera->setReadBuffer( buffer );
   camera->setRenderOrder( osg::Camera::RenderOrder::PRE_RENDER );
   //camera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );
   
   camera->attach( osg::Camera::COLOR_BUFFER, gTexture );

   gCamera = camera;

}

void funcOrtho() {
   int Width = 512, Height = 512;

   osg::Camera* ortho = gOrtho = new osg::Camera;
   ortho->setName( "Ortho" );

   ortho->setGraphicsContext( gGc.get() );

   ortho->setClearColor( osg::Vec4f(1,0,1,1) );
   ortho->setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

   ortho->setProjectionMatrix(osg::Matrix::ortho2D(0, Width, 0, Height));

   //ortho->setProjectionMatrix(osg::Matrix::ortho2D(0,1,0,1));

   ortho->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
   ortho->setViewMatrix( osg::Matrix::identity() );
   ortho->setRenderOrder( osg::Camera::POST_RENDER );

   ortho->setViewport(0, 0, Width, Height);

   auto qaud = osg::createTexturedQuadGeometry(osg::Vec3(), osg::Vec3(Width, 0.0, 0.0), osg::Vec3(0.0, Height, 0.0));

   auto quad = gQuad = new osg::Geode;
   quad->addDrawable( qaud );

   auto image = osgDB::readImageFile("Images/forestRoof.png");
   if (!image)
      OSG_NOTICE<<"no image";

   auto texture = new osg::Texture2D( image );

   quad->getOrCreateStateSet()->setTextureAttributeAndModes( 0, texture );

   osg::ref_ptr<osg::Material> m = new osg::Material;
   m->setColorMode(osg::Material::DIFFUSE);
   m->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 1, 1, 1));

   quad->getOrCreateStateSet()->setAttributeAndModes( m.get(), osg::StateAttribute::ON);

   // Can't get it to brighten up...

   ortho->addChild( quad );

   gViewer->addSlave(ortho, osg::Matrix(), osg::Matrix(), false);

   // ortho->setPreDrawCallback( new Postprocesser( texture ) );
}

int main(int argc, char **argv) {


   gViewer = new osgViewer::Viewer;
   gRoot = new osg::Group;
   
   funcSlave();

   osg::ref_ptr<osg::Node> cessna = osgDB::readRefNodeFile("cessna.osgt");

   if (!cessna) {
        OSG_NOTICE<<"Cannot not find model 'cessna.osg' to render"<<std::endl;
        return 404;
    }

   gRoot->addChild( cessna.get() );
   
   funcOrtho();

   //gViewer->getLight()->setLightNum(0);
   //gViewer->setLightingMode(osgViewer::View::LightingMode::NO_LIGHT);

   gViewer->setSceneData( gRoot );

    //gRoot->getOrCreateStateSet()->setMode(GL_LIGHTING, false);
   
   gViewer->realize();

   gViewer->run();
};


Thank you!

Cheers,
Johny
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10908

PostPosted: Sat Feb 18, 2017 5:14 pm    Post subject:
Viewer slaves and RTTs
Reply with quote

Hi Johny,

It's a bit painful to ready example code that mixes global C pointers
with reference counting objects. There is very strong chance that'll
you be leaking objects or end up with dangling pointers. I strongly
recommend against doing this even in an example as it not only sets a
bad example to yourself and potential problems down the line, it also
gives others in the community, who might read your code looking for
inspiration, and poor start as they might not realize that it's a
really bad programming practice.

As for you problem, reviewing the code the item that jumps out at me
is setting osg::State to use uniforms for the modelview and project
matrix and aliasing of the vertex attributes but you never provide any
shaders to utilize them., so you are disabling part of the fixed
function pipeline but not privide any replacement, so if you don;t see
what you are expecting it's not too surprising The OSG doesn't
provide these shaders for you and will be default use the fixed
function pipeline. These setting in osg::State are only appropriate
for GLES2 or GL3 core profile where shaders are required and no built
in uniform or vertex attributes are provided.

I would recommend you remove these lines of code and just rely upon
the fixed function pipeline. Once you've got a bit further with you
leaning about OpenGL/shaders/OSG then you can start thinking about
re-enabling them.

Robert



On 18 February 2017 at 14:36, Johny Canes <> wrote:
Quote:
Hi,

Here is a test. It loads the image but I can't get either the mainCamera color buffer (gTexture) to render on the quad or the OpenSceneGraph-Data\Images\forestRoof.png.

Ideally, what I wanted is for mainCamera to not(!) draw on the screen, only inside of gTexture. However, in other tests setting the rendertargetimp. to FBO will produce black everything.


Code:
#include "stdafx.h"

#include <osgViewer/Viewer> // includes a lot of things for us
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osg/Material>


osg::ref_ptr<osg::GraphicsContext> gGc;
osgViewer::Viewer* gViewer;
osg::Camera* gCamera;
osg::Texture* gTexture;

osg::Camera* gOrtho;
osg::ref_ptr<osg::Geode> gQuad;

osg::Group* gRoot;

void funcSlave() {
osg::Texture2D* texture2D = new osg::Texture2D;
texture2D->setTextureSize(1024, 1024);
texture2D->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
texture2D->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
gTexture = texture2D;

osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = 300;
traits->y = 100;
traits->width = 1024;
traits->height = 768;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = 0;
traits->samples = 4; // MSAA
traits->vsync = false;

gGc = osg::GraphicsContext::createGraphicsContext( traits.get() );
gGc->getState()->setUseModelViewAndProjectionUniforms( true );
gGc->getState()->setUseVertexAttributeAliasing( true );

GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;

osg::Camera* camera = gViewer->getCamera(); // alternatively: new osg::Camera( viewer->getCamera() );
camera->setName( "Main" );
camera->setGraphicsContext( gGc.get() );

camera->setClearColor( osg::Vec4f(1, 0, 0, 1) );
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );

camera->setDrawBuffer( buffer );
camera->setReadBuffer( buffer );
camera->setRenderOrder( osg::Camera::RenderOrder::PRE_RENDER );
//camera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );

camera->attach( osg::Camera::COLOR_BUFFER, gTexture );

gCamera = camera;

}

void funcOrtho() {
int Width = 512, Height = 512;

osg::Camera* ortho = gOrtho = new osg::Camera;
ortho->setName( "Ortho" );

ortho->setGraphicsContext( gGc.get() );

ortho->setClearColor( osg::Vec4f(1,0,1,1) );
ortho->setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

ortho->setProjectionMatrix(osg::Matrix::ortho2D(0, Width, 0, Height));

//ortho->setProjectionMatrix(osg::Matrix::ortho2D(0,1,0,1));

ortho->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
ortho->setViewMatrix( osg::Matrix::identity() );
ortho->setRenderOrder( osg::Camera::POST_RENDER );

ortho->setViewport(0, 0, Width, Height);

auto qaud = osg::createTexturedQuadGeometry(osg::Vec3(), osg::Vec3(Width, 0.0, 0.0), osg::Vec3(0.0, Height, 0.0));

auto quad = gQuad = new osg::Geode;
quad->addDrawable( qaud );

auto image = osgDB::readImageFile("Images/forestRoof.png");
if (!image)
OSG_NOTICE<<"no image";

auto texture = new osg::Texture2D( image );

quad->getOrCreateStateSet()->setTextureAttributeAndModes( 0, texture );

osg::ref_ptr<osg::Material> m = new osg::Material;
m->setColorMode(osg::Material::DIFFUSE);
m->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 1, 1, 1));

quad->getOrCreateStateSet()->setAttributeAndModes( m.get(), osg::StateAttribute:ShockedN);

// Can't get it to brighten up...

ortho->addChild( quad );

gViewer->addSlave(ortho, osg::Matrix(), osg::Matrix(), false);

// ortho->setPreDrawCallback( new Postprocesser( texture ) );
}

int main(int argc, char **argv) {


gViewer = new osgViewer::Viewer;
gRoot = new osg::Group;

funcSlave();

osg::ref_ptr<osg::Node> cessna = osgDB::readRefNodeFile("cessna.osgt");

if (!cessna) {
OSG_NOTICE<<"Cannot not find model 'cessna.osg' to render"<<std::endl;
return 404;
}

gRoot->addChild( cessna.get() );

funcOrtho();

//gViewer->getLight()->setLightNum(0);
//gViewer->setLightingMode(osgViewer::View::LightingMode::NO_LIGHT);

gViewer->setSceneData( gRoot );

//gRoot->getOrCreateStateSet()->setMode(GL_LIGHTING, false);

gViewer->realize();

gViewer->run();
};



Thank you!

Cheers,
Johny

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








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 56

PostPosted: Sat Feb 18, 2017 6:17 pm    Post subject:
Reply with quote

Hi,

I am not wrapping everything in ref_ptrs. And for the purpose of brevity I did not include a simple quad texel shader.

I've built a fully mature multimaterial shading system including physical / phong into my OSG project, including pointlights, spotlights and hemilights so far.

I am not half a bad programmer, I actually ported my game from Three.js to OpenSceneGraph in several days e.g. http://imgur.com/a/B5h66

I've since done a lot more work, and only one problem remains, which is that my Camera writes directly to the window, as well as its color attachment. I've actually wrote this 5 times throughout my topic, and it remains the only answer I wish to have answered.

Thank you!

Cheers,
Johny
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 56

PostPosted: Sat Feb 18, 2017 6:20 pm    Post subject:
Reply with quote

Hi,

Might I add it was quite nontrivial to port threejs, but it all works. Now only one thing remains, which is either using a pbuffer gc or to somehow prevent my camera from drawing directly to its window.

Thank you!

Cheers,
Johny
Back to top
View user's profile Send private message
SMesserschmidt (Sebastian Messerschmidt)
Forum Moderator


Joined: 10 Sep 2013
Posts: 726

PostPosted: Sat Feb 18, 2017 6:30 pm    Post subject:
Viewer slaves and RTTs
Reply with quote

Hi Johny,
Quote:
Hi,

Might I add it was quite nontrivial to port threejs, but it all works. Now only one thing remains, which is either using a pbuffer gc or to somehow prevent my camera from drawing directly to its window.
Well, then simply render to a FBO and pass the texture to your final
camera which will render to the framebuffer. The multiplerendertargets
example might give you some pointers.


Cheers
Sebastian
Quote:

Thank you!

Cheers,
Johny

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









------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts object deletion and rtts psquare General 2 Fri Jan 27, 2017 2:52 pm View latest post
No new posts About Viewer->updateTraversal() Rambabu General 2 Tue Dec 27, 2016 12:05 pm View latest post
No new posts Mouse Picking with Oculus Viewer matt_kennett General 0 Tue Nov 01, 2016 5:31 am View latest post
No new posts Latest OSG cannot realize viewer unde... kornerr General 4 Wed Oct 19, 2016 2:29 pm View latest post
No new posts Explicitly synchronize all viewer cam... mille25 General 4 Mon Jul 04, 2016 2:25 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP