Note that there are some explanatory texts on larger screens.

plurals
  1. POAligning osgViewer Camera with an Image
    primarykey
    data
    text
    <p>As a precursor to render to texture, I am trying to simply align the osgViewer's camera to a texture mapped plane.</p> <p>This is the code I employ for the same:</p> <pre><code>int main() { osgViewer::Viewer viewer; osg::ref_ptr&lt;osg::Image&gt; image = osgDB::readImageFile("path//to//file.png"); if (!image.valid()) { assert(false); return 1; } osg::ref_ptr&lt;osg::Geometry&gt; pictureQuad = osg::createTexturedQuadGeometry(osg::Vec3(0.f,0.f,0.f), osg::Vec3(image-&gt;s(),0.f,0.f), osg::Vec3(0.f,0.f,image-&gt;t()), 0.f, 0.f, image-&gt;s(), image-&gt;t()); osg::ref_ptr&lt;osg::TextureRectangle&gt; textureRect = new osg::TextureRectangle(image); textureRect-&gt;setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); textureRect-&gt;setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); textureRect-&gt;setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); textureRect-&gt;setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); pictureQuad-&gt;getOrCreateStateSet()-&gt;setTextureAttributeAndModes(0, textureRect.get(), osg::StateAttribute::ON); pictureQuad-&gt;getOrCreateStateSet()-&gt;setMode(GL_DEPTH_TEST, osg::StateAttribute::ON); osg::ref_ptr&lt;osg::Geode&gt; geode = new osg::Geode(); geode-&gt;setDataVariance(osg::Object::DYNAMIC); geode-&gt;addDrawable(pictureQuad.get()); osg::StateSet *state = geode-&gt;getOrCreateStateSet(); state-&gt;setMode( GL_LIGHTING, osg::StateAttribute::PROTECTED | osg::StateAttribute::OFF ); viewer.setSceneData(geode); osg::ref_ptr&lt;osg::Camera&gt; camera = viewer.getCamera(); while( !viewer.done() ) { camera-&gt;setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera-&gt;setProjectionMatrix(osg::Matrix::ortho2D(0.f, image-&gt;s(), 0.f, image-&gt;t())); camera-&gt;setViewMatrixAsLookAt(osg::Vec3f(0.f, -100.f, 0.f), osg::Vec3f(image-&gt;s()*0.5, 0.f, image-&gt;t()*0.5f), osg::Vec3f(0.f, 0.f, 1.f)); viewer.frame(); } return 0; } </code></pre> <p>However, the results show me a view that is completely skewed. Can someone please point out the bug in my code?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload