Hi,
Akilan Thangamani wrote:
Hi,
Extremely sorry for my first question as I was not reading the image file
properly, I couldn't get the display as I thought. But regarding my 2nd
question, I m taking a buffer(filled with image pixels) of size exactly
equivalent to of my screen resolution (1280 * 960). I m trying to display it
in such a way to exactly fit onto my screen without scaling down/up. I put my
code to show the way I create the texture,
osg::Node* CreateTexImage()
{
osg::BoundingBox bb(0.0f,0.0f,0.0f,1.0f,1.0f,1.0f);
osg::Group* group = new osg::Group;
osg::Vec3 top_left(bb.xMin(),bb.yMin(),bb.zMax());
osg::Vec3 bottom_left(bb.xMin(),bb.yMin(),bb.zMin());
osg::Vec3 bottom_right(bb.xMin(),bb.yMax(),bb.zMin());
osg::Vec3 top_right(bb.xMin(),bb.yMax(),bb.zMax());
osg::Vec3 center(bb.xMin(),(bb.yMin()+bb.yMax())*0.5f,(bb.zMin()+bb.zMax())*0.5f);
float height = bb.zMax()-bb.zMin();
osg::Geometry* geom = new osg::Geometry;
osg::Vec3Array* vertices = new osg::Vec3Array(4);
(*vertices)[0] = top_left;
(*vertices)[1] = bottom_left;
(*vertices)[2] = bottom_right;
(*vertices)[3] = top_right;
geom->setVertexArray(vertices);
just use manual vectors here to make 1x1 quad.
osg::Vec2Array* texcoords = new osg::Vec2Array(4);
(*texcoords)[0].set(0.0f,1.0f);
(*texcoords)[1].set(0.0f,0.0f);
(*texcoords)[2].set(1.0f,0.0f);
(*texcoords)[3].set(1.0f,1.0f);
geom->setTexCoordArray(0,texcoords);
osg::Vec3Array* normals = new osg::Vec3Array(1);
(*normals)[0].set(1.0f,0.0f,0.0f);
geom->setNormalArray(normals);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
osg::Vec4Array* colors = new osg::Vec4Array(1);
(*colors)[0].set(1.0f,1.0f,1.0f,1.0f);
geom->setColorArray(colors);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
osg::Geode* geom_geode = new osg::Geode;
geom_geode->addDrawable(geom);
group->addChild(geom_geode);
osg::Texture2D* texture = new osg::Texture2D;
texture->setDataVariance(osg::Object::DYNAMIC);
unsigned char* data;
int width, height;
width=1280; //source_image width
height=960;//source_image height
long size = width * height;
data = new unsigned char[size];
//Reading Image of width * height into buffer
for(i=0;i<(width * height); i++)
data[i]=source_image[i]);
//Setting image
osg::ref_ptr<osg::Image> image = new osg::Image;
image->allocateImage(width, height, 1, GL_LUMINANCE, GL_UNSIGNED_BYTE);
image->setOrigin(osg::Image::BOTTOM_LEFT);
image->setImage(width, height, 1, GL_LUMINANCE, GL_LUMINANCE,
GL_UNSIGNED_BYTE,data, osg::Image::NO_DELETE);
texture->setImage(image);
osg::StateSet* stateset = geom->getOrCreateStateSet();
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
return group;
}
Let me understand what needs to be done to fit onto my screen exaxtly without
scaling?
exact fit to screen is used often in RTT (render to texture)
applications where every pixel need to fall perfectly into target
buffer. So you can look at some RTT examples.
Normal course of action is to set viewport to size of your screen and
set camera projection to ortho to perfectly fit geometry.
Make your quad that you apply the texture to exactly 1x1 and set ortho
projection to 1x1.
Camera->setProjectionMatrixAsOrtho(...
View matrix must be set for your coordinate system. For me easiest is to
use identity view matrix (default opengl with -z into screen) and make
quad in the x-y plane.
jp
Thanks
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=25525#25525
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard.
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.
This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean. MailScanner thanks Transtec Computers for their support.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org