Gerharddc / CppGLESXamarin

A template solution to use C++ OpenGL inside a C# (Xamarin) application.
MIT License
5 stars 1 forks source link

iOS development #1

Open burf2000 opened 9 years ago

burf2000 commented 9 years ago

Hi there, I have forked this so I can try and do the iOS development etc.

Is there any licence for this or is it public domain? I want to do some samples etc for it

burf2000 commented 9 years ago

I am unable to get this to run on Xamarin studio for the Mac? Any ideas?

Gerharddc commented 9 years ago

@burf2000 I actually just got my hands on a mac today and will see if I can get it running tomorrow.

Gerharddc commented 9 years ago

@burf2000 I will starting it out now. Regarding the license, I am not enforcing any license on it so I guess you could say that it is public domain. I did use some code from the ANGLE template though. I'm not sure what license that is under but I doubt it will bother anyone. Maybe I'll check it out at some point.

Gerharddc commented 9 years ago

@burf2000 Ok I have just managed to get the C++ render working inside the default Xamarin OpenGL template. Unfortunately that uses a full-screen view controller and the goal here is actually to get something that is not full-screen. The whole project is also unbelievably messy at the moment. I will try to get it inside a view tomorrow and then also try to package it so that it integrates nicely with the template here. If all goes well I'll have the new template tomorrow evening, otherwise sometime next week.

Gerharddc commented 9 years ago

@burf2000 Ok, please check out the iOS-Next branch and tell me what you think. It should be working now except for release builds.

burf2000 commented 9 years ago

@Gerharddc hey there, sorry I missed your messages, sounds like you have done great work, Have you managed to get this working in Xamarin studio or just VS2015.

I was looking at OpenTK and boy does that have some issues on Android.

Full screen works for me but this is your baby.

Keep up the awesome work

burf2000 commented 9 years ago

Wow, you got it to work on iOS mate, thats amazing work, is there anyway you would move the Android project in to Xamarin Studio as the project is hugely broken if you open it in XS instead of VS2015?

Gerharddc commented 9 years ago

@burf2000 Unfortunately getting the Android up and running on XS will require some work that I do not have time for at the moment. This is because VS 2015 can automatically compile the Android library and reference it to the C# project thereby avoiding this large mess that I had to go through to get iOS working. Android though as I believe does not have the ability to create these "fat" library files that iOS has and you have to put mechanisms in place to get the correct binary copied and linked. If you have time then you could possibly look at it. I would recommend reading up on how to use C++ libraries in a Xamarin.Android project and then just try to incorporate the needed code. I believe it is slightly better documented than is the case with iOS if I remember correctly.

Regarding full-screen support though. If it is not your intention to have the OpenGL-ES view inside a native GUI then part of this project might be overkill. If you want to render the OpenGL-ES full-screen then you can far more easily get a full-screen GL context using EGL in the C++ code and give the whole interop rendering cycle a miss. If you do want to overlay native controls over the OpenGL though then off course you will need a lot of the stuff here.

Regarding OpenTK, it is indeed a mess and the reason why I chose to do this whole C++ OpenGL-ES thing instead of just trying to get OpenTK ported to Windows RT. In the long run though I guess I will reap the performance benefits. Furthermore it does not appear as if though OpenTK is really being actively maintained anymore even though every one is using it. I'm therefore also quite scared of it.

PS. If you do decide to try the Android thing yourself, you can read what I had to do to construct the project in VS at http://www.instructables.com/id/C-OpenGL-ES-Viewer-in-C. The process in XS should be similar though except for the part of linking to the library.

burf2000 commented 9 years ago

Thanks mate, you seem a really talented programmer! I will try and get some time to go through this. I am reviewing Xamarin for work and so I wanted to see if I could get OpenGl to Work.

What are you going to do with this framework? Are you making a game?

How come you did not use the Monogame 3D engine using XNA? I am just curious :)

Gerharddc commented 9 years ago

