Sign in to follow this  

System.Drawing.Graphics and Texture2D?

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

Hi, I'm currently writing some tools for my XNA games and started to miss System.Drawing.Graphics and started to wonder if I can use it in XNA somehow? Either to draw to the backbuffer or to a texture/rendertarget..? (I'm guessing no, but I figured I might as well ask)

Share this post


Link to post
Share on other sites
I haven't tried this, but you may be able to:[list]
[*]Make a Bitmap using one of the size and pixelformat constructors.
[*]Use Graphics.FromBitmap.
[*]Draw using the Graphics object.
[*]Dispose the Graphics object (I would wrap the whole 'Graphics' operation in a using block).
[*]Use Bitmap.LockBits and grab the pixel data out, and transfer them over to a Texture2D.
[/list]
I'm also guessing that System.Drawing.Graphics is only available on Windows, and not 360 or WP7. You'll have to double check.

Depending on what you're using it for, performance might not be adaquate. Though, give it a try to find out. Edited by Nypyren

Share this post


Link to post
Share on other sites
You could import it, and maybe work out how to use it, but I wouldn't recommend it. Between a lack of double buffering and that it's not optimized for game code could leave you with flickering and laggy graphics. I am also unsure how well that would port to Xbox if you were to do so.

Share this post


Link to post
Share on other sites
It wouldn't port to other platforms, but it's for tools so I don't really care. Also, I'm not talking about drawing the actual game this way, I just want to place markers and such in my editor.

Speed is also not really much of a concern, and it's also not as slow as one might think. I once replaced an applications drawing code with D3D. There were thousands (more like 50k) of axis aligned rectangles and lines drawn, each with their own draw call, so I figured I could probably get a significant boost by drawing colored quads and lines in D3D. I performed batching, cached vertex/index buffers, tried with and without indices, I tried userprimitives and so on, and my best attempt got me something like 5-10% performance gain. At that point I figured GDI+ is pretty well optimized for this kind of drawing.

Just out of curiousity, if I used Direct3D instead of XNA, could I get a device context from a texture (as in HDC from WinApi)?

Share this post


Link to post
Share on other sites

This topic is 2043 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this