From: JP Bruyère Date: Mon, 25 Jul 2016 13:07:56 +0000 (+0200) Subject: remove test tm dir X-Git-Tag: v0.4~28 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=55824e2d4fa575f45a129ba4d8f073c7fb5b0d34;p=jp%2Fcrow.git remove test tm dir --- diff --git a/tm/test/HelloCube.cs b/tm/test/HelloCube.cs deleted file mode 100644 index 4ecd56b8..00000000 --- a/tm/test/HelloCube.cs +++ /dev/null @@ -1,87 +0,0 @@ -// -// 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/tm/test/OpenGL/Shader.cs b/tm/test/OpenGL/Shader.cs deleted file mode 100644 index 6ae99b89..00000000 --- a/tm/test/OpenGL/Shader.cs +++ /dev/null @@ -1,336 +0,0 @@ -// -// 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 OpenTK; -using OpenTK.Graphics.OpenGL; - -namespace Crow -{ - public class Shader : IDisposable - { - #region CTOR - public Shader () - { - Init (); - } - public Shader (string vertResPath, string fragResPath = null, string geomResPath = null) - { - VertSourcePath = vertResPath; - FragSourcePath = fragResPath; - GeomSourcePath = geomResPath; - - loadSourcesFiles (); - - Init (); - } - #endregion - - public string VertSourcePath, - FragSourcePath, - GeomSourcePath; - #region Sources - protected string _vertSource = @" - #version 330 - precision lowp float; - - uniform mat4 mvp; - - layout(location = 0) in vec3 in_position; - layout(location = 1) in vec2 in_tex; - - out vec2 texCoord; - - void main(void) - { - texCoord = in_tex; - gl_Position = mvp * vec4(in_position, 1.0); - }"; - - protected string _fragSource = @" - #version 330 - precision lowp float; - - uniform sampler2D tex; - - in vec2 texCoord; - out vec4 out_frag_color; - - void main(void) - { - out_frag_color = texture( tex, texCoord);//vec4(1,0,0,1); - }"; - string _geomSource = @""; -// #version 330 -// layout(triangles) in; -// layout(triangle_strip, max_vertices=3) out; -// void main() -// { -// for(int i=0; i<3; i++) -// { -// gl_Position = gl_in[i].gl_Position; -// EmitVertex(); -// } -// EndPrimitive(); -// }"; - #endregion - - #region Private and protected fields - public int vsId, fsId, gsId, pgmId, mvpLocation; - - Matrix4 mvp = Matrix4.Identity; - #endregion - - - #region Public properties - public virtual string vertSource - { - get { return _vertSource;} - set { _vertSource = value; } - } - public virtual string fragSource - { - get { return _fragSource;} - set { _fragSource = value; } - } - public virtual string geomSource - { - get { return _geomSource; } - set { _geomSource = value; } - } - - public virtual Matrix4 MVP{ - set { mvp = value; } - get { return mvp; } - } - #endregion - - #region Public functions - /// - /// configure sources and compile - /// - public virtual void Init() - { - Compile (); - } - public void Reload(){ - loadSourcesFiles (); - Compile (); - } - public void SetSource(ShaderType shaderType, string _source){ - switch (shaderType) { - case ShaderType.FragmentShader: - fragSource = _source; - return; - case ShaderType.VertexShader: - vertSource = _source; - return; - case ShaderType.GeometryShader: - geomSource = _source; - return; - } - } - public string GetSource(ShaderType shaderType){ - switch (shaderType) { - case ShaderType.FragmentShader: - return fragSource; - case ShaderType.VertexShader: - return vertSource; - case ShaderType.GeometryShader: - return geomSource; - } - return ""; - } - public string GetSourcePath(ShaderType shaderType){ - switch (shaderType) { - case ShaderType.FragmentShader: - return FragSourcePath; - case ShaderType.VertexShader: - return VertSourcePath; - case ShaderType.GeometryShader: - return GeomSourcePath; - } - return ""; - } - public virtual void Compile() - { - Dispose (); - - pgmId = GL.CreateProgram(); - - if (!string.IsNullOrEmpty(vertSource)) - { - vsId = GL.CreateShader(ShaderType.VertexShader); - compileShader(vsId, vertSource); - } - if (!string.IsNullOrEmpty(fragSource)) - { - fsId = GL.CreateShader(ShaderType.FragmentShader); - compileShader(fsId, fragSource); - - } - if (!string.IsNullOrEmpty(geomSource)) - { - gsId = GL.CreateShader(ShaderType.GeometryShader); - compileShader(gsId,geomSource); - } - - if (vsId != 0) - GL.AttachShader(pgmId, vsId); - if (fsId != 0) - GL.AttachShader(pgmId, fsId); - if (gsId != 0) - GL.AttachShader(pgmId, gsId); - - BindVertexAttributes (); - - string info; - GL.LinkProgram(pgmId); - GL.GetProgramInfoLog(pgmId, out info); - - if (!string.IsNullOrEmpty (info)) { - Debug.WriteLine ("Linkage:"); - Debug.WriteLine (info); - } - - info = null; - - GL.ValidateProgram(pgmId); - GL.GetProgramInfoLog(pgmId, out info); - if (!string.IsNullOrEmpty (info)) { - Debug.WriteLine ("Validation:"); - Debug.WriteLine (info); - } - - GL.UseProgram (pgmId); - - GetUniformLocations (); - BindSamplesSlots (); - - Disable (); - } - - protected virtual void BindVertexAttributes() - { - GL.BindAttribLocation(pgmId, 0, "in_position"); - GL.BindAttribLocation(pgmId, 1, "in_tex"); - } - protected virtual void GetUniformLocations() - { - mvpLocation = GL.GetUniformLocation(pgmId, "mvp"); - } - protected virtual void BindSamplesSlots(){ - GL.Uniform1(GL.GetUniformLocation (pgmId, "tex"), 0); - } - public void SetMVP(Matrix4 _mvp){ - GL.UniformMatrix4(mvpLocation, false, ref _mvp); - } - public virtual void Enable(){ - GL.UseProgram (pgmId); - } - public virtual void Disable(){ - GL.UseProgram (0); - } - public static void Enable(Shader s) - { - if (s == null) - return; - s.Enable (); - } - public static void Disable(Shader s) - { - if (s == null) - return; - s.Disable (); - } - #endregion - - void loadSourcesFiles(){ - Stream s; - - if (!string.IsNullOrEmpty (VertSourcePath)) { - s = Crow.Interface.GetStreamFromPath (VertSourcePath); - if (s != null) { - using (StreamReader sr = new StreamReader (s)) { - vertSource = sr.ReadToEnd (); - } - } - } - - if (!string.IsNullOrEmpty (FragSourcePath)) { - s = Crow.Interface.GetStreamFromPath (FragSourcePath); - if (s != null) { - using (StreamReader sr = new StreamReader (s)) { - fragSource = sr.ReadToEnd (); - } - } - } - - if (!string.IsNullOrEmpty (GeomSourcePath)) { - s = Crow.Interface.GetStreamFromPath (GeomSourcePath); - if (s != null) { - using (StreamReader sr = new StreamReader (s)) { - geomSource = sr.ReadToEnd (); - } - } - } - } - void compileShader(int shader, string source) - { - GL.ShaderSource(shader, source); - GL.CompileShader(shader); - - string info; - GL.GetShaderInfoLog(shader, out info); - Debug.WriteLine(info); - - int compileResult; - GL.GetShader(shader, ShaderParameter.CompileStatus, out compileResult); - if (compileResult != 1) - { - Debug.WriteLine("Compile Error!"); - Debug.WriteLine(source); - } - } - public override string ToString () - { - return string.Format ("{0} {1} {2}", VertSourcePath, FragSourcePath, GeomSourcePath); - } - - #region IDisposable implementation - public virtual void Dispose () - { - if (GL.IsProgram (pgmId)) - GL.DeleteProgram (pgmId); - - if (GL.IsShader (vsId)) - GL.DeleteShader (vsId); - if (GL.IsShader (fsId)) - GL.DeleteShader (fsId); - if (GL.IsShader (gsId)) - GL.DeleteShader (gsId); - } - #endregion - } -} - diff --git a/tm/test/OpenGL/Texture.cs b/tm/test/OpenGL/Texture.cs deleted file mode 100644 index ce24808b..00000000 --- a/tm/test/OpenGL/Texture.cs +++ /dev/null @@ -1,94 +0,0 @@ -// -// 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) - { - using (Stream s = Interface.GetStreamFromPath (_mapPath)) { - - try { - Map = _mapPath; - - Bitmap bitmap = new Bitmap (s); - - 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/tm/test/OpenGL/vaoMesh.cs b/tm/test/OpenGL/vaoMesh.cs deleted file mode 100644 index 19acd737..00000000 --- a/tm/test/OpenGL/vaoMesh.cs +++ /dev/null @@ -1,221 +0,0 @@ -// -// 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; - -namespace Crow -{ - public class vaoMesh : IDisposable - { - public int vaoHandle, - positionVboHandle, - texVboHandle, - eboHandle; - - public Vector3[] positions; - public Vector2[] texCoords; - public int[] indices; - - public vaoMesh() - { - } - - public vaoMesh (Vector3[] _positions, Vector2[] _texCoord, int[] _indices) - { - positions = _positions; - texCoords = _texCoord; - indices = _indices; - - CreateBuffers (); - } - - public vaoMesh (float x, float y, float z, float width, float height, float TileX = 1f, float TileY = 1f) - { - positions = - new Vector3[] { - new Vector3 (x - width / 2, y + height / 2, z), - new Vector3 (x - width / 2, y - height / 2, z), - new Vector3 (x + width / 2, y + height / 2, z), - new Vector3 (x + width / 2, y - height / 2, z) - }; - texCoords = new Vector2[] { - new Vector2 (0, TileY), - new Vector2 (0, 0), - new Vector2 (TileX, TileY), - new Vector2 (TileX, 0) - }; - indices = new int[] { 0, 1, 2, 3 }; - - 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 (); - CreateVAOs (); - } - protected void CreateVBOs() - { - positionVboHandle = GL.GenBuffer(); - GL.BindBuffer(BufferTarget.ArrayBuffer, positionVboHandle); - GL.BufferData(BufferTarget.ArrayBuffer, - new IntPtr(positions.Length * Vector3.SizeInBytes), - positions, BufferUsageHint.StaticDraw); - - if (texCoords != null) { - texVboHandle = GL.GenBuffer (); - GL.BindBuffer (BufferTarget.ArrayBuffer, texVboHandle); - GL.BufferData (BufferTarget.ArrayBuffer, - new IntPtr (texCoords.Length * Vector2.SizeInBytes), - texCoords, BufferUsageHint.StaticDraw); - } - - GL.BindBuffer(BufferTarget.ArrayBuffer, 0); - - if (indices != null) { - eboHandle = GL.GenBuffer (); - GL.BindBuffer (BufferTarget.ElementArrayBuffer, eboHandle); - GL.BufferData (BufferTarget.ElementArrayBuffer, - new IntPtr (sizeof(uint) * indices.Length), - indices, BufferUsageHint.StaticDraw); - GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); - } - } - protected void CreateVAOs() - { - vaoHandle = GL.GenVertexArray(); - GL.BindVertexArray(vaoHandle); - - GL.EnableVertexAttribArray(0); - GL.BindBuffer(BufferTarget.ArrayBuffer, positionVboHandle); - GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, true, Vector3.SizeInBytes, 0); - - if (texCoords != null) { - GL.EnableVertexAttribArray (1); - GL.BindBuffer (BufferTarget.ArrayBuffer, texVboHandle); - GL.VertexAttribPointer (1, 2, VertexAttribPointerType.Float, true, Vector2.SizeInBytes, 0); - } - if (indices != null) - GL.BindBuffer(BufferTarget.ElementArrayBuffer, eboHandle); - - GL.BindVertexArray(0); - } - - public void Render(BeginMode _primitiveType){ - GL.BindVertexArray(vaoHandle); - if (indices == null) - GL.DrawArrays (_primitiveType, 0, positions.Length); - else - GL.DrawElements(_primitiveType, indices.Length, - DrawElementsType.UnsignedInt, IntPtr.Zero); - GL.BindVertexArray (0); - } - public void Render(BeginMode _primitiveType, int[] _customIndices){ - GL.BindVertexArray(vaoHandle); - GL.DrawElements(_primitiveType, _customIndices.Length, - DrawElementsType.UnsignedInt, _customIndices); - GL.BindVertexArray (0); - } - public void Render(BeginMode _primitiveType, int instances){ - - GL.BindVertexArray(vaoHandle); - GL.DrawElementsInstanced(_primitiveType, indices.Length, - DrawElementsType.UnsignedInt, IntPtr.Zero, instances); - GL.BindVertexArray (0); - } - - #region IDisposable implementation - public void Dispose () - { - GL.DeleteBuffer (positionVboHandle); - GL.DeleteBuffer (texVboHandle); - GL.DeleteBuffer (eboHandle); - GL.DeleteVertexArray (vaoHandle); - } - #endregion - - } -} \ No newline at end of file diff --git a/tm/test/OpenTK.dll.config b/tm/test/OpenTK.dll.config deleted file mode 100644 index 7098d39e..00000000 --- a/tm/test/OpenTK.dll.config +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tm/test/OpenTKGameWindow.cs b/tm/test/OpenTKGameWindow.cs deleted file mode 100644 index 381f86c8..00000000 --- a/tm/test/OpenTKGameWindow.cs +++ /dev/null @@ -1,331 +0,0 @@ -// -// OpenTKGameWindow.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.Threading; -using OpenTK; -using OpenTK.Graphics.OpenGL; - -namespace Crow -{ - public class OpenTKGameWindow : GameWindow, IValueChange - { - #region IValueChange implementation - public event EventHandler ValueChanged; - public virtual void NotifyValueChanged(string MemberName, object _value) - { - if (ValueChanged != null) - ValueChanged.Invoke(this, new ValueChangeEventArgs(MemberName, _value)); - } - #endregion - - public Interface CrowInterface; - - #region FPS - int frameCpt = 0; - int _fps = 0; - - public int fps { - get { return _fps; } - set { - if (_fps == value) - return; - - _fps = value; - - if (_fps > fpsMax) { - fpsMax = _fps; - ValueChanged.Raise(this, new ValueChangeEventArgs ("fpsMax", fpsMax)); - } else if (_fps < fpsMin) { - fpsMin = _fps; - ValueChanged.Raise(this, new ValueChangeEventArgs ("fpsMin", fpsMin)); - } - - ValueChanged.Raise(this, new ValueChangeEventArgs ("fps", _fps)); - #if MEASURE_TIME - ValueChanged.Raise (this, new ValueChangeEventArgs ("update", - this.CrowInterface.clippingTime.ElapsedTicks.ToString () + " ticks")); - ValueChanged.Raise (this, new ValueChangeEventArgs ("layouting", - this.CrowInterface.layoutTime.ElapsedTicks.ToString () + " ticks")); - ValueChanged.Raise (this, new ValueChangeEventArgs ("drawing", - this.CrowInterface.drawingTime.ElapsedTicks.ToString () + " ticks")); - #endif - } - } - - public int fpsMin = int.MaxValue; - public int fpsMax = 0; - - void resetFps () - { - fpsMin = int.MaxValue; - fpsMax = 0; - _fps = 0; - } - public string update = ""; - public string drawing = ""; - public string layouting = ""; - #endregion - - #region ctor - public OpenTKGameWindow(int _width = 800, int _height = 600, string _title="Crow", - int colors = 32, int depth = 24, int stencil = 0, int samples = 1, - int major=3, int minor=3) - : this(_width, _height, new OpenTK.Graphics.GraphicsMode(colors, depth, stencil, samples), - _title,GameWindowFlags.Default,DisplayDevice.Default, - major,minor,OpenTK.Graphics.GraphicsContextFlags.Default) - { - } - public OpenTKGameWindow (int width, int height, OpenTK.Graphics.GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device, int major, int minor, OpenTK.Graphics.GraphicsContextFlags flags) - : base(width,height,mode,title,options,device,major,minor,flags) - { - CrowInterface = new Interface (); - - Thread t = new Thread (interfaceThread); - t.IsBackground = true; - t.Start (); - } - - #endregion - - void interfaceThread() - { - CrowInterface.Quit += Quit; - CrowInterface.MouseCursorChanged += CrowInterface_MouseCursorChanged; - while (CrowInterface.ClientRectangle.Size.Width == 0) - Thread.Sleep (5); - - while (true) { - CrowInterface.Update (); - Thread.Sleep (1); - } - } - - public void Quit (object sender, EventArgs e) - { - this.Exit (); - } - void CrowInterface_MouseCursorChanged (object sender, MouseCursorChangedEventArgs e) - { - this.Cursor = new MouseCursor( - (int)e.NewCursor.Xhot, - (int)e.NewCursor.Yhot, - (int)e.NewCursor.Width, - (int)e.NewCursor.Height, - e.NewCursor.data); - } - - #region Events - //those events are raised only if mouse isn't in a graphic object - public event EventHandler MouseWheelChanged; - public event EventHandler MouseButtonUp; - public event EventHandler MouseButtonDown; - public event EventHandler MouseClick; - public event EventHandler MouseMove; - public event EventHandler KeyboardKeyDown; - public event EventHandler KeyboardKeyUp; - - #endregion - - #region graphic context - public int texID; - public Shader shader; - public vaoMesh quad; - public Matrix4 projection; - - void createContext() - { - #region Create texture - if (GL.IsTexture(texID)) - GL.DeleteTexture (texID); - GL.GenTextures(1, out texID); - GL.ActiveTexture (TextureUnit.Texture0); - GL.BindTexture(TextureTarget.Texture2D, texID); - - GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, - ClientRectangle.Width, ClientRectangle.Height, 0, - OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, CrowInterface.bmp); - - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); - - GL.BindTexture(TextureTarget.Texture2D, 0); - #endregion - } - void OpenGLDraw() - { - bool blend, depthTest; - GL.GetBoolean (GetPName.Blend, out blend); - GL.GetBoolean (GetPName.DepthTest, out depthTest); - GL.Enable (EnableCap.Blend); - GL.Disable (EnableCap.DepthTest); - - shader.Enable (); - shader.SetMVP (projection); - GL.ActiveTexture (TextureUnit.Texture0); - GL.BindTexture (TextureTarget.Texture2D, texID); - lock (CrowInterface.RenderMutex) { - if (CrowInterface.IsDirty) { - GL.TexSubImage2D (TextureTarget.Texture2D, 0, - CrowInterface.DirtyRect.Left, CrowInterface.DirtyRect.Top, - CrowInterface.DirtyRect.Width, CrowInterface.DirtyRect.Height, - OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, CrowInterface.dirtyBmp); - CrowInterface.IsDirty = false; - } - } - quad.Render (BeginMode.TriangleStrip); - GL.BindTexture(TextureTarget.Texture2D, 0); - - if (!blend) - GL.Disable (EnableCap.Blend); - if (depthTest) - GL.Enable (EnableCap.DepthTest); - } - #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|ClearBufferMask.DepthBufferBit); - } - - #region Game win overrides - protected override void OnLoad(EventArgs e) - { - base.OnLoad(e); - - this.KeyPress += new EventHandler(OpenTKGameWindow_KeyPress); - Keyboard.KeyDown += new EventHandler(Keyboard_KeyDown); - Keyboard.KeyUp += new EventHandler(Keyboard_KeyUp); - Mouse.WheelChanged += new EventHandler(Mouse_WheelChanged); - Mouse.ButtonDown += new EventHandler(Mouse_ButtonDown); - Mouse.ButtonUp += new EventHandler(Mouse_ButtonUp); - Mouse.Move += new EventHandler(Mouse_Move); - - GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); - - Console.WriteLine("\n\n*************************************"); - Console.WriteLine("GL version: " + GL.GetString (StringName.Version)); - Console.WriteLine("GL vendor: " + GL.GetString (StringName.Vendor)); - Console.WriteLine("GLSL version: " + GL.GetString (StringName.ShadingLanguageVersion)); - Console.WriteLine("*************************************\n"); - - 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); - } - - protected override void OnUpdateFrame(FrameEventArgs e) - { - base.OnUpdateFrame(e); - fps = (int)RenderFrequency; - - - if (frameCpt > 50) { - resetFps (); - frameCpt = 0; - GC.Collect(); - GC.WaitForPendingFinalizers(); - NotifyValueChanged("memory", GC.GetTotalMemory (false).ToString()); - } - frameCpt++; - } - protected override void OnRenderFrame(FrameEventArgs e) - { - GLClear (); - - base.OnRenderFrame(e); - - OnRender (e); - OpenGLDraw (); - - SwapBuffers (); - } - - protected override void OnResize(EventArgs e) - { - base.OnResize (e); - CrowInterface.ProcessResize( - new Rectangle( - 0, - 0, - this.ClientRectangle.Width, - this.ClientRectangle.Height)); - createContext (); - GL.Viewport (0, 0, ClientRectangle.Width, ClientRectangle.Height); - } - #endregion - - #region Mouse Handling - void update_mouseButtonStates(ref MouseState e, OpenTK.Input.MouseState otk_e){ - for (int i = 0; i < MouseState.MaxButtons; i++) { - if (otk_e.IsButtonDown ((OpenTK.Input.MouseButton)i)) - e.EnableBit (i); - } - } - void Mouse_Move(object sender, OpenTK.Input.MouseMoveEventArgs otk_e) - { - if (!CrowInterface.ProcessMouseMove (otk_e.X, otk_e.Y)) - MouseMove.Raise (sender, otk_e); - } - void Mouse_ButtonUp(object sender, OpenTK.Input.MouseButtonEventArgs otk_e) - { - if (!CrowInterface.ProcessMouseButtonUp ((int)otk_e.Button)) - MouseButtonUp.Raise (sender, otk_e); - } - void Mouse_ButtonDown(object sender, OpenTK.Input.MouseButtonEventArgs otk_e) - { - if (!CrowInterface.ProcessMouseButtonDown ((int)otk_e.Button)) - MouseButtonDown.Raise (sender, otk_e); - } - void Mouse_WheelChanged(object sender, OpenTK.Input.MouseWheelEventArgs otk_e) - { - if (!CrowInterface.ProcessMouseWheelChanged (otk_e.DeltaPrecise)) - MouseWheelChanged.Raise (sender, otk_e); - } - #endregion - - #region keyboard Handling - void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs otk_e) - { - //if (!CrowInterface.ProcessKeyDown((int)otk_e.Key)) - KeyboardKeyDown.Raise (this, otk_e); - } - void Keyboard_KeyUp(object sender, OpenTK.Input.KeyboardKeyEventArgs otk_e) - { - //if (!CrowInterface.ProcessKeyUp((int)otk_e.Key)) - KeyboardKeyUp.Raise (this, otk_e); - } - void OpenTKGameWindow_KeyPress (object sender, OpenTK.KeyPressEventArgs e) - { - CrowInterface.ProcessKeyPress (e.KeyChar); - } - #endregion - } -} diff --git a/tm/test/packages.config b/tm/test/packages.config deleted file mode 100644 index 45f276a8..00000000 --- a/tm/test/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/tm/test/textest.png b/tm/test/textest.png deleted file mode 100755 index 678e6d44..00000000 Binary files a/tm/test/textest.png and /dev/null differ