Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9152783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:08:20+00:00 2026-06-17T12:08:20+00:00

I am trying to play video on Direct3D 9 device, using: nVLC – for

  • 0

I am trying to play video on Direct3D 9 device, using:

  1. nVLC – for fetching the RGB32 frames from file
  2. SlimDX – Actually displaying frames on video device using textures.

Here is my code to receive RGB32 frames;

    _videoWrapper.SetCallback(delegate(Bitmap frame)
                            {
                                if (_mainContentSurface == null || _dead) 
                                    return;

                                var bmpData = frame.LockBits(new Rectangle(0, 0, frame.Width, frame.Height), ImageLockMode.ReadOnly, frame.PixelFormat);
                                var ptr = bmpData.Scan0;

                                var size = bmpData.Stride * frame.Height;
                                _mainContentSurface.Buffer = new byte[size];

                                System.Runtime.InteropServices.Marshal.Copy(ptr, _mainContentSurface.Buffer, 0, size);

                                _mainContentSurface.SetTexture(_mainContentSurface.Buffer, frame.Width, frame.Height);
                                _secondaryContentSurface.SetTexture(_mainContentSurface.Buffer, frame.Width, frame.Height); // same buffer to second WINDOW

                                _mainContentSurface.VideoFrameRate.Value =_videoWrapper.ActualFrameRate;

                                frame.UnlockBits(bmpData);
                            });

And here is my actual usage of SetTexture and mapping texture to square:

public void SetTexture(byte[] image, int width, int height)
{
    if (Context9 != null && Context9.Device != null)
    {
        if (IsFormClosed)
            return;

        // rendering is seperate from the "FRAME FETCH" thread, if it makes sense.
        // also note that we recreate video texture if needed.
        _renderWindow.BeginInvoke(new Action(() =>
                                {
                                    if (_image == null || _currentVideoTextureWidth != width || _currentVideoTextureHeight != height)
                                    {
                                        if(_image != null)
                                            _image.Dispose();

                                        _image = new Texture(Context9.Device, width, height, 0, Usage.Dynamic, Format.A8R8G8B8,
                                                            Pool.Default);

                                        _currentVideoTextureWidth = width;
                                        _currentVideoTextureHeight = height;

                                        if(_image == null)
                                            throw new Exception("Video card does not support textures power of TWO or dynamic textures. Get a video card");
                                    }

                                    //upload data into texture.
                                    var data = _image.LockRectangle(0, LockFlags.None);
                                    data.Data.Write(image, 0, image.Length);
                                    _image.UnlockRectangle(0);
                                }));
    }
}

and finally the actual rendering:

    Context9.Device.SetStreamSource(0, _videoVertices, 0, Vertex.SizeBytes);
    Context9.Device.VertexFormat = Vertex.Format;

    // Setup our texture. Using Textures introduces the texture stage states,
    // which govern how Textures get blended together (in the case of multiple
    // Textures) and lighting information.
    Context9.Device.SetTexture(0, _image);

    // The sampler states govern how smooth the texture is displayed.
    Context9.Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear);
    Context9.Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
    Context9.Device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);

    // Now drawing 2 triangles, for a quad.
    Context9.Device.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);

Now, it works on my machine. Without problems. With every video file and in every position. But when I checked the WinXP, picture was completely broken. Here is a screencaps for both nonworking and working;

http://www.upload.ee/image/2941734/untitled.PNG

http://www.upload.ee/image/2941762/Untitled2.png

Note that on the first picture, they are _maincontentSurface and _secondaryContentSurface. Does anyone have idea what could be the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:08:21+00:00Added an answer on June 17, 2026 at 12:08 pm

    You shouldn’t need to recreate your texture every time, just create it as dynamic:

    this.Texture = new Texture(device, w, h, 1, Usage.Dynamic, Format.X8R8G8B8, Pool.Default);
    

    About the copy issue could come from stride (row length might be different since it is padded):

    to get Row pitch of the texture:

        public int GetRowPitch()
        {
            if (rowpitch == -1)
            {
                DataRectangle dr = this.Texture.LockRectangle(0, LockFlags.Discard);
                this.rowpitch = dr.Pitch;
                this.Texture.UnlockRectangle(0);
            }
            return rowpitch;
        }
    

    If your texture row pitch is equal to your frame pitch, you can copy the way you do, otherwise you can do it this way:

        public void WriteDataPitch(IntPtr ptr, int len)
        {
            DataRectangle dr = this.Texture.LockRectangle(0, LockFlags.Discard);
    
            int pos = 0;
            int stride = this.Width * 4;
    
            byte* data = (byte*)ptr.ToPointer();
            for (int i = 0; i < this.Height; i++)
            {
                dr.Data.WriteRange((IntPtr)data, this.Width * 4);
    
                pos += dr.Pitch;
                dr.Data.Position = pos;
                data += stride;
            }
            this.Texture.UnlockRectangle(0);
        }
    

    If you want an example of fully working vlc player with slimdx let me know got that around (need to wrap it up nicely)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to play video from youtube using this code but I get this
I am trying to play a video file using JMF but it gives me
I'm trying to play a video using opencv (the video is an avi file
I am trying to play video, where I get frames as bitmaps from the
I am trying to play the Video file on IE8 using quick time but
I am trying to play a video from video path that I have in
I am trying to play .avi file in video lightbox by over riding it's
I am trying to play video files from iPhone media player in my iphone
I am trying to play video files from http urls in my app. Why
I'm trying to play two videos continuously using MPMoviePlayer. I let the second video

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.