Page 1 of 1

What the heck is C#?! (I want to learn it!)

Posted: Wed Jun 10, 2009 5:22 pm
by dandymcgee
Okay so I have a basic idea of what C# is. I've been using C++ for a little over a year now, and I'm familiar with the IDE's interface for the most part due to Visual Basic experience (they made me do it!). I have no clue where to start though. I'd like to just jump right in, as I don't feel I need to read another 200 tutorials explaining what a function is, or a variable, etc. Rather I just need to learn the syntax.

The only projects I ever made in VB contained moving image boxes, labels, buttons, etc. so what I don't understand is how do I draw "real" graphics in a window created in C#? Is there some sort of "OpenGL" control that I just paste on my form, or do I initialize something in the code? For instance, Mar, how are you drawing tiles/levels in your new map editor, which API do you use and how?

Feel free to tell me how completely ignorant I am, as long as its in a way that helps me to understand C# better, even if it be just a smidgin'. ;)

Re: What the heck is C#?! (I want to learn it!)

Posted: Thu Jun 11, 2009 12:39 pm
by programmerinprogress
I believe for shapes and images you use the GDI (graphics device interface)

In all honesty, when it comes to basic programming, the change isn't as odd as it switching to and from C++ to VB (easy but a royal pain in the ass if you're used to putting a semicolon after each statement)


I never got round to full blown C# excellence though, I made a few things in it, and then decided I want to use something a bit more low-level, and ch-ching! I switched to C++ full time ;)

Good luck with it anyway, I wish I could say I was tempted to try C# again... but if anything i'll be trying java because that's what they teach at my university in september (which believe me, after learning C++ for 2 years, i'm pissed about!)

Re: What the heck is C#?! (I want to learn it!)

Posted: Thu Jun 11, 2009 12:42 pm
by MarauderIIC
dandymcgee wrote:Okay so I have a basic idea of what C# is. I've been using C++ for a little over a year now, and I'm familiar with the IDE's interface for the most part due to Visual Basic experience (they made me do it!). I have no clue where to start though.
Microsoft Visual Studio -> File -> New Project... -> C# :)
I'd like to just jump right in, as I don't feel I need to read another 200 tutorials explaining what a function is, or a variable, etc. Rather I just need to learn the syntax.
It's pretty much VB + C++ = C# with a few conveniences and minor differences (as well as customary naming differences). Everything must be in a class. Which is fine, since your forms are a class of their own. If you really want a set of global functions, you can make a new class (add new item... class) and make it "public static MyClass". Then you can go MyClass.MyFunction().
The only projects I ever made in VB contained moving image boxes, labels, buttons, etc. so what I don't understand is how do I draw "real" graphics in a window created in C#? Is there some sort of "OpenGL" control that I just paste on my form, or do I initialize something in the code? For instance, Mar, how are you drawing tiles/levels in your new map editor, which API do you use and how?
The tiles in the tile controls are just drawn onto a PictureBox using a Graphics object. I load the tilesheet into a Bitmap, then I make a Bitmap of the appropriate size (depending on how many tiles the user wants to display longways) for the tile selection box and and "copy" tiles from the tilesheet into it (again using a Graphics object), then I Dispose() the tilesheet's Bitmap. I also have a List of Rectangles that denote what tile is where on my Bitmap. The main viewport is drawn using a User Control that is derived from OpenTK's GLControl.*

The map viewport is rendered using the OpenTK GLControl, which is able to run under The Mono Project. M_D_K wanted to use the Tao library, but I found OpenTK was easier to use with C#: the gl functions are in a C# style, whereas the Tao ones were in a C-style that was clunky and ugly and hard to use, in my opinion, when used with C#. If you want something fully developed and you don't mind it being windows-only, you can use XNA at this point, instead. So no: no built-in C# OpenGL. Needs XNA, DirectX, or some sort of OpenGL library (which is what OpenTK is).

I had originally done the same approach that I was doing for the tile controls, however, for large maps, it was too slow to load - 2s loadtime - and too slow to scroll around, as well as too much of a memory hog for any map. It was running at like 600k+ memory for our Big_lvl test map; now it's running at 20k.

*Most capitalized terms in this paragraph are type names that you may consider googling.

Re: What the heck is C#?! (I want to learn it!)

Posted: Thu Jun 11, 2009 3:44 pm
by dandymcgee
MarauderIIC wrote:
dandymcgee wrote:Okay so I have a basic idea of what C# is. I've been using C++ for a little over a year now, and I'm familiar with the IDE's interface for the most part due to Visual Basic experience (they made me do it!). I have no clue where to start though.
Microsoft Visual Studio -> File -> New Project... -> C# :)
Excellent, now I feel I'm ready to get started on my new operating system! :lol:

I'll take a look at OpenTK. Thanks for all of the advice Mar, I really do appreciate you guys' willingness to respond.

Re: What the heck is C#?! (I want to learn it!)

Posted: Thu Jun 11, 2009 5:25 pm
by MarauderIIC
dandymcgee wrote:Thanks for all of the advice Mar, I really do appreciate you guys' willingness to respond.
You're welcome.