The following can be put for example where you create the mesh, as I did - or of course where ever else you find suitable:
video = Video.FromFile("test.avi"); //I'll set this to open a video with the file menu laterAbout an hour after writing the post it's time to update it.... I changed some stuff in the eventhandler, giving the following code as result:
video.TextureReadyToRender += new TextureRenderEventHandler(onTextureReadyToRender); //Set an event handler to fire when the texture is ready to render.
video.RenderToTexture(_device); // Render the texture with the device (graphics card)
public void onTextureReadyToRender(object sender, TextureRenderEventArgs e)To give some quick comments:
if (e.Texture == null)//If there's no texture file (video) for 'e', then get out of here
SurfaceDescription ds = e.Texture.GetLevelDescription(0);
if (ds.Pool == Pool.Default)
sysSurf = _device.CreateOffscreenPlainSurface(ds.Width, ds.Height,
using (Surface vidSurf = e.Texture.GetSurfaceLevel(0))
if (_tex == null)//If there is no texture set to "_tex"
_tex = new Texture(_device, ds.Width, ds.Height,
1, Usage.Dynamic, ds.Format, ds.Pool);
using (Surface texSurf = _tex.GetSurfaceLevel(0))
SurfaceLoader.FromSurface(texSurf, vidSurf, Filter.Linear, unchecked((int)0xffffffff));
- The update peoblem (application not updating without user interaction) was fixed when I put in the Invalidate() method.
- The updating looks quicker than before - but of course it's impossible to tell by the naked eye.
- The changes were made after I found some useful things in the book("Managed DirectX 9 Kick Start" by Tom Miller in the MDX team)
Sorry about the lack of indents in the code - Blogger doesn't like the easy methods to create indents like tab/space, so I'll just skip that unless I get comments about it ;-)
I still have a lot of trouble with disposing the video texture when closing the application, but since I can't find anything to fix it after trying different ways and searching different places, I'll leave it for now...
The next things I'll do will just be minor issues. like for example stretching the video texture different ways, just to see the effect of it, and if it can be used easy and quick to rectify the frame images..