[osg-users] how to get pixel value using X and Y coordinates

Robert Osfield robert.osfield at gmail.com
Mon Dec 19 02:11:39 PST 2016


Hi Uma,

On 19 December 2016 at 09:08, Uma Devi Selvaraj <umaselvam1503 at gmail.com> wrote:
>       Can somebody tell me is it possible to get pixel value from x and y co-ordinates?


You can implement a draw callback that uses glReadPixels() if you want
the actual pixel value.  This however limits to you doing the
operation in the draw traversal and forces a round trip to the GPU
which is slow process.

Normally when you want to intersect the scene at the mouse x,y
position you'll using osgViewer::View::computeIntersections() or the
osgUtil::IntersectionVisitor with  LineSegmentIntersector.  You can
get the intersection values and tex coords from the intersection which
then can be used to query the osg::Texture and finally the osg::Image
for it's value.  This route is CPU based and avoids the round trip
cost.

Robert.



More information about the osg-users mailing list