summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/GalleryPages/OpenGLGallery.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Controls/GalleryPages/OpenGLGallery.cs')
-rw-r--r--Xamarin.Forms.Controls/GalleryPages/OpenGLGallery.cs70
1 files changed, 70 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls/GalleryPages/OpenGLGallery.cs b/Xamarin.Forms.Controls/GalleryPages/OpenGLGallery.cs
new file mode 100644
index 00000000..bb5ce8ab
--- /dev/null
+++ b/Xamarin.Forms.Controls/GalleryPages/OpenGLGallery.cs
@@ -0,0 +1,70 @@
+´╗┐using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+#if HAVE_OPENTK
+using OpenTK.Graphics;
+using OpenTK.Graphics.ES20;
+#endif
+
+namespace Xamarin.Forms.Controls
+{
+#if HAVE_OPENTK
+ public class OpenGLGallery : ContentPage
+ {
+ float red, green, blue;
+
+ public OpenGLGallery ()
+ {
+ 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 =>{
+ /*
+ if (!inited) {
+ var shader = GL.CreateShader (All.VertexShader);
+ int length = 0;
+ GL.ShaderSource (shader, 1, new string [] { "void main() { gl_FragColor = vec4(0.6, 1.0, 0.0, 1.0); }"}, ref length);
+ GL.CompileShader (shader);
+ int status = 0;
+ GL.GetShader (shader, All.CompileStatus, ref status);
+ if (status == 0) {
+ GL.DeleteShader (shader);
+ throw new Exception();
+ }
+
+ inited = true;
+ }
+ */
+ GL.ClearColor (red, green, blue, 1.0f);
+ GL.Clear ((ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit));
+
+ red += 0.01f;
+ if (red >= 1.0f)
+ red -= 1.0f;
+ green += 0.02f;
+ if (green >= 1.0f)
+ green -= 1.0f;
+ blue += 0.03f;
+ if (blue >= 1.0f)
+ blue -= 1.0f;
+ };
+
+ toggle.Toggled += (s, a) => { view.HasRenderLoop = toggle.IsToggled; };
+ button.Activated += (s, a) => view.Display ();
+
+ var stack = new StackLayout {Padding = new Size (20, 20)};
+ stack.Add (view);
+ stack.Add (toggle);
+ stack.Add (button);
+
+ Content = stack;
+ }
+ }
+#endif
+}