From cc845ca858be069ea6349e2da0c28ff891abd1a7 Mon Sep 17 00:00:00 2001 From: Adrian Ulbrich Date: Sun, 10 Nov 2019 01:26:11 +0100 Subject: [PATCH] Embedded shader files in application --- Unicity.Engine/Properties/AssemblyInfo.cs | 10 +- Unicity.Game/Properties/AssemblyInfo.cs | 10 +- Unicity.Renderer/GraphicsRenderer.cs | 10 +- Unicity.Renderer/Properties/AssemblyInfo.cs | 10 +- .../Properties/Resources.Designer.cs | 83 ++++++++++++ Unicity.Renderer/Properties/Resources.resx | 127 ++++++++++++++++++ Unicity.Renderer/RenderWindow.cs | 4 +- .../fragmentShader.frag} | 2 +- .../test.vert => Resources/vertexShader.vert} | 2 +- Unicity.Renderer/Shader.cs | 2 +- Unicity.Renderer/Unicity.Renderer.csproj | 19 ++- 11 files changed, 247 insertions(+), 32 deletions(-) create mode 100644 Unicity.Renderer/Properties/Resources.Designer.cs create mode 100644 Unicity.Renderer/Properties/Resources.resx rename Unicity.Renderer/{shaders/test.frag => Resources/fragmentShader.frag} (80%) rename Unicity.Renderer/{shaders/test.vert => Resources/vertexShader.vert} (89%) diff --git a/Unicity.Engine/Properties/AssemblyInfo.cs b/Unicity.Engine/Properties/AssemblyInfo.cs index b6ce7aa..c5888d5 100644 --- a/Unicity.Engine/Properties/AssemblyInfo.cs +++ b/Unicity.Engine/Properties/AssemblyInfo.cs @@ -5,12 +5,12 @@ using System.Runtime.InteropServices; // Allgemeine Informationen über eine Assembly werden über die folgenden // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, // die einer Assembly zugeordnet sind. -[assembly: AssemblyTitle("Unicity.Engine")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyTitle("Unicity Game Engine")] +[assembly: AssemblyDescription("Game Engine for the Unicity game")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Unicity.Engine")] -[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyCompany("Alee Productions")] +[assembly: AssemblyProduct("Unicity Engine")] +[assembly: AssemblyCopyright("Copyright © 2019 Alee Productions")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/Unicity.Game/Properties/AssemblyInfo.cs b/Unicity.Game/Properties/AssemblyInfo.cs index 8ebde5e..8ee9d08 100644 --- a/Unicity.Game/Properties/AssemblyInfo.cs +++ b/Unicity.Game/Properties/AssemblyInfo.cs @@ -5,12 +5,12 @@ using System.Runtime.InteropServices; // Allgemeine Informationen über eine Assembly werden über die folgenden // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, // die einer Assembly zugeordnet sind. -[assembly: AssemblyTitle("Unicity.Game")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyTitle("Unicity")] +[assembly: AssemblyDescription("Unicity game")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Unicity.Game")] -[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyCompany("Alee Productions")] +[assembly: AssemblyProduct("Unicity")] +[assembly: AssemblyCopyright("Copyright © 2019 Alee Productions")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/Unicity.Renderer/GraphicsRenderer.cs b/Unicity.Renderer/GraphicsRenderer.cs index 513439e..5e1f730 100644 --- a/Unicity.Renderer/GraphicsRenderer.cs +++ b/Unicity.Renderer/GraphicsRenderer.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; -using System.IO; +using System.Text; using OpenTK; -using OpenTK.Graphics.OpenGL4; +using OpenTK.Graphics.OpenGL; using Unicity.Renderer.Shapes; namespace Unicity.Renderer @@ -26,8 +26,8 @@ namespace Unicity.Renderer this.window = window; window.Render += Window_Render; - string vertexCode = File.ReadAllText("shaders/test.vert"); - string fragmentCode = File.ReadAllText("shaders/test.frag"); + string vertexCode = Encoding.UTF8.GetString(Properties.Resources.vertexShader); + string fragmentCode = Encoding.UTF8.GetString(Properties.Resources.fragmentShader); shader = new Shader(vertexCode, fragmentCode); shader.Use(); @@ -84,8 +84,6 @@ namespace Unicity.Renderer GL.DeleteBuffer(triangleVBO); } - foreach (float v in triangleVerts) System.Console.WriteLine(v); - triangleVAO = GL.GenVertexArray(); triangleVBO = GL.GenBuffer(); diff --git a/Unicity.Renderer/Properties/AssemblyInfo.cs b/Unicity.Renderer/Properties/AssemblyInfo.cs index 1bb3a9f..30d3225 100644 --- a/Unicity.Renderer/Properties/AssemblyInfo.cs +++ b/Unicity.Renderer/Properties/AssemblyInfo.cs @@ -5,12 +5,12 @@ using System.Runtime.InteropServices; // Allgemeine Informationen über eine Assembly werden über die folgenden // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, // die einer Assembly zugeordnet sind. -[assembly: AssemblyTitle("Unicity.Renderer")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyTitle("Unicity Renderer")] +[assembly: AssemblyDescription("Graphics renderer for the Unicity Engine")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Unicity.Renderer")] -[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyCompany("Alee Productions")] +[assembly: AssemblyProduct("Unicity Renderer")] +[assembly: AssemblyCopyright("Copyright © 2019 Alee Productions")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/Unicity.Renderer/Properties/Resources.Designer.cs b/Unicity.Renderer/Properties/Resources.Designer.cs new file mode 100644 index 0000000..c1bc96c --- /dev/null +++ b/Unicity.Renderer/Properties/Resources.Designer.cs @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Unicity.Renderer.Properties { + using System; + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Unicity.Renderer.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Sucht eine lokalisierte Ressource vom Typ System.Byte[]. + /// + internal static byte[] fragmentShader { + get { + object obj = ResourceManager.GetObject("fragmentShader", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// Sucht eine lokalisierte Ressource vom Typ System.Byte[]. + /// + internal static byte[] vertexShader { + get { + object obj = ResourceManager.GetObject("vertexShader", resourceCulture); + return ((byte[])(obj)); + } + } + } +} diff --git a/Unicity.Renderer/Properties/Resources.resx b/Unicity.Renderer/Properties/Resources.resx new file mode 100644 index 0000000..093fbf3 --- /dev/null +++ b/Unicity.Renderer/Properties/Resources.resx @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\fragmentShader.frag;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\vertexShader.vert;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Unicity.Renderer/RenderWindow.cs b/Unicity.Renderer/RenderWindow.cs index eceac9a..823d866 100644 --- a/Unicity.Renderer/RenderWindow.cs +++ b/Unicity.Renderer/RenderWindow.cs @@ -1,7 +1,7 @@ using System; using OpenTK; using OpenTK.Graphics; -using OpenTK.Graphics.OpenGL4; +using OpenTK.Graphics.OpenGL; namespace Unicity.Renderer { @@ -21,7 +21,7 @@ namespace Unicity.Renderer public RenderWindow(int width, int height, string title) { - window = new GameWindow(width, height, GraphicsMode.Default, title, GameWindowFlags.Default, DisplayDevice.Default, 4, 0, GraphicsContextFlags.ForwardCompatible); + window = new GameWindow(width, height, GraphicsMode.Default, title, GameWindowFlags.Default, DisplayDevice.Default, 3, 3, GraphicsContextFlags.ForwardCompatible); window.Load += Window_Load; window.Resize += Window_Resize; window.UpdateFrame += Window_UpdateFrame; diff --git a/Unicity.Renderer/shaders/test.frag b/Unicity.Renderer/Resources/fragmentShader.frag similarity index 80% rename from Unicity.Renderer/shaders/test.frag rename to Unicity.Renderer/Resources/fragmentShader.frag index 8deca4b..7009f75 100644 --- a/Unicity.Renderer/shaders/test.frag +++ b/Unicity.Renderer/Resources/fragmentShader.frag @@ -1,4 +1,4 @@ -#version 400 core +#version 330 core out vec4 FragColor; in vec4 vertexColor; diff --git a/Unicity.Renderer/shaders/test.vert b/Unicity.Renderer/Resources/vertexShader.vert similarity index 89% rename from Unicity.Renderer/shaders/test.vert rename to Unicity.Renderer/Resources/vertexShader.vert index 99496c0..7d1ab7f 100644 --- a/Unicity.Renderer/shaders/test.vert +++ b/Unicity.Renderer/Resources/vertexShader.vert @@ -1,4 +1,4 @@ -#version 400 core +#version 330 core layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aColor; diff --git a/Unicity.Renderer/Shader.cs b/Unicity.Renderer/Shader.cs index 31dcef7..de2b191 100644 --- a/Unicity.Renderer/Shader.cs +++ b/Unicity.Renderer/Shader.cs @@ -1,6 +1,6 @@ using System; using OpenTK; -using OpenTK.Graphics.OpenGL4; +using OpenTK.Graphics.OpenGL; namespace Unicity.Renderer { diff --git a/Unicity.Renderer/Unicity.Renderer.csproj b/Unicity.Renderer/Unicity.Renderer.csproj index 2e8a049..4e5bc8a 100644 --- a/Unicity.Renderer/Unicity.Renderer.csproj +++ b/Unicity.Renderer/Unicity.Renderer.csproj @@ -51,6 +51,11 @@ + + True + True + Resources.resx + @@ -59,12 +64,14 @@ - - Always - - - Always - + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + \ No newline at end of file