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)
3 replies to this topic
Ad:
#2 Members - Reputation: 1863
Posted 07 May 2012 - 01:13 AM
I haven't tried this, but you may be able to:
Depending on what you're using it for, performance might not be adaquate. Though, give it a try to find out.
- 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.
Depending on what you're using it for, performance might not be adaquate. Though, give it a try to find out.
Edited by Nypyren, 07 May 2012 - 01:14 AM.
#3 Members - Reputation: 101
Posted 08 May 2012 - 01:20 PM
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.
#4 Members - Reputation: 280
Posted 08 May 2012 - 07:50 PM
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)?
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)?






