Hi, The idea is to edit a texture in real time. To do this, I get the texture coordinates where I clicked on the model and I try to update the image as follows ...
Texture creation: Code: image = new osg::Image; image->allocateImage(tex_width, tex_height, 1, GL_RGBA, GL_UNSIGNED_BYTE); unsigned int r = 255; unsigned int g = 255; unsigned int b = 0; unsigned int a = 255; for(int i = 0 ; i < tex_width*tex_height ; i++) { memcpy(image->data()+i*4 , &r, 1); memcpy(image->data()+i*4+1, &g, 1); memcpy(image->data()+i*4+2, &b, 1); memcpy(image->data()+i*4+3, &a, 1); } // attach pbo image->setPixelBufferObject(new osg::PixelBufferObject(image)); // push back the image to the texture textureRect->setImage(0, image); Update process: Code: float x = textCoord._v[0]*tex_width; float y = textCoord._v[1]*tex_height; osg::Vec4 color = textureRect->getImage(0)->getColor(x*y); float radio = 80.0; unsigned int r; unsigned int g; unsigned int b; unsigned int a = 255; for(int i = 0 ; i < tex_height ; i++) { for(int j = 0 ; j < tex_width ; j++){ osg::Vec2 t = osg::Vec2(x-j,y-i); float dist = sqrt((t.x()*t.x())+(t.y()*t.y())); if(dist(lower)radio){ r = 0; g = 255; b = 0; } else{ r = 255; g = 255; b = 255; } memcpy(textureRect->getImage(0)->data()+i*j*4 , &r, 1); memcpy(textureRect->getImage(0)->data()+i*j*4+1, &g, 1); memcpy(textureRect->getImage(0)->data()+i*j*4+2, &b, 1); memcpy(textureRect->getImage(0)->data()+i*j*4+3, &a, 1); } } textureRect->getImage(0)->dirty(); osgDB::writeImageFile(*image,"sample.png"); But the idea does not work ... How can I relate the texcoords with the rows and columns of the image? Thank you! Cheers, Aitor ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=33609#33609 _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org