lordJapheth

I recently found the following link that describes how to make 2D primitives in C#:

tutorial

I would love to be able to use this in my XNA game, but the above example uses a Graphics object that it gets from the PainEventArgs of the form. However, the XNA template uses a GraphicsDeviceManager. Is there any way I could get the Graphics object of the xna game window so that I could draw the things in that tutorial



Re: XNA Game Studio Express incorporating c# 2d drawing into the xna template

Jim Perry

Why not just do it this way.




Re: XNA Game Studio Express incorporating c# 2d drawing into the xna template

Fluxtah

The tutorial on that link covers winforms and GDI+, what you really want to do is learn the XNA way of drawing primitives, you can learn all about it by looking at the XNA docs under Graphics > 3D Graphics > How to: Draw Points, Lines and Other 3D Primitives.

Even though its for drawing 3D primitives, its also used for drawing 2D, essentially by using a zero Z value for your vectors.

Once you get the hang of drawing shapes, the rest is up to your imagination, its a powerful drawing API that you can build on top of if you want the abstraction of drawing circles, rectangles and other shapes by simply instancing classes named appropriately like GDI does.





Re: XNA Game Studio Express incorporating c# 2d drawing into the xna template

Fluxtah

Ok, Jim got there first :P



Re: XNA Game Studio Express incorporating c# 2d drawing into the xna template

lordJapheth

That just seems like much more work than is necessary. I've already looked at several threads here that talk about and gives examples of drawing 2D primitives using that technique. If I could just get a Graphics class, it would be far easier to do what is done in that tutorial. If it is indeed possible to get a graphics class for the window in the xna game template, my only real issue is speed. I'm not sure if using System.Drawing and drawing it in a window like that is significantly slower than XNA.





Re: XNA Game Studio Express incorporating c# 2d drawing into the xna template

Fluxtah

GDI+ is not compatible, what your asking is impossible, just abstract the XNA drawing API into something that suits you.





Re: XNA Game Studio Express incorporating c# 2d drawing into the xna template

lordJapheth

Ok, thanks. It was worth a try anyway.