Yes, I wrote a Windows Forms control that wraps DirectX 9.0 and provides direct pixel level control on the video surface.
Actually, I wrote another post on Stack Overflow asking if there are other more suitable approaches: Unsafe C # and pointers for 2D rendering, good or bad?
While this is relatively high performance, it requires an unsafe compiler option because it uses pointers to access memory efficiently. Hence the reason for this earlier post.
This is a high level of necessary steps:
- Download the DirectX SDK.
- Create a new C # Windows Forms project and refer to the installed Microsoft DirectX build.
- Initialize a new DirectX device object with presentation parameters (window, rear buffering, etc.).
- Create the device, taking care of the recording of the βStepβ surface and the current display mode (bits per pixel).
- When you need to display something,
Lock backbuffer surface and save the returned pointer to the beginning of the surface memory. - Use pointer arithmetic, calculate the actual pixel position in the data based on the height of the surface, bits per pixel and the actual x / y pixel coordinate.
- In my case, for simplicity, I stick with 32 bpp, that is, setting a pixel is as simple as: * (surfacePointer + (y * pitch + x)) = Color.FromARGB (255,0,0);
- When finished drawing,
Unlock surface of the back buffer. Imagine a surface. - Repeat step 5 as necessary.
Remember that with this approach, you need to be very careful in checking the current display mode (step and bit per pixel) of the target surface. You will also need to have a strategy to solve the problem of resizing the window or changing the screen format while your program is running.
Ash Sep 12 '08 at 3:02 2008-09-12 03:02
source share