[.net] Direct3D Surface Transparency

Started by
1 comment, last by Pianka 16 years, 11 months ago
I'm using a surface to render my cursor and I obviously want transparency. Here's my loading code:
Quote: Cursor_Background = device.CreateOffscreenPlainSurface(100, 40, Manager.Adapters[0].CurrentDisplayMode.Format, Pool.Default); SurfaceLoader.FromFile(Cursor_Background, "cursor.bmp", Filter.None, Color.White.ToArgb());
My rendering function:
Quote: public void DrawCursor() { Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono); device.StretchRectangle(Cursor_Background, new Rectangle(0, 0, 16, 17), backbuffer, new Rectangle(mouse_x, mouse_y, 16, 17), TextureFilter.None); backbuffer.Dispose(); }
As you can see I want white to be transparent. Every tutorial I've found on this uses something called a ColorKey, which doesn't exist in my project or Surface class so I'm guessing its a DirectDraw version of the class. Any help or suggestions would be great, thanks!
Advertisement
Well since CurrentDisplayMode.Format likely doesn't have any alpha channel your colorkey probably isn't doing anything.

I'm guessing you're coming from something similar to DirectDraw. In Direct3D drawing raw surfaces directly to the backbuffer isn't the best practice. You should look into using an orthograhic matrix along with the sprite interface and using textures to store images, it would definately be faster then your current method.
I used sprites before and I ran into a serious problem when there were only a few on the screen, so I switched to surfaces instead. Can I change the format and have it allow alpha?

This topic is closed to new replies.

Advertisement