@burf2000 I am actually going to use this for the host applications of a new 3D printer that I am developing (http://www.declercqsystems.com/Simon1.html). This will be used for rendering 3D models.

As luck might have it, I actually used MonoGame for my previous app (http://www.windowsphone.com/en-us/store/app/reprap-phone-host/eb5a6b64-2949-498d-8f16-f6394a5e759b , https://www.youtube.com/watch?v=Sfd0ggeTKBw) which was for generic "RepRap" type 3D printers. It was never released for another platform though because I started working on this new machine with brand new technologies that I am building from scratch.

Regarding MonoGame, my biggest problem was horrible performance. Furthermore XNA 3D code is not as portable as that of GLES 2.0 in C++. This is relevant because I want to use WebGL for a web based device interface and do not want to maintain my 3D code in more than one language or platform as this will be my most complex code require the best performance. Another problem with MonoGame is that it is not designed for anything other than games, meaning that it does not natively support not being full-screen and it supports having more than one renderer in one application even less. This was my largest problem because I had to hack around quite a lot to get it working with 2 non-full-screen renderers in my one application. Performance in this setup is also far, far worse than it is already in full-screen games. For making simple games though, it is perfect, but do not try to use it for high-performance applications... By performance I am referring to both slowish loading performance and some awful overall UI stutter.

When I made that app though, ANGLE was not available for Windows (Phone/Store) and I could therefore not do what I am doing now using GLES.

When Windows (Phone/Store) started supporting WebGL though I immediately started work on a Three.JS renderer which was actually quite awesome and the WebViews performed brilliantly and finally gave me a smooth GUI. Sad to say though, once I tried to load large models I found the inherent problem with this approach. Using JS to construct 3D models/scenes is seriously slow. JS also does not have proper file access. I therefore had to load the files in C# and pass chunks to JS for construction. This makes the performance even worse... The web server was a must though because invoking the "runscript" type methods on a WebView itself is indescribably slow and clogs up the GUI thread making the app "freeze".

When ANGLE came out though, I knew that I had my answer...

Hope this helps!

Gerharddc commented 9 years ago

@burf2000 I forgot to mention that MonoGame tends to consume a chunk of memory.

burf2000 commented 9 years ago

@Gerharddc I really appreciate your time and knowledge, you should really blog this knowledge.

So my day job is iOS / Android senior developer usually doing business apps. At night I like to make games, but have a family so I don't get enough time.

I made a game called Hack 24 for iOS (simple 3D world in OpenGl) and I wanted to move it to Android but I did not have the time (https://itunes.apple.com/gb/app/hack24-3d-mmo/id890897701?mt=8)

I then started looking at VR for Android (https://play.google.com/store/apps/details?id=com.burfdevelopment.virtualworlds&hl=en_GB warning its terrible) as a learning thing

So the next 3D project I do I want to write it once, so I am trying my best to not do it in Unity! Its a awesome tool but not my kind of tool.

I am now looking for a solution for Android, iOS and maybe Windows. Monogame 3D is one of them. So is LibGDX and then I found your work. I want to share and show people simple examples of 3D stuff that is cross platform to.

OpenTK just seems to die on Android, would you say ANGLE is what I should use or your stuff?

Gerharddc commented 9 years ago

@burf2000 I have actually tried to start a blog a while back but unfortunately trying to get through high school and "starting a company" simultaneously isn't really leaving me with enough time to do so.

I must agree that Unity is great but it is immensely heavy and I am not into the whole scripting thing and proprietary development environment that they have going on there. Unreal Engine is very much of the same if I understand correctly.

I have actually never heard of LibGDX but the fact that it is written in Java scares me because I have an immense hatred of the language. I would personally not just anything that uses it.

I do believe that there might a bit of a confusion here. ANGLE is merely an OpenGL ES wrapper for DirectX 11 that allows GLES to run on Windows (Phone/Store) which do not have native support for GLES. I needed ANGLE in order to be able to create this project as it powers the Windows part of it. It is completely useless for iOS or Android though.

If you end up using this then all your C++ GLES should be portable (on iOS, Android and Windows Phone/Store) and almost all your C# code too. You will just have to implement the actual GUI files for each platform separately as well as the C# that directly interfaces with these GUIs.

Extending this project to work with Xamarin.Forms though will enable your code to be 99-100% portable. This is on my roadmap as I will need it for my project but I will only be looking at that in the rather distant future as I have to focus on firmware development at the moment. From what I have read though, implementing a new Xamarin.Forms control for this should be quite simple and will probably take a lot less time than in your case the development of an Android and iOS GUI. As a bonus you'll get a universal Windows one for free. If you really want though you should be able to use the current OpenGL Views in Xamarin.Forms which is only available on iOS and Android. It is intended to be used by OpenTK and will probably require the DLL for it. You do not actually have to use OpenTK though as merely routing the needed events from OpenTK to the C++ "should" work just fine. This is very "hackish" though and I would really not recommend it at all.

burf2000 commented 9 years ago

I was really impressed with your video with Nokia mate showing your 3D printer. super cool. OpenTk is doing me in, just does not work in shared forms with Android, there is a massive VBO issue.

My knowledge is really lacking here, I will look more at your code and see if I can get the Android side to work with the iOS side

Gerharddc commented 9 years ago

@burf2000 Thanks, and I wish you the best of luck.

I would though recommend that you get VS 2015 running as this will make your live a lot easier, especially if you have ReSharper. You can do this for free if you use the Community Edition (which is just fine and can do almost everything you need) and the free insider releases of Windows 10 as well as VirtualBox. Using the proper Windows 10 when it is released will be safer though and Parallels is off course much better. The Community Edition of VS is really fine though. I would recommend getting your company on this approach though so-that they can cover any costs. It will also be very beneficial to them, especially in terms of making great "native" multi-platform apps in very little time with very little hassle.

PS. I have seen that the VS solution might have problems with Android when opened from a cloned repo. I am still trying to figure out why. Using the existing source files and reconstructing the projects using my tutorial should fix this for now though.

PPS. When working with Xamarin and VS, I would recommend doing the bulk of the actual code development for Windows and then just doing some quick work to get it working on iOS and Android. The reason for this being that everything is just more seamless and a lot faster when working with Windows. Again, if Xamarin.Forms is used, almost no code will have to be added for the other platforms. The biggest difference will be in referencing any C++ libraries. For Windows RT C++ can be compiled as a runtime component which works pretty much exactly the same as a normal C# DLL from a C# perspective. For iOS and Android though, you will need to use DLLImport (P/Invoke) to wrap the C++ headers. This can be automated for large libraries using CPPSharp. When using P/Invoke though you should just keep in mind that there is a marshalling cost involved when shifting data between the languages. I am not sure is this is relevant for Windows RT and runtime components though.