MonoGame on Raspberry Pi...


40 posts   Page 1 of 2   1, 2
by CartBlanche » Fri Nov 04, 2011 10:20 pm
Hi All,
I'm the project co-ordinator on the MonoGame project. What is MonoGame I hear you ask...
MonoGame is an open source implementation of the XNA APIs using OpenGL, that allows developers to build 2D games that run on Android, iPhone, iPad, Mac, Linux and Windows using the same code base, or reusing existing XNA code that runs on Xbox 360 or Windows Phone 7.


We recently announced MonoGame 2.0

In summary you use Mono's C# compiler to write your game, then target the aforementioned platforms, and I hope eventually Raspberry Pi. There is already another thread that shows that the Mono compiler should work on the device.

So what I'd like to know is if someone could grab the latest sourcecode from here https://github.com/mono/MonoGame and using the Mono compiler on a Raspberry Pi to see if our humble project will work on the RPi?

I envision the RPi as being a great educational tool for would be game programmers to prototype their game ideas or even for newbies to learn game development on a cheap, yet powerful device.

I look forward to your feedback.
Posts: 14
Joined: Fri Nov 04, 2011 10:04 pm
by liz » Fri Nov 04, 2011 10:45 pm
You could be in for a bit of a wait - alpha boards are so scarce that even I don't have one! Let's hope somebody who has one can help you out.
--
Head of Comms, Raspberry Pi Foundation
User avatar
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 4094
Joined: Thu Jul 28, 2011 7:22 pm
by pepedog » Fri Nov 04, 2011 10:51 pm
I will try, possibly tomorrow.
Posts: 968
Joined: Fri Oct 07, 2011 9:55 am
by liz » Fri Nov 04, 2011 10:55 pm
You're brilliant - thank you!
--
Head of Comms, Raspberry Pi Foundation
User avatar
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 4094
Joined: Thu Jul 28, 2011 7:22 pm
by CartBlanche » Sat Nov 05, 2011 10:41 am
Hi pepedog, that would be most excellent!
Posts: 14
Joined: Fri Nov 04, 2011 10:04 pm
by pepedog » Sat Nov 05, 2011 1:14 pm
Can you give brief instructions to use please. Assume I got the git cloned.
It seems opentk is needed, so show how that is "installed" too.
Thanks
Dave
Posts: 968
Joined: Fri Oct 07, 2011 9:55 am
by CartBlanche » Sun Nov 06, 2011 12:00 am
Hi Pepe,
Thanks for taking the time to try this out...

I'm assuming you are using a Linux distro, so for that you'll have to download the Linux sources from
http://www.opentk.com/files/do.....pentk.html
this should build an OpenTK assembly.

I would suggest the following...

Grab the latest MonoGame-Samples code from https://github.com/CartBlanche/MonoGame/zipball/master, unzip it at the same directory level as MonoGame
Your Directory structure should look like this...
[SomeDir]
MonoGame
MonoGame-Samples
OpenTK

Now from MonoDevelop 2.8.x, navigate into the MonoGame-Samples/Samples directory and you should see MonoGame.Samples.Linux.sln, Open this solution.
Within this solution you should find the Tetris or Draw2D sample. Right click select "Run Item". This should then build and run that sample.

The most likely error is that the MonoGame project cannot find the OpenTK assembly.

Actually it just dawned on me that there may be another complication. The Android and iOS ports support OpenGL ES 1.1, via OpenTK, but the Linux port only supports standard OpenGL. So for this to run, I think we'd need a Linux OpenTK that handles OpenGL ES. If the OpenTK build script handles this automagically, then problem solved.

I hope this helps.

D.
Posts: 14
Joined: Fri Nov 04, 2011 10:04 pm
by pepedog » Sun Nov 06, 2011 12:48 pm
CartBlanche
First I am building on a trimslice, for speed/comfort/and GL/GLES (Dual cpu 1000 MHz tegra ARMV7 with hard float and 1Gb ram) Will try on RP if works.
Link for opentk was an exe, I sought zip. I used xbuild on source dirrectory sln file.
Also opened in monodevelop and chose build all, not able to see progresss as silent but cpu load went high.
No MonoGame-Samples directory in link supplied. Perhaps you meant https://github.com/CartBlanche/MonoGame-Samples (271 Mb)
Now I have to cook dinner, I am on steep learning curve with this. I have used VB3 and VB5 a long while ago.
If I built opentk, where do I place sample?
Posts: 968
Joined: Fri Oct 07, 2011 9:55 am
by CartBlanche » Sun Nov 06, 2011 1:01 pm
Yes Pepe,I did mean MonoGame-Samples.

