Forum Xamarin.Forms

OpenGLView page example

ppowerppower ITMember
edited January 2017 in Xamarin.Forms

I'm really new to Xamarin.Forms and I'm trying Visual Studio for Mac.
I tried to build a cross-platform project based on Xamarin.Forms. I would use the OpenGLView inside a TestingPage inherited from ContentPage.
My cross-platform project, named TestOGL, has only one reference to "OpenTK-1.0". The only page added to the project instances the OpenGLView in its constructor, although I unsuccessfully tried to use the OpenGLView in the XAML tree.

public class OpenGLPage : ContentPage
        float red, green, blue;

        public OpenGLPage ()
            Title = "OpenGL";
            var view = new OpenGLView { HasRenderLoop = true };
            var toggle = new Switch { IsToggled = true };
            var button = new Button { Text = "Display" };

            view.HeightRequest = 300;
            view.WidthRequest = 300;

            view.OnDisplay = r => {

                GL.ClearColor (red, green, blue, 1.0f);
                GL.Clear ((ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit));

The iOS project has nothing special, apart the references to OpenTK-1.0, Xamarin.iOS, and TestOGL cross-platform assembly. I noticed that the cross-platform project includes an OpenTK.dll.config file, so I duplicated it also in the iOS project file and its content is here:

  <dllmap os="linux" dll="opengl32.dll" target=""/>
  <dllmap os="linux" dll="glu32.dll" target=""/>
  <dllmap os="linux" dll="openal32.dll" target=""/>
  <dllmap os="linux" dll="alut.dll" target=""/>
  <dllmap os="linux" dll="opencl.dll" target=""/>
  <dllmap os="linux" dll="libX11" target=""/>
  <dllmap os="linux" dll="libXi" target=""/>
  <dllmap os="linux" dll="SDL2.dll" target=""/>
  <dllmap os="osx" dll="opengl32.dll" target="/System/Library/Frameworks/OpenGL.framework/OpenGL"/>
  <dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
  <dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
  <dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
  <dllmap os="osx" dll="libGLESv1_CM.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
  <dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
  <dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
  <dllmap os="osx" dll="SDL2.dll" target="libSDL2.dylib"/>
  <!-- XQuartz compatibility (X11 on Mac) -->
  <dllmap os="osx" dll="" target="/usr/X11/lib/libGL.dylib"/>
  <dllmap os="osx" dll="libX11" target="/usr/X11/lib/libX11.dylib"/>
  <dllmap os="osx" dll="" target="/usr/X11/lib/libXcursor.dylib"/>
  <dllmap os="osx" dll="libXi" target="/usr/X11/lib/libXi.dylib"/>
  <dllmap os="osx" dll="libXinerama" target="/usr/X11/lib/libXinerama.dylib"/>
  <dllmap os="osx" dll="" target="/usr/X11/lib/libXrandr.dylib"/>

When I launch the Debug process in the iPhoneSimulator, I got a System.DLLNotFoundException because of libGLESv2.dll library is missing. What do I need to do?

System.DllNotFoundException: libGLESv2.dll
  at at (wrapper managed-to-native) OpenTK.Graphics.ES20.GL+Core:ClearColor (single,single,single,single)
  at OpenTK.Graphics.ES20.GL.ClearColor (System.Single red, System.Single green, System.Single blue, System.Single alpha) [0x00009] in /Users/builder/data/lanes/4009/0a4ab557/source/opentk/Source/OpenTK/Graphics/ES20.Android/ES.cs:2379
  at TestOGL.OpenGLPage+<OpenGLPage>c__AnonStorey0.<>m__0 (Xamarin.Forms.Rectangle r) [0x00027] in /Users/marco/Projects/TestOGL/TestOGL/TestingGLPage.cs:24
  at Xamarin.Forms.Platform.iOS.OpenGLViewRenderer+Delegate.DrawInRect (GLKit.GLKView view, CoreGraphics.CGRect rect) [0x00010] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\OpenGLViewRenderer.cs:101
  at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3985/62816dd6/source/xamarin-macios/src/UIKit/UIApplication.cs:79
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/3985/62816dd6/source/xamarin-macios/src/UIKit/UIApplication.cs:63
  at TestOGL.iOS.Application.Main (System.String[] args) [0x00008] in /Users/marco/Projects/TestOGL/iOS/Main.cs:17

Why don't you prepare a full and updated Xamarin.Forms OpenGLView that works with all the platforms from scratch? There's plenty of information, but it's really fragmented and any unexperienced user can't sort out all those projects like TextureCube and similar ones.

Sign In or Register to comment.