Ask a questionAsk a question
 

AnswerAnimated texture (video)

  • Thursday, March 29, 2007 1:29 PMCyberLord_Dan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Can I make an animated texutre from a video??? For example to play an .avi file on a square created by 2 triangles???

Answers

  • Friday, April 06, 2007 8:42 PMCyberLord_Dan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Never mind....... I've found something more easier searching on internet: (hope that helps for the ones that want to render movie as a texture):

     

     

    Using Video as Textures

    Another common feature for video files that users must have is the capability to play these movies onto a 3D texture inside the application they are building. Many of the developers use movie files as the "cut-scenes" during their game, and need some way to show the movie in full screen mode. The Audio Video playback classes can handle both cases quite well.

    For the simplest case of a developer wanting to use a full screen movie as a cut-scene in the game they are writing, we made it as simple as could be. Simply load the video file into your Video object, set the "Fullscreen" property to true, and play the video. Nothing could be simpler…well, unless there was a constructor that took these parameters.

    For the more difficult scenario where the developer has some set of geometry they want to texture using a video, we've come up with a different solution. First, there is an event you will want to hook, TextureReadyToRender. This event will be fired every time there is a new frame in the video file that is ready to be rendered as a texture.

    The TextureRenderEventArgs member that is passed into the event handler contains the newly created texture that is ready to be rendered. This event may be fired from many different threads, so ensure that you do not have multiple threads accessing variables simultaneously. Who knows what craziness you can end up with doing that? All you need to do to start the video playing and the event firing is call the method RenderToTexture on the video object. You should begin receiving the events and textures immediately.

    The sample that ships with the DirectX SDK renders the entire scene at the same frame rate as the movie being played; it only renders each frame when a new texture is ready. In many cases, this is adequate for the developers, since movies being rendered as a texture is a fairly uncommon occurrence. However, you may still want to use the texture in your "real time" rendering application, so how would you go about that?

    First, you will need to detect whether your video texture has been created in the system memory pool or the default pool (since you won't have control over this). You can do this by checking the level description of the first level of the texture.

    If the texture was created in the default pool (most common), you will need to use the Direct3D device's method GetRenderTargetData on the surface of the texture and a surface of your own created in the system memory pool. You cannot render textures created in the system memory pool, so you will also need to create a texture in the default memory pool to use for rendering. Something like

    SurfaceDescription ds = e.Texture.GetLevelDescription(0);
    
    if (ds.Pool == Pool.Default)
    {
        systemSurface = device.CreateOffscreenPlainSurface(ds.Width, ds.Height,
            ds.Format, Pool.SystemMemory);
    }
    
    texture = new Texture(device, ds.Width, ds.Height,
        1, Usage.Dynamic, ds.Format, Pool.Default);
    

    This code will check to see whether your video texture has been created in the default memory pool, and if it has, it will create an off-screen plain surface to hold the texture data, plus a texture in the default memory pool that we can use to render our scene. After this is executed, there are two methods on the device that we need to use to get the data from one texture to the next:

    using(Surface videoSurface = e.Texture.GetSurfaceLevel(0))
    {
        using(Surface textureSurface = texture.GetSurfaceLevel(0))
        {
            device.GetRenderTargetData(videoSurface, systemSurface);
            device.UpdateSurface(systemSurface, textureSurface);
        }
    }
    

    As you can see here, we get the render target data from our video texture and move it into our temporary system memory surface. From there, we move it into our real texture. We can then use the texture we created in the default pool as the texture to render our scene.

    Since the texture will be accessed by more than one thread, you will need to ensure that only one thread at a time has access to this texture by using the lock semantics on it.

    The Audio and Video playback classes are not designed to be fully featured implementations of DirectShow. They do not offer many of the in-depth features, such as video capture or filter graph management. They are designed for the simplest cases of loading audio and video data, and playing this data back; nothing more. They are quick and easy to use, but should not be considered a full and robust solution, nor a "replacement" to the DirectShow APIs already out there.

    There are no planned updates for this namespace or references.

All Replies

  • Thursday, April 05, 2007 1:53 AMWessam BahnassiMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Yes. Look the AudioVideoPlayback stuff in MDX.
  • Thursday, April 05, 2007 8:13 PMCyberLord_Dan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    K. Didn't understood nothing Smile . I mean how to I set the "TU TV" coordinates of the movie on a triangle... .pls a complete example
  • Thursday, April 05, 2007 11:00 PMmichi2 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    You might take a look at this => http://directx4vb.vbgamer.com/DirectX4VB/Tutorials/DirectX8/GR_Lesson04.asp

    or just insert "uv-coordinates" in your DX-documentation and hit return
  • Friday, April 06, 2007 9:18 AMCyberLord_Dan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I want a movie texture not an image!!!!!!!!!! for example mov1.avi . And how do I control the timeline, stop, play, pause.... and so on.... How do I render a movie file on a square made from 2 triangles!!!!!?????????
  • Friday, April 06, 2007 11:27 AMWessam BahnassiMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Did you read the Video class in the Managed DX docs?
  • Friday, April 06, 2007 11:36 AMCyberLord_Dan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Yes, but i didn't find some information about setting coordinates of the "animated texutre".......... I learn better from examples... pls one if u can...
  • Friday, April 06, 2007 12:01 PMWessam BahnassiMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Googling it, I got this on the third hit:

    http://www.mashiharu.com/src/VideoBillBoard.cs

  • Friday, April 06, 2007 12:11 PMCyberLord_Dan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Where do I find WorldWind and WorldWind.Renderable references???
  • Friday, April 06, 2007 8:42 PMCyberLord_Dan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Never mind....... I've found something more easier searching on internet: (hope that helps for the ones that want to render movie as a texture):

     

     

    Using Video as Textures

    Another common feature for video files that users must have is the capability to play these movies onto a 3D texture inside the application they are building. Many of the developers use movie files as the "cut-scenes" during their game, and need some way to show the movie in full screen mode. The Audio Video playback classes can handle both cases quite well.

    For the simplest case of a developer wanting to use a full screen movie as a cut-scene in the game they are writing, we made it as simple as could be. Simply load the video file into your Video object, set the "Fullscreen" property to true, and play the video. Nothing could be simpler…well, unless there was a constructor that took these parameters.

    For the more difficult scenario where the developer has some set of geometry they want to texture using a video, we've come up with a different solution. First, there is an event you will want to hook, TextureReadyToRender. This event will be fired every time there is a new frame in the video file that is ready to be rendered as a texture.

    The TextureRenderEventArgs member that is passed into the event handler contains the newly created texture that is ready to be rendered. This event may be fired from many different threads, so ensure that you do not have multiple threads accessing variables simultaneously. Who knows what craziness you can end up with doing that? All you need to do to start the video playing and the event firing is call the method RenderToTexture on the video object. You should begin receiving the events and textures immediately.

    The sample that ships with the DirectX SDK renders the entire scene at the same frame rate as the movie being played; it only renders each frame when a new texture is ready. In many cases, this is adequate for the developers, since movies being rendered as a texture is a fairly uncommon occurrence. However, you may still want to use the texture in your "real time" rendering application, so how would you go about that?

    First, you will need to detect whether your video texture has been created in the system memory pool or the default pool (since you won't have control over this). You can do this by checking the level description of the first level of the texture.

    If the texture was created in the default pool (most common), you will need to use the Direct3D device's method GetRenderTargetData on the surface of the texture and a surface of your own created in the system memory pool. You cannot render textures created in the system memory pool, so you will also need to create a texture in the default memory pool to use for rendering. Something like

    SurfaceDescription ds = e.Texture.GetLevelDescription(0);
    
    if (ds.Pool == Pool.Default)
    {
        systemSurface = device.CreateOffscreenPlainSurface(ds.Width, ds.Height,
            ds.Format, Pool.SystemMemory);
    }
    
    texture = new Texture(device, ds.Width, ds.Height,
        1, Usage.Dynamic, ds.Format, Pool.Default);
    

    This code will check to see whether your video texture has been created in the default memory pool, and if it has, it will create an off-screen plain surface to hold the texture data, plus a texture in the default memory pool that we can use to render our scene. After this is executed, there are two methods on the device that we need to use to get the data from one texture to the next:

    using(Surface videoSurface = e.Texture.GetSurfaceLevel(0))
    {
        using(Surface textureSurface = texture.GetSurfaceLevel(0))
        {
            device.GetRenderTargetData(videoSurface, systemSurface);
            device.UpdateSurface(systemSurface, textureSurface);
        }
    }
    

    As you can see here, we get the render target data from our video texture and move it into our temporary system memory surface. From there, we move it into our real texture. We can then use the texture we created in the default pool as the texture to render our scene.

    Since the texture will be accessed by more than one thread, you will need to ensure that only one thread at a time has access to this texture by using the lock semantics on it.

    The Audio and Video playback classes are not designed to be fully featured implementations of DirectShow. They do not offer many of the in-depth features, such as video capture or filter graph management. They are designed for the simplest cases of loading audio and video data, and playing this data back; nothing more. They are quick and easy to use, but should not be considered a full and robust solution, nor a "replacement" to the DirectShow APIs already out there.

    There are no planned updates for this namespace or references.