If you have the OpenTK directory at the same level as the other 2, within OpenTK there will be a bin sub-directory where the OpenTK.dll assembly should be created. As long as it is somewhere there, it should hopefully be ok.

It all hinges on the OpenTK building with ES 1.1 support. If it does, then using the Linux project should be the next step. I'm not sure how compatible the fixed function OpenGL calls will be between versions.
Posts: 14
Joined: Fri Nov 04, 2011 10:04 pm
by pepedog » Sun Nov 06, 2011 8:39 pm
Well using xbuild the dll's got created (in debug folder? 23000 warnings 0 errors), opening the opentk sln file in monodevelop was not helpful.
I am not the most patient person and there are a few opentk folders
Posts: 968
Joined: Fri Oct 07, 2011 9:55 am
by CartBlanche » Sat Jun 02, 2012 9:20 am
Sorry for not getting back to you Pepe.
I've seen some other threads that talk about getting Mono running on the Pi, so think getting MonoGame running on there, won't be too big a job as MonoGame already has some OpenGL ES 2.0 bindings though OpenTK. So if OpenTK builds on Pi, so should MonoGame.
Posts: 14
Joined: Fri Nov 04, 2011 10:04 pm
by ChrisSwan » Thu Jun 07, 2012 4:04 pm
Hi, thought I'd chip in and start trying to help with this.
I installed Mono-complete on Pi and that compiles and runs my HelloWorld test app just fine.
I unzipped that latest OpenTk (from nightly opentk-2012-03-15.zip) and tried running the already compiled Examples.exe through the desktop: the examples window was ok but the examples all fail to run (moaning about being unable to grab the display).
I've moved onto using xbuild to compile a release version of OpenTK. This gave an error about a missing OpenTK.Compatibility.xml Moving over to building on Windows I ended up with the same error - this xml file is simply missing from the snapshot!
Hunting around the web I found a copy of the xml file and OpenTk has now compiled on Pi with 936 warnings and no errors.

I then run Examples.exe through the desktop, and the Toolkit Sample Browser loads up. However, trying to run OpenGLES Samples->Simple ES 2.0 gives the following errors:

Code: Select all
Could not set X locale modifiers
OpenTK.Graphics.GraphicsModeException: Requested GraphicsMode not available.
  at OpenTK.Platform.X11.X11GraphicsMode.SelectGraphicsMode
(ColorFormat color, Int32 depth, Int32 stencil, Int32 samples,ColorFormat accum, Int32 buffers, Boolean stereo) [0x00000] in <filename unknown>:0
  at OpenTK.Graphics.GraphicsMode.LazySelectGraphicsMode () [0x00000] in <filename unknown>:0
  at OpenTK.Graphics.GraphicsMode.get_Stencil () [0x00000] in <filename unknown>:0
  at OpenTK.Graphics.GraphicsMode..ctor (ColorFormat color, Int32 depth) [0x00000] in <filename unknown>:0
  at Examples.Tutorial.SimpleES20Window..ctor () [0x00000] in <filename unknown>:0
  at Examples.Tutorial.SimpleES20Window.Main () [0x00000] in <filename unknown>:0
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0


Any thoughts on what my next steps should be?
User avatar
Posts: 26
Joined: Thu Jun 07, 2012 3:01 pm
by ChrisSwan » Thu Jun 07, 2012 6:35 pm
For some more info I thought I'd see what would happen if I now tried to build MonoGame on Pi, since I now have a compiled (if not running) OpenTK. I downloaded the latest MonoGame version from the site, and ran xbuild against the linux .sln file. First off I had a slew of errors as it couldn't find OpenTK.dll, but I managed to edit the project file to add that dll path.

I still get some errors though:

Code: Select all
Errors:

