Sign in to follow this  
blueapple

C# and Graphics

Recommended Posts

Here's my story; I've started coding a (tile based) game, using C++ and SDL + OpenGL. I've gotten so far so that a few fancy maps could be handy, so I decided to code a map editor. So I searched these forums and tested out various RAD "tools/languages" (ie. C#, wxPython, wxRuby etc.) and was really satisfied with C#. I can now write basic GUI applications, but to turn it into a map editor, I need some kind of "drawing area" where I can draw the map and handle mouse input. So now is my question to you; How would I go ahead creating a "drawing area", where I can draw tiles (sprites)? How would I get the input (ie. mouse clicks) on this area?

Share this post


Link to post
Share on other sites
You can draw on virtually anything, you just have to get a Graphics object for it. You can call Graphics.FromHwnd() (...I think that's the method) and draw using that.

Mouseclick events contain the location.

Share this post


Link to post
Share on other sites
Hey I don't know about SDL.NET but you could take a look at XNA - I'm using it to learn about games programming in C# at the moment and it's pretty simple to use. Have a look here:

http://msdn.microsoft.com/xna/

James

Share this post


Link to post
Share on other sites
you need to read about GDI+ in msdn,
you can set a panel and draw on it,
or you can use an imagebox control set a new bitmap to it and then you can have easy scrollbars (but having huge bitmap is not a good idea)

The mouse handling is simple, you need to look at the panel/imagebox mouse-down or mouse-move events

for faster performance there are SDL.net (9for openGl) there is Tao, but a game editor can do fine with GDI+.

Share this post


Link to post
Share on other sites
System.Drawing is the namespace you want to take a hard look at. That contains the object model for the GDI+ API. Take in to account that GDI+ is not the fastest roller skate on the rack, so keep that in mind. It's a great API, but it's not meant for speed. SDL.NET would be your next best choice if you wanted speed from hardware blits and such, but it's not as easy to use, and you will end up writing a lot of your own drawing code.

Share this post


Link to post
Share on other sites
Given that you're already familiar with opengl, and can presumably recycle existing code from your game, I'd suggest using opengl alongside system.windows.forms.

Drop a panel into the form as the draw area, along with whatever controls you want as the gui.

You can initialise opengl inside the panel just like you would any win32 window, using the panel's Handle property (which gives you the panel's HWND).

Either write your own bindings to the necessary functions (my preference) or use the Tao framework. The tao framework has the win32 functions necessary to initialise opengl, as well as all the opengl functions themselves.

Share this post


Link to post
Share on other sites

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