Re: [osg-users] Background image texture rescaling problem

2007-09-17 Thread Eric Sokolowsky
Robert Osfield wrote:
 Hi John,
 
 On 9/15/07, John Steinbis [EMAIL PROTECTED] wrote:
 Thanks Robert,
 I have this working now without rescaling the image. My solution was
 to pad the image with zeros making it a power of two and then specify
 the correct percentage of the image to use as 2D texture. Not sure if
 this is the best solution but it works and is fast enough for me.
 
 This is not an elegant way to tackle the problem, workable yes, but
 I'd recommend spending a little time - readying up about
 TextureRectangle or just disabling the resize of non power of two
 textures, you'll end up with a more efficient and elegant solution.

I've used two of these methods to avoid the resizing penalty. The first 
was to use John's solution to create power-of-two images and only fill 
it with a subimage that is actually used. I then use the texture matrix 
to change the texture coordinates so no recoding is necessary. This has 
worked very well for my application. The second method was to use the 
TextureRectangle solution, but there are a few drawbacks to this method: 
it may not be hardware-accelerated, especially on older cards; you lose 
the ability to generate mipmapped textures; and your texture coordinates 
become non-normalized, so that you have to know the size of the image 
when you set up your scene if you do anything fancy.

Texture Rectangles are useful but are not the ultimate solution to all 
problems.

Eric
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Background image texture rescaling problem

2007-09-15 Thread John Steinbis
Thanks Robert,
I have this working now without rescaling the image. My solution was
to pad the image with zeros making it a power of two and then specify
the correct percentage of the image to use as 2D texture. Not sure if
this is the best solution but it works and is fast enough for me.

-- John

On 9/13/07, Robert Osfield [EMAIL PROTECTED] wrote:
 Hi John,

 The rescaling is done on non power of two textures by default,
 rescaling is slow op so best avoided.  You have two choices to disable
 the resize of the non power of two texture as you have down to move to
 using TextureRectangle instead of Texture2D.  If moving to the
 TextureRectangle you'll need to move you pixel coords rather than
 normal non dimensions texture coords - see osgtexturerectangle
 example.

 Robert.

 On 9/12/07, John Steinbis [EMAIL PROTECTED] wrote:
  For an AR project, I need to render a model with video image as
  background. My program is based around osgViewer using osg v2.0. I
  found an example for a HUD and with a few changes made it work as
  background. The code can be found below.
 
  The code runs ok but there is a problem occurring that I cannot figure
  out. Any ideas … ?
 
  When new images are loaded, they are rescaled for some reason. This
  adds a noticeable delay, ~250 ms, and distorts the images, which is
  not acceptable. Output looks like Scaling image 'x' from (720,480) to
  (512,512).
 
  To prevent resizing I use BGTexture-setResizeNonPowerOfTwoHint(false).
  To update an image I use BGTexture-setImage(newImg).
 
  Thanks,
  John
 
 
 
  root-addChild(BGProjectionMatrix);
 
  BGProjectionMatrix-setMatrix(osg::Matrix::ortho2D(0,width,0,height));
  BGProjectionMatrix-addChild(BGModelViewMatrix);
 
  BGModelViewMatrix-setMatrix(osg::Matrix::identity());
  BGModelViewMatrix-setReferenceFrame(osg::Transform::ABSOLUTE_RF);
  BGModelViewMatrix-addChild( BGGeode );
 
  BGTexture-setDataVariance(osg::Object::DYNAMIC);
  BGTexture-setResizeNonPowerOfTwoHint(false); // --
  BGTexture-setImage(BGImage);
 
  BGGeode-addDrawable(BGBackgroundGeometry);
  BGGeode-setStateSet(BGStateSet);
 
  BGBackgroundVertices-push_back( osg::Vec3( 0, 0, 0) );
  BGBackgroundVertices-push_back( osg::Vec3(width, 0, 0) );
  BGBackgroundVertices-push_back( osg::Vec3(width, height, 0) );
  BGBackgroundVertices-push_back( osg::Vec3( 0, height, 0) );
 
  (*texcoords)[0].set(0.0f,0.0f);
  (*texcoords)[1].set(1.0f,0.0f);
  (*texcoords)[2].set(1.0f,1.0f);
  (*texcoords)[3].set(0.0f,1.0f);
 
  BGcolors-push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
  BGnormals-push_back(osg::Vec3(1.0f,1.0f,1.0f));
 
  BGBackgroundGeometry-setTexCoordArray(0,texcoords);
  BGBackgroundGeometry-setColorArray(BGcolors);
  BGBackgroundGeometry-setColorBinding(osg::Geometry::BIND_OVERALL);
  BGBackgroundGeometry-setNormalArray(BGnormals);
  BGBackgroundGeometry-setNormalBinding(osg::Geometry::BIND_OVERALL);
  BGBackgroundGeometry-addPrimitiveSet(BGBackgroundIndices);
  BGBackgroundGeometry-setVertexArray(BGBackgroundVertices);
 
  BGBackgroundIndices-push_back(0);
  BGBackgroundIndices-push_back(1);
  BGBackgroundIndices-push_back(2);
  BGBackgroundIndices-push_back(3);
 
  BGStateSet-setTextureAttributeAndModes(0,BGTexture,osg::StateAttribute::ON);
  BGStateSet-setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
  BGStateSet-setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
  BGStateSet-setRenderBinDetails( 1, RenderBin);
  ___
  osg-users mailing list
  osg-users@lists.openscenegraph.org
  http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
 
 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Background image texture rescaling problem

