• Advertisement
Sign in to follow this  

Drawing lines/shapes on a D3D surface

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

I was wondering how to plug in GDI commands to a texture. I use C# and manaed Direct3D to render my 2D engine, but now, I want to have a trasnparent texture across the entire screen (rendered last of course). Rendering the texture isn't the problem though, its creating it from scratch. I know at SOME point I have to use the "Graphics" class, but as far as how everything works, I am not sure. But anyway, just to 'test', all I really want to do at the moment is draw a couple of lines across the screen (at different colors/thicknesses). Any help would be greatly appreciated. As far as the "bottom line" of my question goes: How do you create a texture from scratch, and use GDI rendering commands to modify it (for managed Direct3D).

Share this post


Link to post
Share on other sites
Advertisement
Here's a general overview of what you would have to do (sorry, but I don't have time to look up the specifics, but this should give you a general overview).

1. If you are drawing to a texture, use texture.GetSurface(0).
2. Lock the surface and get a pointer to the locked data.
-You can do this by getting a GraphicsStream, and I think there's an internal data property or something.
3. With this pointer construct a Bitmap using the following constructor.

public Bitmap (
int width,
int height,
int stride,
PixelFormat format,
IntPtr scan0
)

Make sure you have the same PixelFormat (probably A8R8G8B8)

4. Create a graphics class on that bitmap (Graphics.FromImage() i think)
5. Draw using that graphics class.
6. (You might want to dispose of the classes, not sure if you have to though, but you probably shouldn't use this bitmap or graphics class after the next step.
7. Unlock the surface, and you should be done.
8. If your texture has multiple mip levels, you might want to regenerate them. I think the texture class has a function for that.

I hope that helped =).

Share this post


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

  • Advertisement