Hey,
I can't find a solution. Maybe it helps if I post some code I extracted from my
project. It demonstrates my camera- and shader-setup. In the case I only pass
prjection-matrix to vertex-shader and replace "testmatrix*gl_Vertex" with
"gl_ProjectionMatrix*testmatrix*gl_Vertex" everything works fine. But when I
try to pass the whole modelviewprojection matrix it failed and nothing of the
scene is rendered.
Thanks for help!
osg-code:
Code:
struct TestCallback : public osg::Uniform::Callback{
TestCallback(osg::Camera* viewercam, osg::Camera* othercam)
:_viewercam(viewercam),_othercam(othercam){
}
virtual void operator () (osg::Uniform* uniform, osg::NodeVisitor* nv){
osg::Matrixd vmatrix=_viewercam->getViewMatrix();
//vmatrix=vmatrix.rotate(- M_PI / 2.0, 1, 0, 0);
osg::Matrixd wmatrix=osg::computeLocalToWorld(nv->getNodePath());
osg::Matrixd mvmatrix = _viewercam->getProjectionMatrix()*vmatrix*wmatrix;
uniform->set(mvmatrix);
}
osg::Camera* _viewercam;
osg::Camera* _othercam;
};
class MovementPostDrawCallback : public osg::Camera::DrawCallback{
public:
MovementPostDrawCallback(osg::PositionAttitudeTransform* patnode, double
velocity)
:_patnode(patnode),_velocity(velocity){
_startpos=_patnode->getPosition();
}
virtual void operator()(osg::RenderInfo &renderinfo) const{
osg::Vec3 crtpos=_patnode->getPosition();
double
crttimestp=renderinfo.getState()->getFrameStamp()->getSimulationTime();
double bankangle=0.7;
crtpos[0]=_startpos[0]+sin(crttimestp)*100.0*_velocity;
bankangle=-sin(crttimestp)/2;
_patnode->setPosition(crtpos);
_patnode->setAttitude(osg::Quat(0.0, osg::X_AXIS, bankangle, osg::Y_AXIS,
0.0, osg::Z_AXIS));
}
osg::PositionAttitudeTransform* _patnode;
osg::Vec3 _startpos;
double _velocity;
};
bool loadShaderSrcFiles(std::string vssrcfile, osg::Shader* vs, std::string
fssrcfile, osg::Shader* fs){
bool returnval=true;
if(!vs->loadShaderSourceFromFile(vssrcfile)){
osg::notify(osg::WARN)<<"Error while loading vertexshader-sourcefile
("setTextureSize(width,height);
texture->setInternalFormat(GL_RGBA);
texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
//rtt cam
osg::ref_ptr rttcam = new osg::Camera();
rttcam->setViewport(0,0,width, height);
rttcam->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
rttcam->setClearColor(osg::Vec4(105/255.0,125/255.0,202/255.0,1.0));
rttcam->setRenderOrder(osg::Camera::PRE_RENDER,1);
rttcam->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
rttcam->setReferenceFrame(osg::Transform::RELATIVE_RF);
rttcam->setProjectionMatrix(osg::Matrixd::identity());
rttcam->attach(osg::Camera::COLOR_BUFFER, texture.get());
rttcam->addChild(root);
rttcam->setPostDrawCallback(new
MovementPostDrawCallback(sbuilder.getCessnaPAT(),0.8));
rttcam->setName("RTTCam");
std::cout<<"rttcam created...\n";
//setup postrender-geode
osg::ref_ptr prquad =
osg::createTexturedQuadGeometry(osg::Vec3(),osg::Vec3(width,0.0,0.0),osg::Vec3(0.0,height,0.0));
osg::ref_ptr prgeode = new osg::Geode();
prgeode->addDrawable(prquad.get());
prgeode->setName("PostRenderDisplayGeode");
prquad->getOrCreateStateSet()->setTextureAttributeAndModes(0,texture.get(),osg::StateAttribute::ON);
prquad->setName("PostRenderDisplayQuad");
//visualisation
osg::ref_ptr scenecam = new osg::Camera();
scenecam->setViewport(0,0,width, height);
scenecam->setClearMask(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
scenecam->setClearColor(osg::Vec4(1.0,1.0,1.0,1.0));
scenecam->setRenderOrder(osg::Camera::NESTED_RENDER);
scenecam->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
scenecam->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
scenecam->setProjectionMatrix(osg::Matrix::ortho2D(0,width,0,height));
scenecam->addChild(prgeode.get());
scenecam->setName("SceneCam");
std::cout<<"scenecam created...\n";
osg::ref_ptr rootgroup = new osg::Group();
rootgroup->setName("RootGroup");
rootgroup->addChild(rttcam.get());
rootgroup->addChild(scenecam.get());
osgViewer::Viewer viewer;
viewer.setUpViewInWindow(250,50,width,height);
viewer.setSceneData(rootgroup.get());
osg::ref_ptr testverts = new osg::Shader(osg::Shader::VERTEX);
osg::ref_ptr testfrags = new osg::Shader(osg::Shader::FRAGMENT);
osg::ref_ptr testprog = new osg::Program();
loadShaderSrcFiles("vertexshader120.vert",testverts.get(),"fragmentshader120.frag",testfrags.get());
testprog->addShader(testverts.get());
testprog->addShader(testfrags.get());
osg::ref_ptr testmatrixuniform = new
osg::Uniform(osg::Uniform::FLOAT_MAT4,"testmatrix");
root->getOrCreateStateSet()->addUniform(t