Advertisement Jump to content
Sign in to follow this  

a few questions regarding managed directX

This topic is 4916 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

hello. I am currently working on a user interface library using the managed directx API alongside the c# language. to provide a more robust library, and a nice look and feel, i need to be able to create alpha channels at run-time and apply them to my sprites. it would also help greatly if i were able to do the same with gradients. this library will have a 2D side to it, but i am also planning on writing a 3D interface later. in the case of a 3D UI, i also require to be able to transform between the screen and world spaces along with being able to apply transparency and possible gradients to the 3D surfaces. thank you for your time, --Locke

Share this post

Link to post
Share on other sites
Let's say you are using a .Net "Bitmap" object (the DirectX 'surface' objects that are used as textures, screen buffers, etc. are very similar, but include additional stuff that you probably don't want to mess with).

If you want to access the raw data inside these bitmaps/surfaces, you have to 'lock' them. In this context, 'lock' is used to mean 'nothing else should be allowed the bitmap while I'm doing this crazy stuff to it'.

Usually, you say what rectangle of the bitmap you want to lock, whether you want to do reading/writing/both, and what format you want to manipulate the 'guts' of the bitmap in. If you give it all the correct information, you will be given access to the 'guts'.

A Bitmap object will give you a BitmapData object when you lock it. The 'Scan0' member of BitmapData is the 'guts' of the bitmap. Each byte, or group of bytes corresponds to a pixel. In a 32-bit bitmap, you will usually have a byte for the blue, green, red, and alpha amounts for each pixel, in that order (PixelFormats.Format32bppRGBA or something like that). The bytes will have different meanings depending on what format you are using.

DirectX surfaces are similar, but I can't remember exact details off the top of my head. If you're doing this at load-time, it might be easier to manipulate a Bitmap and then convert to a DirectX texture.

From what I understood of your post, you want to load up some sprites and change the colors on them and apply alpha to them. You can do all of that manually after you lock a given bitmap/surface.

System.Drawing.Bitmap LockBits method
How to convert the "Scan0" thing into something useful, which you typecast like so:

This must be used in an unsafe block of code.

uint *guts = (uint*)bitmapdata1.Scan0.ToPointer();
for (int y=0; y<bitmapdata1.Height; y++)
for (int x=y; x<bitmapdata1.Width; x++)
int index = y*bitmapdata1.Stride/4+x; // Look up Stride in MSDN.
if ((guts[index] & 0xFFFFFF) == 0xFF00FF) // that ugly pink color that people use for transparent marking in old bitmaps.
guts[index] = 0x00000000; // totally transparent

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!