2007-09-15 Thread Robert Osfield
Hi John,

On 9/15/07, John Steinbis [EMAIL PROTECTED] wrote:
 Thanks Robert,
 I have this working now without rescaling the image. My solution was
 to pad the image with zeros making it a power of two and then specify
 the correct percentage of the image to use as 2D texture. Not sure if
 this is the best solution but it works and is fast enough for me.

This is not an elegant way to tackle the problem, workable yes, but
I'd recommend spending a little time - readying up about
TextureRectangle or just disabling the resize of non power of two
textures, you'll end up with a more efficient and elegant solution.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Background image texture rescaling problem

2007-09-15 Thread John Steinbis
I tryed disabling the resize of non power of two textures by using
setResizeNonPowerOfTwoHint but it did not seem to have any effect.
Do you think there is a bug or I just wasnt doing something right? You
can find the line where I tried this in my original post.

I havent been able to figure out how to set the position of a window.
How can I do this? Also, if I try to drag the window to a new
location, it freezes.

-- js


On 9/15/07, Robert Osfield [EMAIL PROTECTED] wrote:
 Hi John,

 On 9/15/07, John Steinbis [EMAIL PROTECTED] wrote:
  Thanks Robert,
  I have this working now without rescaling the image. My solution was
  to pad the image with zeros making it a power of two and then specify
  the correct percentage of the image to use as 2D texture. Not sure if
  this is the best solution but it works and is fast enough for me.

 This is not an elegant way to tackle the problem, workable yes, but
 I'd recommend spending a little time - readying up about
 TextureRectangle or just disabling the resize of non power of two
 textures, you'll end up with a more efficient and elegant solution.

 Robert.
 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Background image texture rescaling problem

2007-09-15 Thread Robert Osfield
On 9/15/07, John Steinbis [EMAIL PROTECTED] wrote:
 I tryed disabling the resize of non power of two textures by using
 setResizeNonPowerOfTwoHint but it did not seem to have any effect.
 Do you think there is a bug or I just wasnt doing something right? You
 can find the line where I tried this in my original post.

It'll only work if you have capable hardware - i.e. Gefore6 series or
later, otherwise it'll detect this an resize things as usual.

 I havent been able to figure out how to set the position of a window.
 How can I do this? Also, if I try to drag the window to a new
 location, it freezes.

We'll if you want to ask this, then start a new thread.  Also in the
meantime look at the osgwindow example.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Background image texture rescaling problem

2007-09-12 Thread John Steinbis
For an AR project, I need to render a model with video image as
background. My program is based around osgViewer using osg v2.0. I
found an example for a HUD and with a few changes made it work as
background. The code can be found below.

The code runs ok but there is a problem occurring that I cannot figure
out. Any ideas … ?

When new images are loaded, they are rescaled for some reason. This
adds a noticeable delay, ~250 ms, and distorts the images, which is
not acceptable. Output looks like Scaling image 'x' from (720,480) to
(512,512).

To prevent resizing I use BGTexture-setResizeNonPowerOfTwoHint(false).
To update an image I use BGTexture-setImage(newImg).

Thanks,
John



root-addChild(BGProjectionMatrix);

BGProjectionMatrix-setMatrix(osg::Matrix::ortho2D(0,width,0,height));
BGProjectionMatrix-addChild(BGModelViewMatrix);

BGModelViewMatrix-setMatrix(osg::Matrix::identity());
BGModelViewMatrix-setReferenceFrame(osg::Transform::ABSOLUTE_RF);
BGModelViewMatrix-addChild( BGGeode );

BGTexture-setDataVariance(osg::Object::DYNAMIC);
BGTexture-setResizeNonPowerOfTwoHint(false); // --
BGTexture-setImage(BGImage);

BGGeode-addDrawable(BGBackgroundGeometry);
BGGeode-setStateSet(BGStateSet);

BGBackgroundVertices-push_back( osg::Vec3( 0, 0, 0) );
BGBackgroundVertices-push_back( osg::Vec3(width, 0, 0) );
BGBackgroundVertices-push_back( osg::Vec3(width, height, 0) );
BGBackgroundVertices-push_back( osg::Vec3( 0, height, 0) );

(*texcoords)[0].set(0.0f,0.0f);
(*texcoords)[1].set(1.0f,0.0f);
(*texcoords)[2].set(1.0f,1.0f);
(*texcoords)[3].set(0.0f,1.0f);

BGcolors-push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
BGnormals-push_back(osg::Vec3(1.0f,1.0f,1.0f));

BGBackgroundGeometry-setTexCoordArray(0,texcoords);
BGBackgroundGeometry-setColorArray(BGcolors);
BGBackgroundGeometry-setColorBinding(osg::Geometry::BIND_OVERALL);
BGBackgroundGeometry-setNormalArray(BGnormals);
BGBackgroundGeometry-setNormalBinding(osg::Geometry::BIND_OVERALL);
BGBackgroundGeometry-addPrimitiveSet(BGBackgroundIndices);
BGBackgroundGeometry-setVertexArray(BGBackgroundVertices);

BGBackgroundIndices-push_back(0);
BGBackgroundIndices-push_back(1);
BGBackgroundIndices-push_back(2);
BGBackgroundIndices-push_back(3);

BGStateSet-setTextureAttributeAndModes(0,BGTexture,osg::StateAttribute::ON);
BGStateSet-setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
BGStateSet-setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
BGStateSet-setRenderBinDetails( 1, RenderBin);
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org