/home/pi/MonoGame-2.5.0.0/MonoGame.Framework.Linux.sln (default targets) ->
(Build target) ->
/home/pi/MonoGame-2.5.0.0/MonoGame.Framework/MonoGame.Framework.Linux.csproj (default targets) ->
/usr/lib/mono/4.0/Microsoft.CSharp.targets (CoreCompile target) ->

        Linux/Graphics/Effect/EffectPass.cs(58,36): error CS1502: The best overloaded method match for `OpenTK.Graphics.OpenGL.GL.ProgramParameter(int, OpenTK.Graphics.OpenGL.AssemblyProgramParameterArb, int)' has some invalid arguments
        Linux/Graphics/Effect/EffectPass.cs(58,36): error CS1503: Argument `#2' cannot convert `OpenTK.Graphics.OpenGL.Version32' expression to type `OpenTK.Graphics.OpenGL.AssemblyProgramParameterArb'
        Linux/Graphics/Effect/EffectPass.cs(59,36): error CS1502: The best overloaded method match for `OpenTK.Graphics.OpenGL.GL.ProgramParameter(int, OpenTK.Graphics.OpenGL.AssemblyProgramParameterArb, int)' has some invalid arguments
        Linux/Graphics/Effect/EffectPass.cs(59,36): error CS1503: Argument `#2' cannot convert `OpenTK.Graphics.OpenGL.Version32' expression to type `OpenTK.Graphics.OpenGL.AssemblyProgramParameterArb'
        Linux/Graphics/Effect/EffectPass.cs(71,36): error CS1502: The best overloaded method match for `OpenTK.Graphics.OpenGL.GL.ProgramParameter(int, OpenTK.Graphics.OpenGL.AssemblyProgramParameterArb, int)' has some invalid arguments
        Linux/Graphics/Effect/EffectPass.cs(71,36): error CS1503: Argument `#2' cannot convert `OpenTK.Graphics.OpenGL.Version32' expression to type `OpenTK.Graphics.OpenGL.AssemblyProgramParameterArb'

         26 Warning(s)
         6 Error(s)

Time Elapsed 00:00:51.9590040


I'm not sure I know where to start with these ones...
User avatar
Posts: 26
Joined: Thu Jun 07, 2012 3:01 pm
by ChrisSwan » Fri Jun 08, 2012 9:06 am
Me again ;-)

Well definite progress has been made now. Looking at those errors in more detail against the source files I realised there was a mismatch between the OpenTK and MonoGame versions. So I downloaded the OpenTK V1.0 (opentk-2010-10-06.zip) and that built straight away on the Pi without errors. Moving on to MonoGame.Framework that then built without errors too :-)

So next I've downloaded your MonoGame-Samples to the pi and ran xbuild: After pointing the .sln file at the right folders for MonoGame.Framework and ThirdParty I get 5 errors, but a lot of the examples have succesfully compiled.

I noticed that Draw2D was one of the successful compilations, so I tried running that but it unfortunately crashes with lots of 0x0000 addresses for the graphics device initialisation.

Stepping back I tried the OpenTK example (the OpenGL ES one in particular), but that also refused to run with basically the same error.

Here are the runtime errors:

