├── Droid ├── Assets │ └── AboutAssets.txt ├── MainActivity.cs ├── OpenGLDemo.Droid.csproj ├── Properties │ ├── AndroidManifest.xml │ └── AssemblyInfo.cs ├── Resources │ ├── AboutResources.txt │ ├── Resource.designer.cs │ ├── drawable-hdpi │ │ ├── icon.png │ │ └── mario.png │ ├── drawable-xhdpi │ │ ├── icon.png │ │ └── mario.png │ ├── drawable-xxhdpi │ │ ├── icon.png │ │ └── mario.png │ └── drawable │ │ └── icon.png └── packages.config ├── OpenGLDemo.sln ├── OpenGLDemo.userprefs ├── OpenGLDemo ├── OpenGLCube.cs ├── OpenGLDemo.cs ├── OpenGLDemo.projitems ├── OpenGLDemo.shproj ├── Shaders │ ├── Fragment.glsl │ ├── SimpleFragment.glsl │ ├── SimpleVertex.glsl │ └── Vertex.glsl └── mario.png ├── README.md ├── UITests ├── AppInitializer.cs ├── OpenGLDemo.UITests.csproj ├── Tests.cs └── packages.config └── iOS ├── AppDelegate.cs ├── Entitlements.plist ├── ITunesArtwork ├── ITunesArtwork@2x ├── Info.plist ├── Main.cs ├── OpenGLDemo.iOS.csproj ├── Resources ├── Default-568h@2x.png ├── Default-Portrait.png ├── Default-Portrait@2x.png ├── Default.png ├── Default@2x.png ├── Icon-60@2x.png ├── Icon-60@3x.png ├── Icon-76.png ├── Icon-76@2x.png ├── Icon-Small-40.png ├── Icon-Small-40@2x.png ├── Icon-Small-40@3x.png ├── Icon-Small.png ├── Icon-Small@2x.png ├── Icon-Small@3x.png └── LaunchScreen.storyboard └── packages.config /Droid/Assets/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories) and given a Build Action of "AndroidAsset". 3 | 4 | These files will be deployed with your package and will be accessible using Android's 5 | AssetManager, like this: 6 | 7 | public class ReadAsset : Activity 8 | { 9 | protected override void OnCreate (Bundle bundle) 10 | { 11 | base.OnCreate (bundle); 12 | 13 | InputStream input = Assets.Open ("my_asset.txt"); 14 | } 15 | } 16 | 17 | Additionally, some Android functions will automatically load asset files: 18 | 19 | Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); 20 | -------------------------------------------------------------------------------- /Droid/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Android.App; 4 | using Android.Content; 5 | using Android.Content.PM; 6 | using Android.Runtime; 7 | using Android.Views; 8 | using Android.Widget; 9 | using Android.OS; 10 | 11 | namespace OpenGLDemo.Droid 12 | { 13 | [Activity (Label = "OpenGLDemo.Droid", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] 14 | public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity 15 | { 16 | protected override void OnCreate (Bundle bundle) 17 | { 18 | base.OnCreate (bundle); 19 | 20 | global::Xamarin.Forms.Forms.Init (this, bundle); 21 | 22 | LoadApplication (new App2 ()); 23 | } 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Droid/OpenGLDemo.Droid.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 7 | {5F037DD6-8F6E-4197-9909-C58C67CE5746} 8 | Library 9 | OpenGLDemo.Droid 10 | Assets 11 | Resources 12 | Properties\AndroidManifest.xml 13 | Resource 14 | Resources\Resource.designer.cs 15 | True 16 | True 17 | OpenGLDemo.Droid 18 | v5.0 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug 25 | DEBUG; 26 | prompt 27 | 4 28 | None 29 | false 30 | true 31 | 32 | 33 | full 34 | true 35 | bin\Release 36 | prompt 37 | 4 38 | false 39 | false 40 | true 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | ..\packages\Xamarin.Forms.1.3.3.6323\lib\MonoAndroid10\FormsViewGroup.dll 49 | 50 | 51 | 52 | ..\packages\Xamarin.Android.Support.v4.21.0.3.0\lib\MonoAndroid10\Xamarin.Android.Support.v4.dll 53 | 54 | 55 | ..\packages\Xamarin.Forms.1.3.3.6323\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll 56 | 57 | 58 | ..\packages\Xamarin.Forms.1.3.3.6323\lib\MonoAndroid10\Xamarin.Forms.Core.dll 59 | 60 | 61 | ..\packages\Xamarin.Forms.1.3.3.6323\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /Droid/Properties/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Droid/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using Android.App; 4 | 5 | // Information about this assembly is defined by the following attributes. 6 | // Change them to the values specific to your project. 7 | 8 | [assembly: AssemblyTitle ("OpenGLDemo.Droid")] 9 | [assembly: AssemblyDescription ("")] 10 | [assembly: AssemblyConfiguration ("")] 11 | [assembly: AssemblyCompany ("")] 12 | [assembly: AssemblyProduct ("")] 13 | [assembly: AssemblyCopyright ("burfies1")] 14 | [assembly: AssemblyTrademark ("")] 15 | [assembly: AssemblyCulture ("")] 16 | 17 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 18 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 19 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 20 | 21 | [assembly: AssemblyVersion ("1.0.0")] 22 | 23 | // The following attributes are used to specify the signing key for the assembly, 24 | // if desired. See the Mono documentation for more information about signing. 25 | 26 | //[assembly: AssemblyDelaySign(false)] 27 | //[assembly: AssemblyKeyFile("")] 28 | 29 | -------------------------------------------------------------------------------- /Droid/Resources/AboutResources.txt: -------------------------------------------------------------------------------- 1 | Images, layout descriptions, binary blobs and string dictionaries can be included 2 | in your application as resource files. Various Android APIs are designed to 3 | operate on the resource IDs instead of dealing with images, strings or binary blobs 4 | directly. 5 | 6 | For example, a sample Android app that contains a user interface layout (main.axml), 7 | an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) 8 | would keep its resources in the "Resources" directory of the application: 9 | 10 | Resources/ 11 | drawable/ 12 | icon.png 13 | 14 | layout/ 15 | main.axml 16 | 17 | values/ 18 | strings.xml 19 | 20 | In order to get the build system to recognize Android resources, set the build action to 21 | "AndroidResource". The native Android APIs do not operate directly with filenames, but 22 | instead operate on resource IDs. When you compile an Android application that uses resources, 23 | the build system will package the resources for distribution and generate a class called "R" 24 | (this is an Android convention) that contains the tokens for each one of the resources 25 | included. For example, for the above Resources layout, this is what the R class would expose: 26 | 27 | public class R { 28 | public class drawable { 29 | public const int icon = 0x123; 30 | } 31 | 32 | public class layout { 33 | public const int main = 0x456; 34 | } 35 | 36 | public class strings { 37 | public const int first_string = 0xabc; 38 | public const int second_string = 0xbcd; 39 | } 40 | } 41 | 42 | You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main 43 | to reference the layout/main.axml file, or R.strings.first_string to reference the first 44 | string in the dictionary file values/strings.xml. 45 | -------------------------------------------------------------------------------- /Droid/Resources/Resource.designer.cs: -------------------------------------------------------------------------------- 1 | #pragma warning disable 1591 2 | // ------------------------------------------------------------------------------ 3 | // 4 | // This code was generated by a tool. 5 | // Mono Runtime Version: 4.0.30319.17020 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | 12 | [assembly: Android.Runtime.ResourceDesignerAttribute("OpenGLDemo.Droid.Resource", IsApplication=true)] 13 | 14 | namespace OpenGLDemo.Droid 15 | { 16 | 17 | 18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] 19 | public partial class Resource 20 | { 21 | 22 | static Resource() 23 | { 24 | global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 25 | } 26 | 27 | public static void UpdateIdValues() 28 | { 29 | } 30 | 31 | public partial class Attribute 32 | { 33 | 34 | static Attribute() 35 | { 36 | global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 37 | } 38 | 39 | private Attribute() 40 | { 41 | } 42 | } 43 | 44 | public partial class Drawable 45 | { 46 | 47 | // aapt resource value: 0x7f020000 48 | public const int icon = 2130837504; 49 | 50 | // aapt resource value: 0x7f020001 51 | public const int mario = 2130837505; 52 | 53 | static Drawable() 54 | { 55 | global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 56 | } 57 | 58 | private Drawable() 59 | { 60 | } 61 | } 62 | } 63 | } 64 | #pragma warning restore 1591 65 | -------------------------------------------------------------------------------- /Droid/Resources/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/Droid/Resources/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /Droid/Resources/drawable-hdpi/mario.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/Droid/Resources/drawable-hdpi/mario.png -------------------------------------------------------------------------------- /Droid/Resources/drawable-xhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/Droid/Resources/drawable-xhdpi/icon.png -------------------------------------------------------------------------------- /Droid/Resources/drawable-xhdpi/mario.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/Droid/Resources/drawable-xhdpi/mario.png -------------------------------------------------------------------------------- /Droid/Resources/drawable-xxhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/Droid/Resources/drawable-xxhdpi/icon.png -------------------------------------------------------------------------------- /Droid/Resources/drawable-xxhdpi/mario.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/Droid/Resources/drawable-xxhdpi/mario.png -------------------------------------------------------------------------------- /Droid/Resources/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/Droid/Resources/drawable/icon.png -------------------------------------------------------------------------------- /Droid/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /OpenGLDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "OpenGLDemo", "OpenGLDemo\OpenGLDemo.shproj", "{B7DD8B60-20D3-4C2B-AFB6-3446B564B37C}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenGLDemo.iOS", "iOS\OpenGLDemo.iOS.csproj", "{0ED42D1C-B74C-4364-9881-F0EB96916FA5}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenGLDemo.Droid", "Droid\OpenGLDemo.Droid.csproj", "{5F037DD6-8F6E-4197-9909-C58C67CE5746}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenGLDemo.UITests", "UITests\OpenGLDemo.UITests.csproj", "{6C8F2694-BDE3-40EC-83DE-8D50006870CE}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|iPhoneSimulator = Debug|iPhoneSimulator 15 | Release|iPhone = Release|iPhone 16 | Release|iPhoneSimulator = Release|iPhoneSimulator 17 | Debug|iPhone = Debug|iPhone 18 | Debug|Any CPU = Debug|Any CPU 19 | Release|Any CPU = Release|Any CPU 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {0ED42D1C-B74C-4364-9881-F0EB96916FA5}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator 23 | {0ED42D1C-B74C-4364-9881-F0EB96916FA5}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator 24 | {0ED42D1C-B74C-4364-9881-F0EB96916FA5}.Debug|iPhone.ActiveCfg = Debug|iPhone 25 | {0ED42D1C-B74C-4364-9881-F0EB96916FA5}.Debug|iPhone.Build.0 = Debug|iPhone 26 | {0ED42D1C-B74C-4364-9881-F0EB96916FA5}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator 27 | {0ED42D1C-B74C-4364-9881-F0EB96916FA5}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator 28 | {0ED42D1C-B74C-4364-9881-F0EB96916FA5}.Release|Any CPU.ActiveCfg = Release|iPhone 29 | {0ED42D1C-B74C-4364-9881-F0EB96916FA5}.Release|Any CPU.Build.0 = Release|iPhone 30 | {0ED42D1C-B74C-4364-9881-F0EB96916FA5}.Release|iPhone.ActiveCfg = Release|iPhone 31 | {0ED42D1C-B74C-4364-9881-F0EB96916FA5}.Release|iPhone.Build.0 = Release|iPhone 32 | {0ED42D1C-B74C-4364-9881-F0EB96916FA5}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator 33 | {0ED42D1C-B74C-4364-9881-F0EB96916FA5}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator 34 | {5F037DD6-8F6E-4197-9909-C58C67CE5746}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {5F037DD6-8F6E-4197-9909-C58C67CE5746}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {5F037DD6-8F6E-4197-9909-C58C67CE5746}.Debug|iPhone.ActiveCfg = Debug|Any CPU 37 | {5F037DD6-8F6E-4197-9909-C58C67CE5746}.Debug|iPhone.Build.0 = Debug|Any CPU 38 | {5F037DD6-8F6E-4197-9909-C58C67CE5746}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU 39 | {5F037DD6-8F6E-4197-9909-C58C67CE5746}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU 40 | {5F037DD6-8F6E-4197-9909-C58C67CE5746}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {5F037DD6-8F6E-4197-9909-C58C67CE5746}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {5F037DD6-8F6E-4197-9909-C58C67CE5746}.Release|iPhone.ActiveCfg = Release|Any CPU 43 | {5F037DD6-8F6E-4197-9909-C58C67CE5746}.Release|iPhone.Build.0 = Release|Any CPU 44 | {5F037DD6-8F6E-4197-9909-C58C67CE5746}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU 45 | {5F037DD6-8F6E-4197-9909-C58C67CE5746}.Release|iPhoneSimulator.Build.0 = Release|Any CPU 46 | {6C8F2694-BDE3-40EC-83DE-8D50006870CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {6C8F2694-BDE3-40EC-83DE-8D50006870CE}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {6C8F2694-BDE3-40EC-83DE-8D50006870CE}.Debug|iPhone.ActiveCfg = Debug|Any CPU 49 | {6C8F2694-BDE3-40EC-83DE-8D50006870CE}.Debug|iPhone.Build.0 = Debug|Any CPU 50 | {6C8F2694-BDE3-40EC-83DE-8D50006870CE}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU 51 | {6C8F2694-BDE3-40EC-83DE-8D50006870CE}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU 52 | {6C8F2694-BDE3-40EC-83DE-8D50006870CE}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {6C8F2694-BDE3-40EC-83DE-8D50006870CE}.Release|Any CPU.Build.0 = Release|Any CPU 54 | {6C8F2694-BDE3-40EC-83DE-8D50006870CE}.Release|iPhone.ActiveCfg = Release|Any CPU 55 | {6C8F2694-BDE3-40EC-83DE-8D50006870CE}.Release|iPhone.Build.0 = Release|Any CPU 56 | {6C8F2694-BDE3-40EC-83DE-8D50006870CE}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU 57 | {6C8F2694-BDE3-40EC-83DE-8D50006870CE}.Release|iPhoneSimulator.Build.0 = Release|Any CPU 58 | EndGlobalSection 59 | EndGlobal 60 | -------------------------------------------------------------------------------- /OpenGLDemo.userprefs: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /OpenGLDemo/OpenGLCube.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using OpenTK; 3 | using Xamarin.Forms; 4 | using OpenTK.Graphics.ES20; 5 | using System.Text; 6 | using System.Threading; 7 | using System.Reflection; 8 | using System.Linq; 9 | using OpenGLDemo; 10 | using System.IO; 11 | using System.Drawing; 12 | 13 | 14 | #if __ANDROID__ 15 | using Android.Util; 16 | using Android.App; 17 | using Android.Opengl; 18 | using Android.Graphics; 19 | using Android; 20 | #elif __IOS__ 21 | using UIKit; 22 | using Foundation; 23 | using CoreGraphics; 24 | #endif 25 | 26 | namespace OpenGLDemo 27 | { 28 | public class myReferenceTime2 29 | { 30 | private myReferenceTime2() 31 | { 32 | } 33 | 34 | static DateTime reference_time; 35 | static bool reference_time_set = false; 36 | 37 | public static double GetTimeFromReferenceMs() 38 | { 39 | if (!reference_time_set) 40 | { 41 | reference_time = DateTime.Now; 42 | reference_time_set = true; 43 | return 0.0; 44 | } 45 | DateTime actual_time = DateTime.Now; 46 | TimeSpan ts = new TimeSpan(actual_time.Ticks - reference_time.Ticks); 47 | return ts.TotalMilliseconds; 48 | } 49 | 50 | } 51 | 52 | public class App2 : Xamarin.Forms.Application 53 | { 54 | 55 | public App2 () 56 | { 57 | MainPage = new OpenGlTutoTextured { }; // your page here 58 | } 59 | } 60 | 61 | public class OpenGlTutoTextured : ContentPage 62 | { 63 | bool init_gl_done = false; 64 | 65 | private bool focus = false; 66 | private bool hidden_by_menu = false; 67 | 68 | int viewportWidth; 69 | int viewportHeight; 70 | 71 | int texture_handle = -1; 72 | int texture_sampler_handle = -1; 73 | 74 | // Vector4 to use quaternions 75 | Vector4 [] vertices; 76 | 77 | // Set color with red, green, blue and alpha (opacity) values 78 | Vector2 [] texture_coordinates; 79 | 80 | int mProgramHandle; 81 | int mTextureCoordinatesHandle; 82 | int mPositionHandle; 83 | int mMVPMatrixHandle; 84 | 85 | Matrix4 mProjectionMatrix; 86 | Matrix4 mViewMatrix; 87 | Matrix4 mModelViewProjectionMatrix; 88 | 89 | OpenGLView my3DView = null; 90 | 91 | public OpenGlTutoTextured() 92 | { 93 | Title = "Test"; 94 | 95 | my3DView = new OpenGLView 96 | { 97 | HeightRequest = 300, 98 | WidthRequest = 300, 99 | HasRenderLoop = true 100 | }; 101 | 102 | my3DView.OnDisplay = r => 103 | { 104 | // while ((!focus) || (hidden_by_menu)) 105 | // { 106 | // Thread.Sleep (500); 107 | // } 108 | 109 | if (!init_gl_done) 110 | { 111 | // get 3D view dimensions in pixels 112 | #if __ANDROID__ 113 | // get 3D view dimensions in pixels 114 | double width_in_pixels = TypedValue.ApplyDimension(ComplexUnitType.Dip, (float) my3DView.Width, Xamarin.Forms.Forms.Context.Resources.DisplayMetrics); 115 | double height_in_pixels = TypedValue.ApplyDimension(ComplexUnitType.Dip, (float) my3DView.Height, Xamarin.Forms.Forms.Context.Resources.DisplayMetrics); 116 | #elif __IOS__ 117 | 118 | double width_in_pixels = 300; 119 | double height_in_pixels = 300; 120 | 121 | #endif 122 | InitGl((int) width_in_pixels, (int) height_in_pixels); 123 | } 124 | 125 | Render (); 126 | }; 127 | 128 | var stack = new StackLayout 129 | { 130 | Padding = new Xamarin.Forms.Size (20, 20), 131 | Children = {my3DView} 132 | }; 133 | 134 | Content = stack; 135 | } 136 | 137 | void InitGl(int width, int height) 138 | { 139 | viewportHeight = width; 140 | viewportWidth = height; 141 | 142 | // Set our triangle's vertices 143 | vertices = new Vector4 [] 144 | { 145 | new Vector4(-0.5f, 0.5f, 0.0f, 1.0f), 146 | new Vector4( 0.5f, 0.5f, 0.0f, 1.0f), 147 | new Vector4(-0.5f, -0.5f, 0.0f, 1.0f), 148 | 149 | new Vector4( 0.5f, 0.5f, 0.0f, 1.0f), 150 | new Vector4( 0.5f, -0.5f, 0.0f, 1.0f), 151 | new Vector4(-0.5f, -0.5f, 0.0f, 1.0f) 152 | }; 153 | 154 | // Set texture coordinates 155 | texture_coordinates = new Vector2 [] 156 | { 157 | new Vector2(0.0f, 0.0f), 158 | new Vector2(1.0f, 0.0f), 159 | new Vector2(0.0f, 1.0f), 160 | 161 | new Vector2(1.0f, 0.0f), 162 | new Vector2(1.0f, 1.0f), 163 | new Vector2(0.0f, 1.0f) 164 | }; 165 | 166 | // Vertex shader 167 | string vertexShaderSrc = @" 168 | uniform mat4 uMVPMatrix; 169 | attribute vec2 vTextureCoordinates; 170 | attribute vec4 vPosition; 171 | varying vec2 varyingTextureCoordinates; 172 | 173 | void main() 174 | { 175 | varyingTextureCoordinates = vTextureCoordinates; 176 | gl_Position = uMVPMatrix * vPosition; 177 | }"; 178 | 179 | 180 | // Fragment shader 181 | string fragmentShaderSrc = @" 182 | 183 | varying lowp vec2 varyingTextureCoordinates; 184 | uniform sampler2D texture_sampler; 185 | 186 | void main (void) 187 | { 188 | gl_FragColor = texture2D(texture_sampler, varyingTextureCoordinates); 189 | } 190 | "; 191 | 192 | int vertexShader = LoadShader (ShaderType.VertexShader, vertexShaderSrc ); 193 | int fragmentShader = LoadShader (ShaderType.FragmentShader, fragmentShaderSrc ); 194 | mProgramHandle = GL.CreateProgram(); 195 | if (mProgramHandle == 0) 196 | throw new InvalidOperationException ("Unable to create program"); 197 | 198 | GL.AttachShader (mProgramHandle, vertexShader); 199 | GL.AttachShader (mProgramHandle, fragmentShader); 200 | 201 | GL.BindAttribLocation (mProgramHandle, 0, "vPosition"); 202 | GL.LinkProgram (mProgramHandle); 203 | 204 | GL.Viewport(0, 0, viewportWidth, viewportHeight); 205 | 206 | // Add program to OpenGL environment 207 | GL.UseProgram (mProgramHandle); 208 | 209 | texture_handle = LoadTexture("mario", 1, true, false); 210 | texture_sampler_handle = GL.GetUniformLocation(mProgramHandle, "texture_sampler"); 211 | 212 | init_gl_done = true; 213 | } 214 | 215 | public static int LoadShader (ShaderType type, string shader_source) 216 | { 217 | int shader = GL.CreateShader (type); 218 | if (shader == 0) 219 | { 220 | throw new InvalidOperationException ("Unable to create shader"); 221 | } 222 | 223 | int length = 0; 224 | GL.ShaderSource (shader, 1, new string [] {shader_source}, (int[]) null); 225 | GL.CompileShader (shader); 226 | 227 | int compiled = 0; 228 | GL.GetShader (shader, ShaderParameter.CompileStatus, out compiled); 229 | if (compiled == 0) 230 | { 231 | length = 0; 232 | GL.GetShader (shader, ShaderParameter.InfoLogLength, out length); 233 | if (length > 0) 234 | { 235 | StringBuilder log = new StringBuilder(length); 236 | GL.GetShaderInfoLog (shader, length, out length, log); 237 | 238 | throw new InvalidOperationException ("GL2 : Couldn't compile shader: " + log.ToString ()); 239 | } 240 | 241 | GL.DeleteShader (shader); 242 | throw new InvalidOperationException ("Unable to compile shader of type : " + type.ToString ()); 243 | } 244 | 245 | return shader; 246 | } 247 | 248 | // see https://github.com/Clancey/Canvas/blob/master/Xamarin.Canvas.Android/Extension.cs 249 | // int id = GetId (typeof(Resource.Drawable), name); 250 | static int GetId (Type type, string propertyName) 251 | { 252 | FieldInfo[] props = type.GetFields (); 253 | FieldInfo prop = props.Select (p => p).Where (p => p.Name == propertyName).FirstOrDefault (); 254 | if (prop != null) 255 | { 256 | return (int)prop.GetValue(type); 257 | } 258 | return -1; 259 | } 260 | 261 | // see http://deathbyalgorithm.blogspot.fr/2013/05/opentk-textures.html 262 | public static int LoadTexture(string name, int quality, bool repeat, bool flip_y) 263 | { 264 | 265 | string prefix; 266 | 267 | #if __IOS__ 268 | prefix = "OpenGLDemo.iOS."; 269 | #endif 270 | #if __ANDROID__ 271 | prefix = "OpenGLDemo.Droid."; 272 | #endif 273 | 274 | var assembly = typeof(App2).GetTypeInfo ().Assembly; 275 | 276 | // foreach (var res in assembly.GetManifestResourceNames()) 277 | // System.Diagnostics.Debug.WriteLine("found resource: " + res); 278 | 279 | Stream stream = assembly.GetManifestResourceStream (prefix + name + ".png"); 280 | byte[] imageData; 281 | 282 | using (MemoryStream ms = new MemoryStream()) 283 | { 284 | stream.CopyTo(ms); 285 | imageData = ms.ToArray(); 286 | } 287 | 288 | #if __ANDROID__ 289 | 290 | Bitmap b = BitmapFactory.DecodeByteArray (imageData, 0, imageData.Length); 291 | 292 | #elif __IOS__ 293 | 294 | UIImage image = ImageFromByteArray (imageData); 295 | int width = (int)image.CGImage.Width; 296 | int height = (int)image.CGImage.Height; 297 | 298 | CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB (); 299 | byte[] imageData2 = new byte[height * width * 4]; 300 | CGContext context = new CGBitmapContext (imageData2, width, height, 8, 4 * width, colorSpace, 301 | CGBitmapFlags.PremultipliedLast | CGBitmapFlags.ByteOrder32Big); 302 | 303 | colorSpace.Dispose (); 304 | context.ClearRect (new RectangleF (0, 0, width, height)); 305 | context.DrawImage (new RectangleF (0, 0, width, height), image.CGImage); 306 | 307 | #endif 308 | 309 | int [] textures = new int[1]; 310 | 311 | //Generate a new texture target in gl 312 | GL.GenTextures(1, textures); 313 | 314 | //Will bind the texture newly/empty created with GL.GenTexture 315 | //All gl texture methods targeting Texture2D will relate to this texture 316 | GL.BindTexture(TextureTarget.Texture2D, textures[0]); 317 | 318 | //The reason why your texture will show up glColor without setting these parameters is actually 319 | //TextureMinFilters fault as its default is NearestMipmapLinear but we have not established mipmapping 320 | //We are only using one texture at the moment since mipmapping is a collection of textures pre filtered 321 | //I'm assuming it stops after not having a collection to check. 322 | switch (quality) 323 | { 324 | case 1://High quality 325 | GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) All.Linear); 326 | GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) All.Linear); 327 | break; 328 | //case 0: 329 | default://Low quality 330 | GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) All.Nearest); 331 | GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) All.Nearest); 332 | break; 333 | } 334 | 335 | if (repeat) 336 | { 337 | //This will repeat the texture past its bounds set by TexImage2D 338 | GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int) All.Repeat); 339 | GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int) All.Repeat); 340 | } 341 | else 342 | { 343 | //This will clamp the texture to the edge, so manipulation will result in skewing 344 | //It can also be useful for getting rid of repeating texture bits at the borders 345 | GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int) All.ClampToEdge); 346 | GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int) All.ClampToEdge); 347 | } 348 | 349 | #if __ANDROID__ 350 | GLUtils.TexImage2D ((int) All.Texture2D, 0, b, 0); 351 | b.Recycle(); 352 | #elif __IOS__ 353 | GL.TexImage2D (TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, imageData2); 354 | #endif 355 | 356 | GL.BindTexture(TextureTarget.Texture2D, 0); 357 | 358 | return textures[0]; 359 | } 360 | 361 | // see http://www.opentk.com/node/2559 362 | public static void BindTexture(int textureId, TextureUnit textureUnit, int UniformId) 363 | { 364 | GL.ActiveTexture(textureUnit); 365 | GL.BindTexture(TextureTarget.Texture2D, textureId); 366 | GL.Uniform1(UniformId, textureUnit - TextureUnit.Texture0); 367 | } 368 | 369 | public static void UniformMatrix4(int location, Matrix4 value) 370 | { 371 | GL.UniformMatrix4(location, 1, false, ref value.Row0.X); 372 | } 373 | 374 | void Render () 375 | { 376 | GL.UseProgram (mProgramHandle); 377 | 378 | GL.ClearColor (0.7f, 0.7f, 0.7f, 1); 379 | GL.Clear (ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); 380 | 381 | float aspectRatio = ((float) Width) / ((float) Height); 382 | 383 | float ratio = ((float) viewportWidth) / ((float) viewportHeight); 384 | 385 | BindTexture(texture_handle, TextureUnit.Texture0, texture_sampler_handle); 386 | 387 | mProjectionMatrix = Matrix4.CreateOrthographicOffCenter(-ratio, ratio, -1, 1, 0.1f, 10.0f); 388 | 389 | // Set the camera position (View matrix) 390 | mViewMatrix = Matrix4.LookAt(new Vector3(0, 0, 5), new Vector3(0, 0, 0), new Vector3(0, 1, 0)); 391 | 392 | // Calculate the projection and view transformation 393 | mModelViewProjectionMatrix = Matrix4.Mult(mViewMatrix, mProjectionMatrix); 394 | 395 | Matrix4 mModel = Matrix4.CreateRotationY((float) (Math.PI * 2.0 * myReferenceTime2.GetTimeFromReferenceMs() / 5000.0)); 396 | 397 | mModelViewProjectionMatrix = Matrix4.Mult(mModelViewProjectionMatrix, mModel); 398 | 399 | // get handle to vertex shader's vPosition member 400 | mPositionHandle = GL.GetAttribLocation(mProgramHandle, "vPosition"); 401 | 402 | // get handle to vertex shader's vTextureCoordinates member 403 | mTextureCoordinatesHandle = GL.GetAttribLocation(mProgramHandle, "vTextureCoordinates"); 404 | 405 | // Enable a handle to the triangle vertices 406 | GL.EnableVertexAttribArray (mPositionHandle); 407 | 408 | // Enable a handle to the triangle colors 409 | GL.EnableVertexAttribArray (mTextureCoordinatesHandle); 410 | 411 | unsafe 412 | { 413 | fixed (Vector4* pvertices = vertices) 414 | { 415 | // Prepare the triangle coordinate data 416 | GL.VertexAttribPointer (mPositionHandle, Vector4.SizeInBytes / 4, VertexAttribPointerType.Float, false, 0, new IntPtr (pvertices)); 417 | } 418 | 419 | fixed (Vector2* ptexturecoordinates = texture_coordinates) 420 | { 421 | // Prepare the triangle color data 422 | GL.VertexAttribPointer (mTextureCoordinatesHandle, Vector2.SizeInBytes / 4, VertexAttribPointerType.Float, false, 0, new IntPtr (ptexturecoordinates)); 423 | } 424 | } 425 | 426 | // get handle to shape's transformation matrix 427 | mMVPMatrixHandle = GL.GetUniformLocation(mProgramHandle, "uMVPMatrix"); 428 | 429 | // Apply the projection and view transformation 430 | UniformMatrix4 (mMVPMatrixHandle, mModelViewProjectionMatrix); 431 | 432 | GL.DrawArrays (BeginMode.Triangles, 0, vertices.Length); 433 | 434 | GL.Finish (); 435 | 436 | // Disable vertex array 437 | GL.DisableVertexAttribArray(mPositionHandle); 438 | 439 | // Disable color array 440 | GL.DisableVertexAttribArray(mTextureCoordinatesHandle); 441 | } 442 | 443 | public void FocusChangeTo(bool new_focus) 444 | { 445 | if (new_focus != focus) 446 | { 447 | if (new_focus) 448 | { 449 | // do stuffs here 450 | focus = true; 451 | } 452 | else 453 | { 454 | focus = false; 455 | 456 | // do stuffs here 457 | } 458 | } 459 | } 460 | 461 | public void FocusHiddenByMenyTo(bool new_hidden_by_menu) 462 | { 463 | if (new_hidden_by_menu != hidden_by_menu) 464 | { 465 | if (new_hidden_by_menu) 466 | { 467 | // do stuffs here 468 | hidden_by_menu = true; 469 | } 470 | else 471 | { 472 | hidden_by_menu = false; 473 | // do stuffs here 474 | } 475 | } 476 | } 477 | 478 | #if __IOS__ 479 | public static UIKit.UIImage ImageFromByteArray(byte[] data) 480 | { 481 | if (data == null) { 482 | return null; 483 | } 484 | 485 | UIKit.UIImage image; 486 | try { 487 | image = new UIKit.UIImage(Foundation.NSData.FromArray(data)); 488 | } catch (Exception e) { 489 | Console.WriteLine ("Image load failed: " + e.Message); 490 | return null; 491 | } 492 | return image; 493 | } 494 | #endif 495 | } 496 | } 497 | 498 | -------------------------------------------------------------------------------- /OpenGLDemo/OpenGLDemo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using OpenTK; 3 | using Xamarin.Forms; 4 | using OpenTK.Graphics.ES20; 5 | using System.Text; 6 | using System.Reflection; 7 | using System.IO; 8 | 9 | #if __ANDROID__ 10 | using Android.Util; 11 | using Android.App; 12 | #endif 13 | 14 | // based on Xamarin triangle ES20 demo 15 | namespace OpenGLDemo 16 | { 17 | public class myReferenceTime 18 | { 19 | private myReferenceTime() 20 | { 21 | } 22 | 23 | static DateTime reference_time; 24 | static bool reference_time_set = false; 25 | 26 | public static double GetTimeFromReferenceMs() 27 | { 28 | if (!reference_time_set) 29 | { 30 | reference_time = DateTime.Now; 31 | reference_time_set = true; 32 | return 0.0; 33 | } 34 | DateTime actual_time = DateTime.Now; 35 | TimeSpan ts = new TimeSpan(actual_time.Ticks - reference_time.Ticks); 36 | return ts.TotalMilliseconds; 37 | } 38 | 39 | } 40 | 41 | public class App : Xamarin.Forms.Application 42 | { 43 | 44 | public App () 45 | { 46 | MainPage = new OpenGlTuto { }; // your page here 47 | } 48 | } 49 | 50 | public class OpenGlTuto : ContentPage 51 | { 52 | bool init_gl_done = false; 53 | 54 | int viewportWidth; 55 | int viewportHeight; 56 | 57 | // Vector4 to use quaternions 58 | Vector4 [] vertices; 59 | 60 | // Set color with red, green, blue and alpha (opacity) values 61 | Vector4 [] colors; 62 | 63 | uint mProgramHandle; 64 | int mColorHandle; 65 | int mPositionHandle; 66 | int mMVPMatrixHandle; 67 | 68 | Matrix4 mProjectionMatrix; 69 | Matrix4 mViewMatrix; 70 | Matrix4 mModelViewProjectionMatrix; 71 | 72 | OpenGLView my3DView = null; 73 | 74 | public OpenGlTuto() 75 | { 76 | Title = "Test"; 77 | 78 | my3DView = new OpenGLView 79 | { 80 | HeightRequest = 300, 81 | WidthRequest = 300, 82 | HasRenderLoop = true 83 | }; 84 | 85 | my3DView.OnDisplay = r => 86 | { 87 | if (!init_gl_done) 88 | { 89 | #if __ANDROID__ 90 | // get 3D view dimensions in pixels 91 | double width_in_pixels = TypedValue.ApplyDimension(ComplexUnitType.Dip, (float) my3DView.Width, Xamarin.Forms.Forms.Context.Resources.DisplayMetrics); 92 | double height_in_pixels = TypedValue.ApplyDimension(ComplexUnitType.Dip, (float) my3DView.Height, Xamarin.Forms.Forms.Context.Resources.DisplayMetrics); 93 | #elif __IOS__ 94 | 95 | double width_in_pixels = 300; 96 | double height_in_pixels = 300; 97 | 98 | #endif 99 | InitGl((int) width_in_pixels, (int) height_in_pixels); 100 | } 101 | 102 | Render (); 103 | }; 104 | 105 | var stack = new StackLayout 106 | { 107 | Padding = new Xamarin.Forms.Size (20, 20), 108 | Children = {my3DView} 109 | }; 110 | 111 | Content = stack; 112 | } 113 | 114 | void InitGl(int width, int height) 115 | { 116 | viewportHeight = width; 117 | viewportWidth = height; 118 | 119 | // Set our triangle's vertices 120 | vertices = new Vector4 [] 121 | { 122 | new Vector4(0.0f, 0.5f, 0.0f, 1.0f), 123 | new Vector4(0.5f, -0.5f, 0.0f, 1.0f), 124 | new Vector4(-0.5f, -0.5f, 0.0f, 1.0f) 125 | }; 126 | 127 | // Set color with red, green, blue and alpha (opacity) values 128 | colors = new Vector4 [] 129 | { 130 | new Vector4(1.0f, 0.0f, 0.0f, 1.0f), 131 | new Vector4(0.0f, 1.0f, 0.0f, 1.0f), 132 | new Vector4(0.0f, 0.0f, 1.0f, 1.0f) 133 | }; 134 | 135 | uint vertexShader = CompileShader ("Vertex", ShaderType.VertexShader); 136 | uint fragmentShader = CompileShader ("Fragment", ShaderType.FragmentShader); 137 | 138 | mProgramHandle = (uint)GL.CreateProgram(); 139 | if (mProgramHandle == 0) 140 | throw new InvalidOperationException ("Unable to create program"); 141 | 142 | GL.AttachShader (mProgramHandle, vertexShader); 143 | GL.AttachShader (mProgramHandle, fragmentShader); 144 | 145 | GL.BindAttribLocation (mProgramHandle, 0, "vPosition"); 146 | GL.LinkProgram (mProgramHandle); 147 | 148 | GL.Viewport(0, 0, viewportWidth, viewportHeight); 149 | 150 | // Add program to OpenGL environment 151 | GL.UseProgram (mProgramHandle); 152 | 153 | init_gl_done = true; 154 | } 155 | 156 | public static uint CompileShader(string shaderName, ShaderType shaderType){ 157 | string prefix; 158 | 159 | #if __IOS__ 160 | prefix = "OpenGLDemo.iOS.Shaders."; 161 | #endif 162 | #if __ANDROID__ 163 | prefix = "OpenGLDemo.Droid.Shaders."; 164 | #endif 165 | 166 | var assembly = typeof(App).GetTypeInfo ().Assembly; 167 | 168 | foreach (var res in assembly.GetManifestResourceNames()) 169 | System.Diagnostics.Debug.WriteLine("found resource: " + res); 170 | 171 | Stream stream = assembly.GetManifestResourceStream (prefix + shaderName + ".glsl"); 172 | 173 | string shaderString; 174 | 175 | using (var reader = new StreamReader (stream)) { 176 | shaderString = reader.ReadToEnd (); 177 | } 178 | 179 | uint shaderHandle = (uint)GL.CreateShader (shaderType); 180 | GL.ShaderSource ((int)shaderHandle, shaderString); 181 | GL.CompileShader (shaderHandle); 182 | 183 | return shaderHandle; 184 | } 185 | 186 | public static void UniformMatrix4(int location, Matrix4 value) 187 | { 188 | GL.UniformMatrix4(location, 1, false, ref value.Row0.X); 189 | } 190 | 191 | void Render () 192 | { 193 | GL.UseProgram (mProgramHandle); 194 | 195 | GL.ClearColor (0.7f, 0.7f, 0.7f, 1); 196 | GL.Clear (ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); 197 | 198 | float aspectRatio = ((float) Width) / ((float) Height); 199 | 200 | float ratio = ((float) viewportWidth) / ((float) viewportHeight); 201 | 202 | mProjectionMatrix = Matrix4.CreateOrthographicOffCenter(-ratio, ratio, -1, 1, 0.1f, 10.0f); 203 | 204 | // Set the camera position (View matrix) 205 | mViewMatrix = Matrix4.LookAt(new Vector3(0, 0, 5), new Vector3(0, 0, 0), new Vector3(0, 1, 0)); 206 | 207 | // Calculate the projection and view transformation 208 | mModelViewProjectionMatrix = Matrix4.Mult(mViewMatrix, mProjectionMatrix); 209 | 210 | Matrix4 mModel = Matrix4.CreateRotationY((float) (Math.PI * 2.0 * myReferenceTime.GetTimeFromReferenceMs() / 5000.0)); 211 | 212 | mModelViewProjectionMatrix = Matrix4.Mult(mModelViewProjectionMatrix, mModel); 213 | 214 | // get handle to vertex shader's vPosition member 215 | mPositionHandle = GL.GetAttribLocation(mProgramHandle, "vPosition"); 216 | 217 | // get handle to vertex shader's vColor member 218 | mColorHandle = GL.GetAttribLocation(mProgramHandle, "vColor"); 219 | 220 | // Enable a handle to the triangle vertices 221 | GL.EnableVertexAttribArray (mPositionHandle); 222 | 223 | // Enable a handle to the triangle colors 224 | GL.EnableVertexAttribArray (mColorHandle); 225 | 226 | unsafe 227 | { 228 | fixed (Vector4* pvertices = vertices) 229 | { 230 | // Prepare the triangle coordinate data 231 | GL.VertexAttribPointer (mPositionHandle, Vector4.SizeInBytes / 4, VertexAttribPointerType.Float, false, 0, new IntPtr (pvertices)); 232 | } 233 | 234 | fixed (Vector4* pcolors = colors) 235 | { 236 | // Prepare the triangle color data 237 | GL.VertexAttribPointer (mColorHandle, Vector4.SizeInBytes / 4, VertexAttribPointerType.Float, false, 0, new IntPtr (pcolors)); 238 | } 239 | } 240 | 241 | // get handle to shape's transformation matrix 242 | mMVPMatrixHandle = GL.GetUniformLocation(mProgramHandle, "uMVPMatrix"); 243 | 244 | // Apply the projection and view transformation 245 | UniformMatrix4 (mMVPMatrixHandle, mModelViewProjectionMatrix); 246 | 247 | GL.DrawArrays (BeginMode.Triangles, 0, 3); 248 | 249 | GL.Finish (); 250 | 251 | // Disable vertex array 252 | GL.DisableVertexAttribArray(mPositionHandle); 253 | 254 | // Disable color array 255 | GL.DisableVertexAttribArray (mColorHandle); 256 | } 257 | } 258 | 259 | } 260 | 261 | -------------------------------------------------------------------------------- /OpenGLDemo/OpenGLDemo.projitems: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | {B7DD8B60-20D3-4C2B-AFB6-3446B564B37C} 7 | 8 | 9 | OpenGLDemo 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /OpenGLDemo/OpenGLDemo.shproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {B7DD8B60-20D3-4C2B-AFB6-3446B564B37C} 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /OpenGLDemo/Shaders/Fragment.glsl: -------------------------------------------------------------------------------- 1 | varying lowp vec4 color; 2 | void main (void) 3 | { 4 | gl_FragColor = color; 5 | } 6 | -------------------------------------------------------------------------------- /OpenGLDemo/Shaders/SimpleFragment.glsl: -------------------------------------------------------------------------------- 1 | varying lowp vec4 DestinationColor; 2 | 3 | void main(void) { 4 | gl_FragColor = DestinationColor; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /OpenGLDemo/Shaders/SimpleVertex.glsl: -------------------------------------------------------------------------------- 1 | attribute vec4 Position; 2 | attribute vec4 SourceColor; 3 | 4 | varying vec4 DestinationColor; 5 | 6 | uniform mat4 Projection; 7 | uniform mat4 Modelview; 8 | 9 | void main(void) { 10 | DestinationColor = SourceColor; 11 | gl_Position = Projection * Modelview * Position; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /OpenGLDemo/Shaders/Vertex.glsl: -------------------------------------------------------------------------------- 1 | uniform mat4 uMVPMatrix; 2 | attribute vec4 vColor; 3 | attribute vec4 vPosition; 4 | varying vec4 color; 5 | void main() 6 | { 7 | color = vColor; 8 | gl_Position = uMVPMatrix * vPosition; 9 | } -------------------------------------------------------------------------------- /OpenGLDemo/mario.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/OpenGLDemo/mario.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenGLXamarin 2 | Here is an example of Xamarin Forms and OpenGLView. This works for iOS and Android. 3 | 4 | Built using Xamarin Studio for Mac -------------------------------------------------------------------------------- /UITests/AppInitializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using Xamarin.UITest; 5 | using Xamarin.UITest.Queries; 6 | 7 | namespace OpenGLDemo.UITests 8 | { 9 | public class AppInitializer 10 | { 11 | public static IApp StartApp (Platform platform) 12 | { 13 | if (platform == Platform.Android) { 14 | return ConfigureApp.Android.StartApp (); 15 | } 16 | 17 | return ConfigureApp.iOS.StartApp (); 18 | } 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /UITests/OpenGLDemo.UITests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {6C8F2694-BDE3-40EC-83DE-8D50006870CE} 7 | Library 8 | OpenGLDemo.UITests 9 | OpenGLDemo.UITests 10 | v4.5 11 | 12 | 13 | true 14 | full 15 | false 16 | bin\Debug 17 | DEBUG; 18 | prompt 19 | 4 20 | false 21 | 22 | 23 | full 24 | true 25 | bin\Release 26 | prompt 27 | 4 28 | false 29 | 30 | 31 | 32 | 33 | ..\packages\NUnit.2.6.3\lib\nunit.framework.dll 34 | 35 | 36 | ..\packages\Xamarin.UITest.0.7.1\lib\Xamarin.UITest.dll 37 | 38 | 39 | 40 | 41 | {0ED42D1C-B74C-4364-9881-F0EB96916FA5} 42 | OpenGLDemo.iOS 43 | False 44 | False 45 | 46 | 47 | {5F037DD6-8F6E-4197-9909-C58C67CE5746} 48 | OpenGLDemo.Droid 49 | False 50 | False 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /UITests/Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using NUnit.Framework; 5 | using Xamarin.UITest; 6 | using Xamarin.UITest.Queries; 7 | 8 | namespace OpenGLDemo.UITests 9 | { 10 | [TestFixture (Platform.Android)] 11 | [TestFixture (Platform.iOS)] 12 | public class Tests 13 | { 14 | IApp app; 15 | Platform platform; 16 | 17 | public Tests (Platform platform) 18 | { 19 | this.platform = platform; 20 | } 21 | 22 | [SetUp] 23 | public void BeforeEachTest () 24 | { 25 | app = AppInitializer.StartApp (platform); 26 | } 27 | 28 | [Test] 29 | public void WelcomeTextIsDisplayed () 30 | { 31 | AppResult[] results = app.WaitForElement (c => c.Marked ("Welcome to Xamarin Forms!")); 32 | app.Screenshot ("Welcome screen."); 33 | 34 | Assert.IsTrue (results.Any ()); 35 | } 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /UITests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /iOS/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | using Foundation; 6 | using UIKit; 7 | 8 | namespace OpenGLDemo.iOS 9 | { 10 | [Register ("AppDelegate")] 11 | public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate 12 | { 13 | public override bool FinishedLaunching (UIApplication app, NSDictionary options) 14 | { 15 | global::Xamarin.Forms.Forms.Init (); 16 | 17 | // Code for starting up the Xamarin Test Cloud Agent 18 | #if ENABLE_TEST_CLOUD 19 | Xamarin.Calabash.Start(); 20 | #endif 21 | 22 | LoadApplication (new App2 ()); 23 | 24 | return base.FinishedLaunching (app, options); 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /iOS/Entitlements.plist: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /iOS/ITunesArtwork: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/ITunesArtwork -------------------------------------------------------------------------------- /iOS/ITunesArtwork@2x: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/ITunesArtwork@2x -------------------------------------------------------------------------------- /iOS/Info.plist: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | CFBundleDisplayName 6 | OpenGLDemo 7 | CFBundleIdentifier 8 | com.BurfDevelopment.opengldemo 9 | CFBundleShortVersionString 10 | 1.0 11 | CFBundleVersion 12 | 1.0 13 | LSRequiresIPhoneOS 14 | 15 | MinimumOSVersion 16 | 7.0 17 | UIDeviceFamily 18 | 19 | 1 20 | 2 21 | 22 | UIRequiredDeviceCapabilities 23 | 24 | armv7 25 | 26 | UISupportedInterfaceOrientations 27 | 28 | UIInterfaceOrientationPortrait 29 | UIInterfaceOrientationLandscapeLeft 30 | UIInterfaceOrientationLandscapeRight 31 | 32 | UISupportedInterfaceOrientations~ipad 33 | 34 | UIInterfaceOrientationPortrait 35 | UIInterfaceOrientationPortraitUpsideDown 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | CFBundleIconFiles 40 | 41 | Icon-60@2x 42 | Icon-60@3x 43 | Icon-76 44 | Icon-76@2x 45 | Default 46 | Default@2x 47 | Default-568h 48 | Default-568h@2x 49 | Default-Landscape 50 | Default-Landscape@2x 51 | Default-Portrait 52 | Default-Portrait@2x 53 | Icon-Small-40 54 | Icon-Small-40@2x 55 | Icon-Small-40@3x 56 | Icon-Small 57 | Icon-Small@2x 58 | Icon-Small@3x 59 | 60 | UILaunchStoryboardName 61 | LaunchScreen 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /iOS/Main.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | using Foundation; 6 | using UIKit; 7 | 8 | namespace OpenGLDemo.iOS 9 | { 10 | public class Application 11 | { 12 | // This is the main entry point of the application. 13 | static void Main (string[] args) 14 | { 15 | // if you want to use a different Application Delegate class from "AppDelegate" 16 | // you can specify it here. 17 | UIApplication.Main (args, null, "AppDelegate"); 18 | } 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /iOS/OpenGLDemo.iOS.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | iPhoneSimulator 6 | {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 7 | {0ED42D1C-B74C-4364-9881-F0EB96916FA5} 8 | Exe 9 | OpenGLDemo.iOS 10 | Resources 11 | OpenGLDemo.iOS 12 | 13 | 14 | true 15 | full 16 | false 17 | bin\iPhoneSimulator\Debug 18 | DEBUG;ENABLE_TEST_CLOUD; 19 | prompt 20 | 4 21 | false 22 | i386 23 | None 24 | true 25 | true 26 | true 27 | 28 | 29 | full 30 | true 31 | bin\iPhone\Release 32 | prompt 33 | 4 34 | Entitlements.plist 35 | ARMv7, ARM64 36 | false 37 | iPhone Developer 38 | true 39 | 40 | 41 | full 42 | true 43 | bin\iPhoneSimulator\Release 44 | prompt 45 | 4 46 | i386 47 | false 48 | None 49 | true 50 | 51 | 52 | true 53 | full 54 | false 55 | bin\iPhone\Debug 56 | DEBUG;ENABLE_TEST_CLOUD; 57 | prompt 58 | 4 59 | false 60 | ARMv7, ARM64 61 | Entitlements.plist 62 | true 63 | iPhone Developer 64 | true 65 | true 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | ..\packages\Xamarin.TestCloud.Agent.0.13.0\lib\Xamarin.iOS10\Calabash.dll 74 | 75 | 76 | 77 | ..\packages\Xamarin.Forms.1.3.3.6323\lib\Xamarin.iOS10\Xamarin.Forms.Platform.iOS.dll 78 | 79 | 80 | ..\packages\Xamarin.Forms.1.3.3.6323\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll 81 | 82 | 83 | ..\packages\Xamarin.Forms.1.3.3.6323\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /iOS/Resources/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/Resources/Default-568h@2x.png -------------------------------------------------------------------------------- /iOS/Resources/Default-Portrait.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/Resources/Default-Portrait.png -------------------------------------------------------------------------------- /iOS/Resources/Default-Portrait@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/Resources/Default-Portrait@2x.png -------------------------------------------------------------------------------- /iOS/Resources/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/Resources/Default.png -------------------------------------------------------------------------------- /iOS/Resources/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/Resources/Default@2x.png -------------------------------------------------------------------------------- /iOS/Resources/Icon-60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/Resources/Icon-60@2x.png -------------------------------------------------------------------------------- /iOS/Resources/Icon-60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/Resources/Icon-60@3x.png -------------------------------------------------------------------------------- /iOS/Resources/Icon-76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/Resources/Icon-76.png -------------------------------------------------------------------------------- /iOS/Resources/Icon-76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/Resources/Icon-76@2x.png -------------------------------------------------------------------------------- /iOS/Resources/Icon-Small-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/Resources/Icon-Small-40.png -------------------------------------------------------------------------------- /iOS/Resources/Icon-Small-40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/Resources/Icon-Small-40@2x.png -------------------------------------------------------------------------------- /iOS/Resources/Icon-Small-40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/Resources/Icon-Small-40@3x.png -------------------------------------------------------------------------------- /iOS/Resources/Icon-Small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/Resources/Icon-Small.png -------------------------------------------------------------------------------- /iOS/Resources/Icon-Small@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/Resources/Icon-Small@2x.png -------------------------------------------------------------------------------- /iOS/Resources/Icon-Small@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burf2000/OpenGLXamarin/3609d222cf035a2bf83c5393e3b04f7a0ee97808/iOS/Resources/Icon-Small@3x.png -------------------------------------------------------------------------------- /iOS/Resources/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /iOS/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | --------------------------------------------------------------------------------