Skip to main content
GameDev.net gamedev.net
🔒 Locked

Plotting pixels with C# & Managed Directx

Started by BASSOFeeSH Oct 11, 2005 at 2:23 PM 1 replies 1k views
Original Post
BASSOFeeSH
BASSOFeeSH
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};
BackBuffer.Data.Write(pixelData);

/*all done*/
SecondarySurface.Unlock();

-- What would Sweetness do?
remigius
remigius
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.
BeanDog
BeanDog
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 );

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.