From: jp Date: Sat, 23 Jul 2016 09:42:41 +0000 (+0200) Subject: tutorial examples X-Git-Tag: v0.4~40 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=7164e3fd70dc2401c6b325e4ddda4755332c00f6;p=jp%2Fcrow.git tutorial examples --- diff --git a/Crow.OpenTK.nuspec b/Crow.OpenTK.nuspec index af071203..7bc58240 100644 --- a/Crow.OpenTK.nuspec +++ b/Crow.OpenTK.nuspec @@ -2,8 +2,8 @@ Crow.OpenTK - 0.4.1 - C# Rapid Widget Toolkit + 0.4.3 + C# Rapid Open Widget Toolkit JP Bruyere Grand Tetras Software Team https://www.gnu.org/licenses/gpl-3.0.html @@ -11,10 +11,17 @@ https://jpbruyere.github.io/Crow/images/crow.png false - CROW is a pure C# widget toolkit with templates, styles, compositing, and bindings. - Crow.OpenTK is the OpenTK ready version. +CROW is a pure C# widget toolkit with templates, styles, compositing, and bindings. +Crow.OpenTK is the OpenTK ready version. +This package depends on a pre-release OpenTK version, ensure pre-release packages are visible in your nuget client when adding Crow package. - Beta release, minimal OpenTK implementation. + +CROW is a pure C# widget toolkit with templates, styles, compositing, and bindings. +Crow.OpenTK is the OpenTK ready version. + +For more information, please visit https://jpbruyere.github.io/Crow/. + + pre-alpha release, minimal OpenTK implementation. Copyright 2016 diff --git a/Crow.csproj b/Crow.csproj index 72e52fed..68f67ca6 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -12,19 +12,19 @@ True False False - $(SolutionDir)/build/$(Configuration) - $(SolutionDir)/build/obj/$(Configuration) 4 False false False OnBuildSuccess v4.5 - Crow project description + C# Rapid Open Widget 4194304 0.4 8.0.30703 - 2.0 + 2.0 + $(SolutionDir)/build/$(Configuration) + $(SolutionDir)/build/obj/$(Configuration) true @@ -39,100 +39,288 @@ __linux__;MEASURE_TIME - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -140,22 +328,30 @@ + + packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\atk-sharp.dll + - $(SolutionDir)packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\cairo-sharp.dll - gtk-sharp-3.0 + packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\cairo-sharp.dll + + + packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\gdk-sharp.dll - $(SolutionDir)packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\gio-sharp.dll - gio-sharp-3.0 + packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\gio-sharp.dll - $(SolutionDir)packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\glib-sharp.dll - glib-sharp-3.0 + packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\glib-sharp.dll + + + packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\gtk-dotnet.dll + + + packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\gtk-sharp.dll + + + packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\pango-sharp.dll - - $(SolutionDir)packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\gdk-sharp.dll - gtk-sharp-3.0 - @@ -255,6 +451,8 @@ - + + + diff --git a/Templates/Window.goml b/Templates/Window.goml index 3acb51ab..5ce4347c 100755 --- a/Templates/Window.goml +++ b/Templates/Window.goml @@ -4,7 +4,7 @@ MouseLeave="../onBorderMouseLeave"> + Background="vgradient|0:0,4;0,6;0,0;0,5|1:0,0;0,8;0,8;0,9"> diff --git a/Tests/BasicTests.cs b/Tests/BasicTests.cs new file mode 100644 index 00000000..e194bc80 --- /dev/null +++ b/Tests/BasicTests.cs @@ -0,0 +1,137 @@ +using System; +using Crow; +using System.Collections.Generic; +using System.Linq; +using System.IO; + + +namespace Tests +{ + class BasicTests : OpenTKGameWindow + { + public BasicTests () + : base(800, 600,"test: press spacebar to toogle test files") + { + } + + int idx = 0; + string[] testFiles; + + #region Test values for Binding + public int intValue = 25; + + public int IntValue { + get { + return intValue; + } + set { + intValue = value; + NotifyValueChanged ("IntValue", intValue); + } + } + void onSpinnerValueChange(object sender, ValueChangeEventArgs e){ + if (e.MemberName != "Value") + return; + intValue = Convert.ToInt32(e.NewValue); + } + void change_alignment(object sender, EventArgs e){ + RadioButton rb = sender as RadioButton; + if (rb == null) + return; + NotifyValueChanged ("alignment", Enum.Parse(typeof(Alignment), rb.Caption)); + } + public IList List2 = new List(new string[] + { + "string1", + "string2", + "string3", + "string4", + "string5", + "string6", + "string7", + "string8", + "string8", + "string8", + "string8", + "string8", + "string8", + "string9" + } + ); + IList testList = Color.ColorDic.ToList(); + public IList TestList { + set{ + testList = value; + NotifyValueChanged ("TestList", testList); + } + get { return testList; } + } + #endregion + + void OnClear (object sender, MouseButtonEventArgs e) => TestList = null; + + void OnLoadList (object sender, MouseButtonEventArgs e) => TestList = Color.ColorDic.ToList(); + + protected override void OnLoad (EventArgs e) + { + base.OnLoad (e); + + KeyboardKeyDown += GOLIBTests_KeyboardKeyDown1; + + + testFiles = new string [] { @"Interfaces/Divers/welcome.crow" }; + testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/GraphicObject", "*.crow")).ToArray (); + //testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/basicTests", "*.crow")).ToArray (); + testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Container", "*.crow")).ToArray (); + testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Group", "*.crow")).ToArray (); + testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Stack", "*.crow")).ToArray (); + testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Splitter", "*.crow")).ToArray (); + testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Expandable", "*.crow")).ToArray (); + testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Divers", "*.crow")).ToArray (); + + this.Title = testFiles [idx] + ". Press key to switch example."; + CrowInterface.LoadInterface(testFiles[idx]).DataSource = this; + } + void GOLIBTests_KeyboardKeyDown1 (object sender, OpenTK.Input.KeyboardKeyEventArgs e) + { + if (e.Key == OpenTK.Input.Key.Escape) { + Quit (null, null); + return; + } else if (e.Key == OpenTK.Input.Key.L) { + TestList.Add ("new string"); + NotifyValueChanged ("TestList", TestList); + return; + } else if (e.Key == OpenTK.Input.Key.W) { + GraphicObject w = CrowInterface.LoadInterface("Interfaces/testWindow.goml"); + w.DataSource = this; + return; + } + CrowInterface.ClearInterface (); + idx++; + if (idx == testFiles.Length) + idx = 0; + this.Title = testFiles [idx] + ". Press key to cycle examples."; + GraphicObject obj = CrowInterface.LoadInterface(testFiles[idx]); + obj.DataSource = this; + } + + void onButClick(object send, MouseButtonEventArgs e) + { + Console.WriteLine ("button clicked:" + send.ToString()); + } + void onAddTabButClick(object sender, MouseButtonEventArgs e){ + + TabView tv = CrowInterface.FindByName("tabview1") as TabView; + if (tv == null) + return; + tv.AddChild (new TabItem () { Caption = "NewTab" }); + } + [STAThread] + static void Main () + { + Console.WriteLine ("starting example"); + BasicTests win = new BasicTests (); + win.Run (30); + } + } +} \ No newline at end of file diff --git a/Tests/GOLIBTestsOTK.cs b/Tests/GOLIBTestsOTK.cs deleted file mode 100644 index 316c73c2..00000000 --- a/Tests/GOLIBTestsOTK.cs +++ /dev/null @@ -1,169 +0,0 @@ -#define MONO_CAIRO_DEBUG_DISPOSE - - -using System; -using System.Runtime.InteropServices; -using OpenTK; -using OpenTK.Graphics.OpenGL; - -using System.Diagnostics; - -//using GGL; -using Crow; -using System.Threading; -using System.Collections.Generic; -using System.Linq; -using System.IO; - - -namespace testOTK -{ - class GOLIBTests : OpenTKGameWindow - { - public GOLIBTests () - : base(800, 600,"test: press spacebar to toogle test files") - { - VSync = VSyncMode.Off; - Interface.CurrentInterface = CrowInterface; - } - - int frameCpt = 0; - int idx = 0; - - string[] testFiles; - - - public int intValue = 25; - - public int IntValue { - get { - return intValue; - } - set { - intValue = value; - NotifyValueChanged ("IntValue", intValue); - } - } - void onSpinnerValueChange(object sender, ValueChangeEventArgs e){ - if (e.MemberName != "Value") - return; - intValue = Convert.ToInt32(e.NewValue); - } - void change_alignment(object sender, EventArgs e){ - RadioButton rb = sender as RadioButton; - if (rb == null) - return; - NotifyValueChanged ("alignment", Enum.Parse(typeof(Alignment), rb.Caption)); - } - public IList List2 = new List(new string[] - { - "string1", - "string2", - "string3", - "string4", - "string5", - "string6", - "string7", - "string8", - "string8", - "string8", - "string8", - "string8", - "string8", - "string9" - } - ); - IList testList = Color.ColorDic.ToList(); - public IList TestList { - set{ - testList = value; - NotifyValueChanged ("TestList", testList); - } - get { return testList; } - } - void OnClear (object sender, MouseButtonEventArgs e) => TestList = null; - - void OnLoadList (object sender, MouseButtonEventArgs e) => TestList = Color.ColorDic.ToList(); - - protected override void OnLoad (EventArgs e) - { - base.OnLoad (e); - //this.AddWidget(new test4()); - KeyboardKeyDown += GOLIBTests_KeyboardKeyDown1; - - //testFiles = new string [] { @"Interfaces/Divers/testBind0.crow" }; - testFiles = new string [] { @"Interfaces/Divers/testCombobox.crow" }; - testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/GraphicObject", "*.crow")).ToArray (); - //testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/basicTests", "*.crow")).ToArray (); - testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Container", "*.crow")).ToArray (); - testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Group", "*.crow")).ToArray (); - testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Stack", "*.crow")).ToArray (); - testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Splitter", "*.crow")).ToArray (); - testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Expandable", "*.crow")).ToArray (); - testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Divers", "*.crow")).ToArray (); - - //testFiles = Directory.GetFiles(@"Interfaces", "*.crow").Concat(testFiles).ToArray(); - this.Title = testFiles [idx]; - CrowInterface.LoadInterface(testFiles[idx]).DataSource = this; - - //CrowInterface.LoadInterface ("#Tests.ui.fps.crow").DataSource = this; - - } - void GOLIBTests_KeyboardKeyDown1 (object sender, OpenTK.Input.KeyboardKeyEventArgs e) - { - if (e.Key == OpenTK.Input.Key.Escape) { - Quit (null, null); - return; - } else if (e.Key == OpenTK.Input.Key.L) { - TestList.Add ("new string"); - NotifyValueChanged ("TestList", TestList); - return; - } else if (e.Key == OpenTK.Input.Key.W) { - GraphicObject w = CrowInterface.LoadInterface("Interfaces/testWindow.goml"); - w.DataSource = this; - return; - } - CrowInterface.ClearInterface (); - idx++; - if (idx == testFiles.Length) - idx = 0; - this.Title = testFiles [idx]; - GraphicObject obj = CrowInterface.LoadInterface(testFiles[idx]); - obj.DataSource = this; - } - - void onButClick(object send, MouseButtonEventArgs e) - { - Console.WriteLine ("button clicked:" + send.ToString()); - } - void onAddTabButClick(object sender, MouseButtonEventArgs e){ - - TabView tv = CrowInterface.FindByName("tabview1") as TabView; - if (tv == null) - return; - tv.AddChild (new TabItem () { Caption = "NewTab" }); - } - [STAThread] - static void Main () - { - Console.WriteLine ("starting example"); - GOLIBTests win = new GOLIBTests (); - win.Run (30); - //win.KeyPressEvent += win.Win_KeyPressEvent; - } - -// void Win_KeyPressEvent (object o, Gtk.KeyPressEventArgs args) -// { -// CrowInterface.ClearInterface (); -// idx++; -// if (idx == testFiles.Length) -// idx = 0; -// this.Title = testFiles [idx]; -// GraphicObject obj = CrowInterface.LoadInterface(testFiles[2]); -// obj.DataSource = this; -// } - - - - } -} \ No newline at end of file diff --git a/Tests/HelloCube.cs b/Tests/HelloCube.cs new file mode 100644 index 00000000..4ecd56b8 --- /dev/null +++ b/Tests/HelloCube.cs @@ -0,0 +1,87 @@ +// +// HelloCube.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2016 jp +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; +using OpenTK; +using OpenTK.Graphics.OpenGL; +using Crow; + +namespace Tests +{ + class HelloCube : OpenTKGameWindow + { + [STAThread] + static void Main () + { + HelloCube win = new HelloCube (); + win.Run (30); + } + + public HelloCube () + : base(800, 600,"Crow Test with OpenTK") + { + } + + vaoMesh cube; + Texture texture; + Matrix4 projection, modelview; + + void initGL(){ + GL.Enable (EnableCap.CullFace); + GL.Enable (EnableCap.Blend); + GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); + + cube = vaoMesh.CreateCube (); + texture = new Texture ("image/textest.png"); + + projection = + Matrix4.CreatePerspectiveFieldOfView ( + MathHelper.PiOver4, + ClientRectangle.Width / (float)ClientRectangle.Height, 1.0f, 10.0f); + modelview = Matrix4.LookAt(new Vector3(5,5,5), Vector3.Zero, Vector3.UnitZ); + } + + protected override void OnLoad (EventArgs e) + { + base.OnLoad (e); + + CrowInterface.AddWidget( + new Window () + { + Title = "Hello World", + Width = 200, + Height = 200 + } + ); + initGL (); + } + public override void OnRender (FrameEventArgs e) + { + base.OnRender (e); + + shader.SetMVP(modelview * projection); + + GL.BindTexture (TextureTarget.Texture2D, texture); + cube.Render (BeginMode.Triangles); + GL.BindTexture (TextureTarget.Texture2D, 0); + } + } +} \ No newline at end of file diff --git a/Tests/HelloWorld.cs b/Tests/HelloWorld.cs new file mode 100644 index 00000000..22362393 --- /dev/null +++ b/Tests/HelloWorld.cs @@ -0,0 +1,27 @@ +using System; +using Crow; + +namespace Tests +{ + class HelloWorld : OpenTKGameWindow + { + public HelloWorld () + : base(800, 600,"Crow Test with OpenTK") + { + } + + protected override void OnLoad (EventArgs e) + { + base.OnLoad (e); + + CrowInterface.AddWidget(new Label("Hello World")); + } + + [STAThread] + static void Main () + { + HelloWorld win = new HelloWorld (); + win.Run (30); + } + } +} \ No newline at end of file diff --git a/Tests/Interfaces/Divers/welcome.crow b/Tests/Interfaces/Divers/welcome.crow new file mode 100644 index 00000000..504413a1 --- /dev/null +++ b/Tests/Interfaces/Divers/welcome.crow @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/Tests/OTKCrow.cs b/Tests/OTKCrow.cs deleted file mode 100644 index baa42f07..00000000 --- a/Tests/OTKCrow.cs +++ /dev/null @@ -1,43 +0,0 @@ -#define MONO_CAIRO_DEBUG_DISPOSE - - -using System; -using System.Runtime.InteropServices; -using OpenTK; -using OpenTK.Graphics.OpenGL; - -using System.Diagnostics; - -//using GGL; -using Crow; -using System.Threading; -using System.Collections.Generic; -using System.Linq; -using System.IO; - - -namespace testCrowOTK -{ - class CrowTest : OpenTKGameWindow - { - public CrowTest () - : base(800, 600,"Crow Test with OpenTK") - { - } - - - protected override void OnLoad (EventArgs e) - { - base.OnLoad (e); - - CrowInterface.LoadInterface ("#Tests.ui.test.crow").DataSource = this; - } - - [STAThread] - static void Main () - { - CrowTest win = new CrowTest (); - win.Run (30); - } - } -} \ No newline at end of file diff --git a/Tests/OpenGL/Shader.cs b/Tests/OpenGL/Shader.cs index 54f9140a..6ae99b89 100644 --- a/Tests/OpenGL/Shader.cs +++ b/Tests/OpenGL/Shader.cs @@ -1,12 +1,31 @@ -using System; +// +// Shader.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2016 jp +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; using System.Diagnostics; using System.IO; -using System.Reflection; using OpenTK; using OpenTK.Graphics.OpenGL; -using System.Collections.Generic; -namespace Tetra +namespace Crow { public class Shader : IDisposable { @@ -59,7 +78,7 @@ namespace Tetra void main(void) { - out_frag_color = texture( tex, texCoord); + out_frag_color = texture( tex, texCoord);//vec4(1,0,0,1); }"; string _geomSource = @""; // #version 330 diff --git a/Tests/OpenGL/Texture.cs b/Tests/OpenGL/Texture.cs new file mode 100644 index 00000000..5e3a350a --- /dev/null +++ b/Tests/OpenGL/Texture.cs @@ -0,0 +1,93 @@ +// +// Texture.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2016 jp +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; +using System.Drawing; +using OpenTK.Graphics.OpenGL; +using System.Drawing.Imaging; +using System.IO; +using System.Diagnostics; + +namespace Crow +{ + public class Texture + { + public string Map; + public int texRef; + public int Width; + public int Height; + + public Texture(string _mapPath, bool flipY = true) + { + if (!File.Exists (_mapPath)) + throw new FileNotFoundException ("Texture not found", _mapPath); + try { + Map = _mapPath; + + Bitmap bitmap = new Bitmap(_mapPath); + + if(flipY) + bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); + + BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), + ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + + createTexture (data.Scan0, data.Width, data.Height); + + bitmap.UnlockBits(data); + + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); + + GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); + + } catch (Exception ex) { + Debug.WriteLine ("Error loading texture: " + Map + ":" + ex.Message); + } + } + + public Texture(int width, int height) + { + createTexture (IntPtr.Zero, width, height); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp); + } + + void createTexture(IntPtr data, int width, int height) + { + Width = width; + Height = height; + + GL.GenTextures(1, out texRef); + GL.BindTexture(TextureTarget.Texture2D, texRef); + GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, + OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data); + } + + public static implicit operator int(Texture t) + { + return t == null ? 0: t.texRef; + } + } + +} diff --git a/Tests/OpenGL/vaoMesh.cs b/Tests/OpenGL/vaoMesh.cs index b076362c..19acd737 100644 --- a/Tests/OpenGL/vaoMesh.cs +++ b/Tests/OpenGL/vaoMesh.cs @@ -1,14 +1,27 @@ -using System; -using System.Runtime.InteropServices; -using System.Collections.Generic; +// +// vaoMesh.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2016 jp +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; using OpenTK; using OpenTK.Graphics.OpenGL; -//using System.Drawing; -using System.Drawing.Imaging; -using System.IO; -using System.Threading; -using System.Diagnostics; -using System.Linq; namespace Crow { @@ -33,8 +46,7 @@ namespace Crow texCoords = _texCoord; indices = _indices; - CreateVBOs (); - CreateVAOs (); + CreateBuffers (); } public vaoMesh (float x, float y, float z, float width, float height, float TileX = 1f, float TileY = 1f) @@ -54,8 +66,72 @@ namespace Crow }; indices = new int[] { 0, 1, 2, 3 }; - CreateVBOs (); - CreateVAOs (); + CreateBuffers (); + } + public static vaoMesh CreateCube(){ + vaoMesh tmp = new vaoMesh (); + tmp.positions = new Vector3[] + { + new Vector3(-1.0f, -1.0f, -1.0f), + new Vector3( -1.0f, -1.0f, 1.0f), + new Vector3( 1.0f, -1.0f, -1.0f), + new Vector3(1.0f, -1.0f, 1.0f), + new Vector3(1.0f, 1.0f, -1.0f), + new Vector3( 1.0f, 1.0f, 1.0f), + new Vector3( -1.0f, 1.0f, -1.0f), + new Vector3(-1.0f, 1.0f, 1.0f) + }; + tmp.indices = new int[] + { + // front face + 0, 2, 1, 1, 2, 3, + // top face + 2, 4, 3, 3, 4, 5, + // back face + 4, 6, 5, 5, 6, 7, + // left face + 6, 0, 7, 7, 0, 1, + // bottom face + 1, 3, 7, 7, 3, 5, + // right face +// 1, 5, 6, 6, 2, 1, + }; + tmp.texCoords = new Vector2[] + { + new Vector2(0, 0), + new Vector2(0, 1), + new Vector2(1, 0), + new Vector2(1, 1), + new Vector2(0, 0), + new Vector2(0, 1), + new Vector2(1, 0), + new Vector2(1, 1), + }; + tmp.CreateBuffers (); + return tmp; +// Normals = new Vector3[] +// { +// new Vector3(-1.0f, -1.0f, 1.0f), +// new Vector3( 1.0f, -1.0f, 1.0f), +// new Vector3( 1.0f, 1.0f, 1.0f), +// new Vector3(-1.0f, 1.0f, 1.0f), +// new Vector3(-1.0f, -1.0f, -1.0f), +// new Vector3( 1.0f, -1.0f, -1.0f), +// new Vector3( 1.0f, 1.0f, -1.0f), +// new Vector3(-1.0f, 1.0f, -1.0f), +// }; +// +// Colors = new int[] +// { +// Utilities.ColorToRgba32(Color.DarkRed), +// Utilities.ColorToRgba32(Color.DarkRed), +// Utilities.ColorToRgba32(Color.Gold), +// Utilities.ColorToRgba32(Color.Gold), +// Utilities.ColorToRgba32(Color.DarkRed), +// Utilities.ColorToRgba32(Color.DarkRed), +// Utilities.ColorToRgba32(Color.Gold), +// Utilities.ColorToRgba32(Color.Gold), +// }; } public void CreateBuffers(){ CreateVBOs (); diff --git a/Tests/OpenTKGameWindow.cs b/Tests/OpenTKGameWindow.cs index 1dcd6066..381f86c8 100644 --- a/Tests/OpenTKGameWindow.cs +++ b/Tests/OpenTKGameWindow.cs @@ -19,13 +19,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; using System.Threading; -using System.Xml; -using Cairo; using OpenTK; using OpenTK.Graphics.OpenGL; @@ -151,9 +145,10 @@ namespace Crow #endregion #region graphic context - int texID; - Tetra.Shader shader; - public static Crow.vaoMesh quad; + public int texID; + public Shader shader; + public vaoMesh quad; + public Matrix4 projection; void createContext() { @@ -183,6 +178,7 @@ namespace Crow GL.Disable (EnableCap.DepthTest); shader.Enable (); + shader.SetMVP (projection); GL.ActiveTexture (TextureUnit.Texture0); GL.BindTexture (TextureTarget.Texture2D, texID); lock (CrowInterface.RenderMutex) { @@ -196,7 +192,7 @@ namespace Crow } quad.Render (BeginMode.TriangleStrip); GL.BindTexture(TextureTarget.Texture2D, 0); - shader.Disable (); + if (!blend) GL.Disable (EnableCap.Blend); if (depthTest) @@ -204,12 +200,18 @@ namespace Crow } #endregion + /// + /// Override this method for your OpenGL rendering calls + /// public virtual void OnRender(FrameEventArgs e) { } + /// + /// Override this method to customize clear method between frames + /// public virtual void GLClear() { - GL.Clear (ClearBufferMask.ColorBufferBit); + GL.Clear (ClearBufferMask.ColorBufferBit|ClearBufferMask.DepthBufferBit); } #region Game win overrides @@ -233,10 +235,9 @@ namespace Crow Console.WriteLine("GLSL version: " + GL.GetString (StringName.ShadingLanguageVersion)); Console.WriteLine("*************************************\n"); - shader = new Tetra.Shader (); - shader.Enable(); - shader.SetMVP(OpenTK.Matrix4.CreateOrthographicOffCenter (-0.5f, 0.5f, -0.5f, 0.5f, 1, -1)); - GL.UseProgram(0); + projection = OpenTK.Matrix4.CreateOrthographicOffCenter (-0.5f, 0.5f, -0.5f, 0.5f, 1, -1); + + shader = new Shader (); quad = new Crow.vaoMesh (0, 0, 0, 1, 1, 1, -1); } @@ -254,7 +255,6 @@ namespace Crow NotifyValueChanged("memory", GC.GetTotalMemory (false).ToString()); } frameCpt++; - //CrowInterface.Update (); } protected override void OnRenderFrame(FrameEventArgs e) { diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index ab27a959..48427086 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -8,12 +8,12 @@ Exe Tests Tests - testOTK.GOLIBTests + Tests.HelloWorld v4.5 - $(SolutionDir)/build/$(Configuration) - $(SolutionDir)/build/obj/$(Configuration) AnyCPU - 0.4 + 0.4 + $(SolutionDir)/build/$(Configuration) + $(SolutionDir)/build/obj/$(Configuration) true @@ -31,39 +31,49 @@ false + - $(SolutionDir)\packages\OpenTK.Next.1.2.2336.6514-pre\lib\net20\OpenTK.dll + ..\packages\OpenTK.Next.1.2.2336.6514-pre\lib\net20\OpenTK.dll + + + ..\packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\atk-sharp.dll - $(SolutionDir)packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\cairo-sharp.dll - gtk-sharp-3.0 + ..\packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\cairo-sharp.dll + + + ..\packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\gdk-sharp.dll - $(SolutionDir)packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\gio-sharp.dll - gio-sharp-3.0 + ..\packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\gio-sharp.dll - $(SolutionDir)packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\glib-sharp.dll - glib-sharp-3.0 - - - $(SolutionDir)packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\gdk-sharp.dll - gtk-sharp-3.0 - - + ..\packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\glib-sharp.dll + + + ..\packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\gtk-dotnet.dll + + + ..\packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\gtk-sharp.dll + + + ..\packages\gtk-sharp.Linux.3.14.3.14.7\lib\net40\pango-sharp.dll + - - - - - - + + + + + + + + @@ -122,111 +132,147 @@ PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + Tests.Interfaces.test7.goml @@ -234,114 +280,162 @@ PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + PreserveNewest + + + + + + + PreserveNewest + + + + PreserveNewest + @@ -356,7 +450,9 @@ - + + PreserveNewest + diff --git a/Tests/image/textest.png b/Tests/image/textest.png new file mode 100755 index 00000000..678e6d44 Binary files /dev/null and b/Tests/image/textest.png differ diff --git a/Tests/ui/test.crow b/Tests/ui/test.crow index d0450fed..d293a65e 100755 --- a/Tests/ui/test.crow +++ b/Tests/ui/test.crow @@ -1,5 +1,5 @@  - + @@ -16,7 +16,21 @@ - + + + + + + + + + + + + + + +