C# and Graphics

Started by
6 comments, last by gharen2 17 years ago
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?
Check out my devlog.
Advertisement
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.
I stumbled upon SDL.NET, which appears to be able to draw graphics inside a windows form.
Has anyone got any experience with it?

http://cs-sdl.sourceforge.net/
Check out my devlog.
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
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+.

GDI+ seems to be just the thing I was looking for, thanks everybody!
Check out my devlog.
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.
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.

This topic is closed to new replies.

Advertisement