5

guys. I have a opengl library written in c++. I know that I can use Angle but because of this I will need to code in C++ my whole app. Is there a way to use c++ opengl in UWP and still use C# as a main language?

Rustam Ibragimov
  • 2,571
  • 7
  • 22
  • 33
  • Maybe [this](http://stackoverflow.com/questions/32015682/how-to-use-c-class-in-windows-10-c-sharp-universal-app) helps. You can find a lot of info about interoperability on MSFT docs. – Kristian Vukusic Oct 09 '16 at 14:10

3 Answers3

6

Is there a way to use c++ opengl in UWP and still use C# as a main language?

ANGLE is currently the only way to get the OpenGL API to run in UWP. For more details please reference this thread.

You can write your own via interop if you want to use ANGLE from c#. You can also write your low level OpenGL stuff in C++ and wrapper it. Then invoke it by C# in your logic level.

Fortunately, people who have the same requirements as you created an issue on the GitHub a few days ago, and got samples from @mattleibow. @mattleibow shared his code in this thread. For more details, please reference OpenGL surface from SwapChainPanel declared in XAML in C#.

Additionally, ANGLE is actually for translating OpenGL ES to DirectX. So I recommend you to use Win2D instead. Win2D is a new, immediate mode 2D drawing framework for XAML applications on Windows 8.1 and Windows 10. It is built on the high performance foundation of DirectX, but is designed to provide the convenience and ease of use expected by C# and .NET developers. More details you can reference this video.

Impurity
  • 1,037
  • 2
  • 16
  • 31
Sunteen Wu
  • 10,509
  • 1
  • 10
  • 21
  • Thanks, but I already have an opengl library written in c++ and I need to somehow integrate this library to UWP. Rewriting it to DirectX would take a lot of time. – Rustam Ibragimov Oct 11 '16 at 04:38
  • @RustamIbragimov please reference [OpenGL surface from SwapChainPanel declared in XAML in C#](https://github.com/Microsoft/angle/issues/89) – Sunteen Wu Oct 11 '16 at 04:41
0

I realize it's been a long time since you posed this question, but I needed to do this also, so put together a small C# project that shows how to use ANGLE from C#. It includes minimal bindings to GL from C# (since OpenTK does not yet target UWP), and a part of the template application from ANGLE itself, which has all the SwapChainPanel, etc, setup. You can check it out here.

j4m3z0r
  • 397
  • 1
  • 3
  • 8
0

I had this issue, so I created my own library. You could use my new library (https://github.com/hamarb123/hamarb123.SharpGLES) which runs OpenGL ES on UWP (and .NET Framework), it even has a GLESSwapChainPanel class for ease of use.