Code: Select all
Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for OpenTK.Graphics.GraphicsMode ---> System.PlatformNotSupportedException: Please, refer to http://www.opentk.com for more information.
  at OpenTK.Platform.Factory+UnsupportedPlatform.CreateGraphicsMode () [0x00000] in <filename unknown>:0
  at OpenTK.Graphics.GraphicsMode..cctor () [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at OpenTK.GameWindow..ctor () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.GameWindow.Initialize () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.GameWindow..ctor () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.LinuxGamePlatform..ctor (Microsoft.Xna.Framework.Game game) [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.GamePlatform.Create (Microsoft.Xna.Framework.Game game) [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.Game..ctor () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Samples.Draw2D.Game1..ctor () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Samples.Draw2D.Program.Main () [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for OpenTK.Graphics.GraphicsMode ---> System.PlatformNotSupportedException: Please, refer to http://www.opentk.com for more information.
  at OpenTK.Platform.Factory+UnsupportedPlatform.CreateGraphicsMode () [0x00000] in <filename unknown>:0
  at OpenTK.Graphics.GraphicsMode..cctor () [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at OpenTK.GameWindow..ctor () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.GameWindow.Initialize () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.GameWindow..ctor () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.LinuxGamePlatform..ctor (Microsoft.Xna.Framework.Game game) [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.GamePlatform.Create (Microsoft.Xna.Framework.Game game) [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.Game..ctor () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Samples.Draw2D.Game1..ctor () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Samples.Draw2D.Program.Main () [0x00000] in <filename unknown>:0


So I'm getting closer, but no cigar just yet ;-)
User avatar
Posts: 26
Joined: Thu Jun 07, 2012 3:01 pm
by YttriumOx » Wed Jun 20, 2012 1:40 pm
Hi CartBlanche, Pepe, Chris and anyone else following along,

I thought I'd join the fun trying to get this going on my Raspberry Pi as well. Actually, if we can get it sorted out, it's going to make my life at work much easier for a special project I'm working on that might end up using the RPi and Mono; and XNA could well be a good choice for my UI.

So far I've only dedicated about 6 hours of time to getting this up and running here at my office; but thanks to all the wonderful info you guys have posted above, I've been able to get to basically the same point as Chris without a great deal of trouble.
  • I'm doing all this on the debian wheezy beta release for the Raspberry Pi.
  • My builds for mono apps/dlls/components are all done with mdtool rather than xbuild.
  • Mono is working fine and dandy in general (i.e. enough for "Hello World"; assuming all okay in general).
  • OpenTK is built - I used opentk-2010-10-06.
    • Lots of warnings on compile, but no errors.
    • The OpenTk "Examples.exe" runs, but attempting to use any of the GL examples gives me the same "OpenTK.Graphics.GraphicsModeException" that Chris posted.
  • I can't seem to get git working through my corporate proxy (anyone had experience with this?) even after setting both the environment variable and git config http.proxy; so I have to grab everything manually (minor annoyance only at this stage).
  • According to this tutorial, "mesa-common-dev" is required ("OpenTk needs this to create a window"). I've installed this via apt-get; but there's no change in behaviour.
  • Carrying on anyway, just as Chris did, I built MonoGame 2.1.5 and had no problems (78 warnings, 0 errors).
  • I then compiled the samples from CartBlanche (putting the MonoGame-Samples directory under the main MonoGame directory to solve the pathing issue, instead of changing the solution and/or projects).
    • This is where my result differs from Chris's - I got no errors compiling the samples at all.
  • Despite the build going well, attempting to start any of the samples gives me the same "OpenTK.Graphics.GraphicsModeException: Requested GraphicsMode not available" exception as the OpenTk Examples.exe.
So, that's where I'm up to so far... basically the same as Chris, but I'm hopeful we can make progress and get it going.
I'm working under the assumption that until we can get OpenTk working correctly, MonoGame is just always going to fail with the same issue.

If I find out anything new, I'll be sure to let you know and hope you all can do the same!
Posts: 1
Joined: Wed Jun 20, 2012 11:25 am
by ChrisSwan » Wed Jun 20, 2012 9:00 pm
Hi YttriumOx, welcome to the party :D

Great to hear that you've at least got to the same point as me. I've been battling away at this some more, and here are my latest findings:

  • The first problem was that X11 wasn't being detected (even when running through LXDE). Installing libX11-dev fixed that part.
  • But the next issue is that libEGL.so isn't being picked up. Initially I thought the culprit was GlxHelper.cs as the library string is libGL instead of EGL, but changing that string didn't fix anything. I now think that's a red herring though, as I suspect that the code shouldn't have gone down that path in the first place.
  • I next found this post but adding that function didn't change anything.
  • My idea after that was to set up an Ubuntu machine with PowerVR's EGL emulator to see if I could repro the problem, but annoyingly that ran just fine!
  • So my very latest idea is to compare the output of the Pi using 'MONO_LOG_LEVEL=debug mono Examples.exe' against the output on Ubuntu and try to fathom out where they are differing. I'll hopefully be able to feed more back on that tomorrow or Friday.

I *think* mesa is a dead end as my understanding is that it's for OpenGL, not GLES. Oh, and I haven't had any git problems myself I'm afraid.

Agreed that OpenTK definitely seems to be the problem area, and if we can get past this then I'm fairly confident that monogame will start working too.

Hopefully between us we can progress this one and get things working! ;)
User avatar
Posts: 26
Joined: Thu Jun 07, 2012 3:01 pm
by juantar » Wed Jul 18, 2012 1:18 pm
Were you able to have MonoGame run in the Pi?

Thanks!
Posts: 2
Joined: Wed Jul 18, 2012 1:17 pm
by dellis1972 » Mon Jul 23, 2012 5:51 pm
hi

I've started looking at this myself. I think the main problem is the inability to resolve the libEGL dll/so. This is what is causing allot of the problems, the openTK doesnt know it supports GLES. There are a few instances where OpenTK is trying to use the Desktop Factory to do things rather than the embedded one which is what we should be using.

I have a sample opentk app running in a emulatored gles 2.0 environment on my windows box. Though, so we know it works, just need to get the correct dll loading.

Once opentk is working it will be quite easy to get a MonoGame.Framework.Embedded.dll sorted out,

Dean
Posts: 13
Joined: Mon Jul 23, 2012 12:07 pm
by noxo » Tue Jul 31, 2012 7:57 pm
Hi guys,

I managed to run MonoGame sample(s) on Raspberry PI. I've one screenshot evidence in
here: https://twitter.com/enoksokoivisto/status/230201323944022016/photo/1 ;)

I tried this with Debian Squeeze (ARMEL), because there seems to be a lot of evidence that Mono does not run properly on ARMHF. For example OpenTK example caused Mono to crash on floating point related looking error on Debian Wheezy (ARMHF).

Debian Squeeze comes with Mono 2.6.9 which only support C# 3.0, so build target must be set to C# 3.0 in MonoGame sample(s) and Framework. In addition GraphicsDevice class in MonoGame requires minor changes, because it were using Enum.HasFlag method, which is only available in C# 4.0.

I think that main issue is the performance, it's was really bad on my try. I think it's due that OpenTK uses software rasterizer / renderer (libGL.so.1 from package mesa-common-dev) instead HW accelerated OpenGL ES (/opt/vc/lib).

So next actions to have a decently running MonoGame on RPI would be:
[*] OpenTK running in OpenGL ES mode on Linux
[*] MonoFrameWork.Linux to use OpenGL ES instead of OpenGL

Unfortunately Mono 2.6.9 ARMEL seems also be prone to crash on floating point type of errors on some Box2DXNA stuff that I tried.

In end, here's my short checklist how-to prepare RPI:

[*] Debian Squeeze (debian6-19-04-2012.img)
[*] mono 2.6.9 (apt-get install mono-runtime)
[*] mesa opengl drivers (apt-get install mesa-common-dev)

Optional for audio:
[*] open al for audio (apt-get install libopenal-dev)
[*] load alsa driver module (modprobe snd_bcm2835)

BR
Erkki
Posts: 15
Joined: Tue Jul 31, 2012 6:52 pm
Location: Vantaa, Finland
by dellis1972 » Wed Aug 01, 2012 8:10 am
Hi Erkki

Good work, I managed to get Mono 2.10.x working ok on Raspbian but I'm not tried any floating point stuff , I will try today.

I had to make some tweeks to OpenTK to get it to load the GLES so, but then hit some entry point not found errors. I have already started on a MonoGame.Framework.Embedded project which is kind of a hibrid between the linux version and the opengles supported version used by iOS/Android.

I think OpenTK is the main problem, once that is working correctly the rest of the framework should just work.

Dean
Posts: 13
Joined: Mon Jul 23, 2012 12:07 pm
by noxo » Wed Aug 01, 2012 9:07 am
Hi Dean,

Nice to know somone is working on "Linux Desktop GLES" support for OpenTK and MonoGame.

Do you share source code of these forks of MonoGame and OpenTK somewhere (GitHub etc), would be super-nice to follow the progress and fiddle with it? I know it's still under development, but still ;) I also started some work to merge MonoGame.Android stuff to MonoGame.Linux for GLES support, but I'm sure you have made a lot more progress.

Erkki
Posts: 15
Joined: Tue Jul 31, 2012 6:52 pm
Location: Vantaa, Finland
by dellis1972 » Wed Aug 01, 2012 9:08 am
Hmm.

I think mono will need to have a custom compile for the pi.

I ran this code

DateTime startTime = DateTime.Now;
double root;
for (int i = 0; i <= 100000000; i++)
{
root = Math.Sqrt(i);
}
TimeSpan runTime = DateTime.Now - startTime;
Console.WriteLine("Time elapsed: " + Convert.ToString(runTime.TotalMilliseconds/1000));
Console.ReadLine();

On a desktop it took 0.77 seconds to run.

The Pi took 32.2 seconds to run, which suggests that the default installation is using software floating point support. I would not expect the pi to run the code in 0.77 seconds but it should be quicker than 32.2.

The C version ran in 10 seconds, so I assume we could get mono to run in at least 10 seconds with the proper compile flags.

Dean
Posts: 13
Joined: Mon Jul 23, 2012 12:07 pm
by dellis1972 » Wed Aug 01, 2012 1:09 pm
Erkki

I'll try and get the code into a branch so people can play with it over the weekend. :)

Not to sure what to do with the opentk stuff, its not stored on github so its makes it difficult to fork without taking a copy of the whole thing

Dean
Posts: 13
Joined: Mon Jul 23, 2012 12:07 pm
by noxo » Wed Aug 01, 2012 3:15 pm
dellis1972 wrote:Erkki

I'll try and get the code into a branch so people can play with it over the weekend. :)

Not to sure what to do with the opentk stuff, its not stored on github so its makes it difficult to fork without taking a copy of the whole thing

Dean


That would be awesome, isn't OpenTK also in GitHub under the Mono project (http://github.com/mono/opentk) ?

Erkki
Posts: 15
Joined: Tue Jul 31, 2012 6:52 pm
Location: Vantaa, Finland
by dellis1972 » Thu Aug 02, 2012 8:45 am
It is but that is not the latest svn version there are been some changes since then. I will check, perhaps I can fork that version and then merge the changes from svn into that.

Dean
Posts: 13
Joined: Mon Jul 23, 2012 12:07 pm