Hi, > >>> I use a TextureGrabForeground to do some multipass > >>> rendering. I need to access the texture coordinates > >>> of the valid rect of the texture, depending on extensions > >>> like GL_ARB_texture_non_power_of_two supported by the > >>> target machine. Methods like getTexCoords are not exposed > >>> by the interface... So how do I access the texture > >>> cords? (Note that the coordinates might change during > >>> runtime depending on the current size of the viewport > >>> (resizing, etc)) > >> It is possible to get the pixel-size of the viewport (see > >> getPixelWidth()/getPixelHeight() in osg::Viewport) so you should be > able > >> to use that to compute your actual texcoords. > >> > >> Does this help? > > > > Yes, I guess that's what I thought I had to do. But I must > > know how tex coords are calculated inside TextureGrabForeground, > > so I guess I'll have to take a look at the code. > > Ah, you want to figure out how large an image was grabbed and where it > ends up in your texture? > > With image grabbing, there are no tex-coords 'calculated' as such, since > it only grabs an image and put's it into another image (the texture).
yes > Looking at TextureGrabForeGround, it copies the viewport (at viewport > left/bottom and with max width/height of viewport or image) to the > bottom left of the texture (0,0)). yepp... > As texture coords is only associated with polygon corners when > rendering, and is mapped as GL defines it (for NPOT: 0,0 at bottom left, > 1,1 upper right w.r.t. the full size of the texture), I would think that > using (0,0) and (1.0/min(viewport->getPixelWidth(), > texture->getimage()->getWidth()), 1.0/ditto(height)) would work, but I > assume you've tried that? Well yes... my solution right now looks like this: void calcTextureCoordinates( int width, int height, float &u, float &v ) { bool isPOT = osgispower2(width) && osgispower2(height); bool hasNPot = win.hasExtension("GL_ARB_texture_non_power_of_two"); bool hasRectTex = win.hasExtension("GL_ARB_texture_rectangle"); if((isPOT || hasNPot) && !hasRectTex){ u = v = 1.0; }else if(hasRectTex){ u = width-1; v = height-1; }else{ u = static_cast<Real32>(width) / osgnextpower2(width); v = static_cast<Real32>(height) / osgnextpower2(height); } } then I do something like this: ViewportPtr vp = ...; calcTextureCoordinates( vp->getPixelWidth(), vp->getPixelHeight(), u, v ); Seems to work... Regards and thank you Marcus, Toni ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Opensg-users mailing list Opensg-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensg-users