Video Texture Scaling question/issues

I have an application that uses video via

self.moviePlaybackObject.setTexture(loader.loadTexture(videolink), 1) 

I’m trying to get that video to strech fully onto a simple plane

<CoordinateSystem> { Y-Up }

<Comment> {
  "maya2egg plane.mb plane.egg"
}
<Group> groundPlane_transform {
}
<Group> pPlane1 {
  <VertexPool> pPlaneShape1.verts {
    <Vertex> 1 {
      -0.5 -0.5 0
      <Normal> { 0 0 -1 }
      <UV> { 0 0 }
      <RGBA> { 1 1 1 1 }
    }
    <Vertex> 2 {
      -0.5 0.5 0
      <Normal> { 0 0 -1 }
      <UV> { 0 1 }
      <RGBA> { 1 1 1 1 }
    }
    <Vertex> 3 {
      0.5 -0.5 0
      <Normal> { 0 0 -1 }
      <UV> { 1 0 }
      <RGBA> { 1 1 1 1 }
    }
    <Vertex> 4 {
      0.5 0.5 0
      <Normal> { 0 0 -1 }
      <UV> { 1 1 }
      <RGBA> { 1 1 1 1 }
    }
  }
  <Polygon> {
    <Normal> { 0 0 -1 }
    <VertexRef> { 3 4 2 1 <Ref> { pPlaneShape1.verts } }
  }
}

which is scaled in panda

plane.setScale(2,1,1)

Now, Applying an image texture to that plane, the entire image streches accross the plane, but when applying a video texture, the video only fills part of the plane (about 1/3), and fills the rest with black.

On one specific hardware configuration, textures-power-2 off made the video scale fully accross the texture, but textures-power-2 up and textures-power-2 down or not using textures-power-2 either makes the video fail to load or just scale inaccurately.

The videos in question are not Square videos. they are standard def or dvd def.

Any suggestions?
[/code]

If you tell Panda that your graphics card can handle non-power-2 textures, via “textures-power-2 none”, then Panda will create your video textures exactly they size they are. If, however, you have either “up” or “down” to textures-power-2, Panda assumes your graphics card can only handle power-of-2 textures.

So, what should Panda do in this case when you try to load a texture that is not a power of 2? For an ordinary texture, the answer is easy: scale it up or down to the next nearest power of 2. However, for a video texture, it would be far too expensive to do this, since we’d have to rescale each frame as it is rendered in real time. So we have to treat video textures as a special case.

When you try to load a non-power-of-2 video texture, Panda will allocate an actual texture image that is the next power-of-2 size, but it will only use the bottom-left corner of the texture. For example, if your video is 640x480 pixels, Panda will allocate a texture image that is 1024x512 pixels, and only fill the video into the lower-left 640x480 pixels; the rest of the texture image will be black. It will be up to you to set the UV’s on the geometry appropriately to scale the texture up to the full size of your geometry; in this example, for instance, your texture card should have UV’s ranging from (0, 0) to (0.625, 0.9375)–that is to say, up to (640.0/1024.0, 480.0/512.0).

If you don’t want to hardcode this ratio into the egg file, you can do:

plane.setTexScale(TextureStage.getDefault(), myVideoTex.getTexScale())

This will scale the UV’s appropriately. Alternatively, if you are building a card at runtime (instead of loading it from an egg file), you can generate the UV’s from (0, 0) to (myVideoTex.getTexScale()[0], myVideoTex.getTexScale()[1]).

David

Thanks David. That works splendidly!