• Advertisement
Sign in to follow this  

Plotting pixels with C# & Managed Directx

This topic is 4576 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, so nearly two years ago I posted this thread I finally got around to playing with the Managed DirectDraw stuff again, & figured how to do this. And yes, I know ddraw has been depreciated.
...do some stuff... 
initialize DirectDraw & create surfaces
   ...do more stuff... 

/*a GraphicsStream, which we write to in order manipulate pixels*/
Ddraw.LockedData BackBuffer; 

/*holds the x,y poisition of the pixel*/
int x = 10;
int y = 10; 

/*couldn't written my own, but since it's already here...*/
System.Drawing.Color color = System.Drawing.Color.Green;

/*Lock(...) gives us access to the screen data.  Wait until we can lock it*/
BackBuffer = SecondarySurface.Lock(Ddraw.LockFlags.Wait);

/*Similar to how we'd calculate the arrary index back in c for the surface memory*/
BackBuffer.Data.Seek(y * BackBuffer.Pitch + x * (BackBuffer.RGBBitCount / 8), System.IO.SeekOrigin.Current);

/*this is assuming 32bit color, so pass the color data as a byte array
Blue, Green, Red, Alpha*/
byte[] pixelData = {color.B, color.G, color.R, 0};

/*all done*/

Share this post

Link to post
Share on other sites
IIRC you can use pretty much the same approach with D3D surfaces (obtained from a texture resource, or the backbuffer). In fact, it even looks a little easier, without the data seeking & stuff. This way you won't have to worry about the deprecation of DDraw.

Share this post

Link to post
Share on other sites
I would do it by making an array of D3DXVECTOR4's, filling them with screen-space X,Y,Z,RHW values, and passing them to my D3DDevice's DrawPrimitiveUP.

~BenDilts( void );

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement