Jump to content

  • Log In with Google      Sign In   
  • Create Account

System.Drawing.Graphics and Texture2D?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 DvDmanDT   Members   -  Reputation: 897

Like
0Likes
Like

Posted 06 May 2012 - 11:30 PM

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)

Sponsor:

#2 Nypyren   Crossbones+   -  Reputation: 4346

Like
0Likes
Like

Posted 07 May 2012 - 01:13 AM

I haven't tried this, but you may be able to:
  • 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.
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, 07 May 2012 - 01:14 AM.


#3 Alphablackwolf   Members   -  Reputation: 101

Like
0Likes
Like

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 DvDmanDT   Members   -  Reputation: 897

Like
0Likes
Like

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)?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS