6
\$\begingroup\$

I want to learn to develop 3D and 2D graphics with either OpenGL or DirectX. I chose OpenGL as it's being used in webGL and works cross-platform.

I already know .NET well, and the C# language just fits my style very well and I feel secure with it.

However, I want to develop a game that works on Windows and Linux. Is this possible to do with the combination of C#, .NET and OpenGL. I know that OpenGL will not be a problem.

\$\endgroup\$
  • \$\begingroup\$ Both answers so far mentioned Java so I'll comment here: should you choose to use Java, you can often compile on one platform, and use the resulting JAR file on any platform (there are occasional problems, and you should always test). It does have OpenGL bindings already, JOGL and LWJGL are the two most widely used. In addition, with the use of Java applets, your game can even easily run in a browser! This is my favorite and most appealing thing about Java; RuneScape is the most popular example of a Java applet which uses OpenGL (or DirectX!) to great effect. \$\endgroup\$ – Ricket Aug 14 '10 at 15:16
6
\$\begingroup\$

I highly suggest you take a look at OpenTK. Using it with MonoDevelop has worked out great for me in the past (Though I never wrote a full on game with it). If you stick the the C# 2.0 standard, you'll have little to no problems.

\$\endgroup\$
  • 1
    \$\begingroup\$ C# 3.0 and .NET 3.5 seem pretty well supported on Mono these days too. \$\endgroup\$ – Mike Strobel Aug 17 '10 at 17:38
4
\$\begingroup\$

Unity3D is developed using Mono, so of course you can!

Just be careful.

Like the others said: test your code as often as possible on 'the other OS' - and by that I mean daily.

Unity is available for Windows and the Mac, but since Mac essentially is unix, I guess it's only a matter of time/effort before Unity can target Linux..

\$\endgroup\$
  • \$\begingroup\$ Sometimes the best of answer lies below. Practically unity will be the best, given the op specifically mentioned C# as preferable. \$\endgroup\$ – cowboysaif Sep 9 '14 at 14:09
  • \$\begingroup\$ Unity currently supports Linux unity3d.com/unity/multiplatform/desktop \$\endgroup\$ – cowboysaif Sep 9 '14 at 14:13
  • \$\begingroup\$ Unless you are worried about their company logo in the flash screen, developing and distributing is free. \$\endgroup\$ – cowboysaif Sep 9 '14 at 14:14
3
\$\begingroup\$

In theory, yes, you should be able to develop a 3D application using C# and OpenGL on both Windows and Linux.

In practice, this is likely to be somewhat painful: you will need to restrict yourself to the subset of functionality that works for both Visual Studio and Mono, and it is likely that you won't be able to use many tools and libraries which have been targeted at only one environment.

You will need to take a very rigorous approach of converting your project files from one environment to the other, testing early and often so as to catch problems quickly, and rewriting immediately anything that proves not to be portable. This can be very frustrating at times.

In the end, ask yourself why you would want to target Linux. If learning C# and 3D development is your main goal, maybe you should concentrate on Windows instead of getting lost in the intricate details of different platforms. If your goal is to write a platform independent 3D application, many other interesting languages, such as Java or Python, might be better options in term of portability, and they are close enough to C# that you can leverage most of your experience in that domain.

\$\endgroup\$
  • 1
    \$\begingroup\$ You can use monodevelop on both windows and linux and therefore don't need to convert project files. You can have a monodevelop project file and a vs.net project file. Just like you can have a vs.net 2008 and a vs.net 2010 project file but pointing to same source... etc.. \$\endgroup\$ – bbqchickenrobot Aug 2 '12 at 0:41
1
\$\begingroup\$

Yes it's doable. If you need to check for compatibility while working with Visual Studio Mono Tools can be very helpful. But they aren't free.

Also there is always Java, which is a very similar language to C#, has great OpenGL bindings, and works virtually the same on all platforms.

\$\endgroup\$
1
\$\begingroup\$

SDL.NET looks like the best place to start. From their site

SDL.NET is a set of object-oriented CLS-compliant .NET bindings for the SDL gaming library and provides high-level access to audio, keyboard, mouse, joystick, TrueType fonts, various image formats, sound mixing, MPEG-1 movies, 2D video framebuffer and 3D hardware via OpenGL.

and SDL is

Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. It is used by MPEG playback software, emulators, and many popular games, including the award winning Linux port of "Civilization: Call To Power."

Qt seems to be another option for a cross platform UI.

MonoXNA and looks like a nice project, but it is still in its infancy. It may be a place for you dig in and get some great low level knowledge as the libraries come together.

\$\endgroup\$
0
\$\begingroup\$

Two people say yes, I'd say no.
You can do it using C# and OpenGL, but not using .NET. .NET is Windows specific.
Go with Mono and the libraries they support and you should be good. .NET framework is never fully ported (it's a hairy subject) but the base libraries are, so a lot of knowledge is applicable, but to be fact specific, no, a project developed with .NET is not guaranteed to compile or run on Linux.

Okay, edited to add, yes you can, if you don't use unported features. .NET is not fully crossplatform. I took the porting requirements stricter than what the question asked for.

\$\endgroup\$
  • \$\begingroup\$ Sorry, but Mono is .NET and not Windows specific. From their front page: Mono is an open source implementation of Microsoft's .NET Framework based on the ECMA standards for C# and the Common Language Runtime. mono-project.com/Main_Page \$\endgroup\$ – Larry Smithmier Aug 14 '10 at 17:54
  • \$\begingroup\$ That's great, but it's not saying it implements the full .NET framework, and if it is saying that, it is simply wrong. Check their roadmap: mono-project.com/Compatibility clearly certain features are not supported. I also advise you to check the wikipedia entry at en.wikipedia.org/wiki/.net_framework \$\endgroup\$ – Kaj Aug 14 '10 at 18:39
  • 2
    \$\begingroup\$ .NET is not the same as the .NET Framework. If you will edit your answer above to match the title of the Wikipedia entry you reference, and state that the full .NET Framework is not supported except on Windows, then I will gladly agree with you because you are correct. But ".NET is Windows specific." is incorrect. \$\endgroup\$ – Larry Smithmier Aug 14 '10 at 19:00
  • \$\begingroup\$ Fair enough. My post does say ".Net framework is never fully ported", but I indeed use the terms interchangeably (then again so does Mono in the line you quoted!). \$\endgroup\$ – Kaj Aug 14 '10 at 19:17
0
\$\begingroup\$

In theory it is possible, but unless you have your heart set on making a game in C#, I suggest using C++ instead. Compiled code is always faster if well written and you will be writing a game that produces an executable for the platform you are developing for. if you do write a game in C# for Linux, mono will produce and executable file that of course the .net framework will run, so even though you written the game for Linux, you actually written the game for the .Net Framework that is actually able to run the game because Mono open version works on Linux. kind of like wine, so in reality, you still only written the game for windows.

If that does not bother you then I say have fun, but like everybody else has already stated, you will have to avoid the windows only functions when making your game which might require you to reinvent the wheel to get the same functionality on Linux;however,those rules would apply no mater which language you choose go with unless you use Java which would be the same boat as C# but minus Unity awesomeness.

\$\endgroup\$
  • \$\begingroup\$ In practice, it is possible too. Talking of an OpenGL game, it will not be using lots of OS API. .NET has standard API for most uses. The only contentious point is creating the OpenGL context, for that, you can use conditional compilation, or take advantage of SDL.NET, OpenTK, MonoGame or Unity, all of which do it for you. Also, both Mono and .NET Framework have support for AOT (ahead of time) compilation that will generate native binaries. Doing this (the recommendation is to do it during installation) improves the perfomance, matching C++ in some scenarios. Ah, and shaders do not suffer. \$\endgroup\$ – Theraot May 18 '18 at 6:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.