diff --git a/.gitignore b/.gitignore index 940794e..bcf91b8 100644 --- a/.gitignore +++ b/.gitignore @@ -286,3 +286,12 @@ __pycache__/ *.btm.cs *.odx.cs *.xsd.cs + + + +# +# Ignores for FNA-Template +# +# Ignore the libs directory (user will add it themselves) +FNALibs + diff --git a/CreateTemplate/CreateTemplate.csproj b/CreateTemplate/CreateTemplate.csproj new file mode 100644 index 0000000..7d5e9f5 --- /dev/null +++ b/CreateTemplate/CreateTemplate.csproj @@ -0,0 +1,57 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {F6DF8289-8138-41C7-B747-E672AFEE44A4} + Exe + Properties + CreateTemplate + CreateTemplate + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CreateTemplate/Program.cs b/CreateTemplate/Program.cs new file mode 100644 index 0000000..d75645b --- /dev/null +++ b/CreateTemplate/Program.cs @@ -0,0 +1,166 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; + +namespace CreateTemplate +{ + class Program + { + static void Main(string[] args) + { + // Validate command line: + if(args.Length == 0 || args.Length != (args[0] == "--template" ? 4 : 3)) + { + Console.WriteLine("Usage:"); + Console.WriteLine(" CreateTemplate [--template] "); + Console.WriteLine(); + Console.WriteLine("The output will be placed in the folder at " + Path.DirectorySeparatorChar + ""); + Console.WriteLine(); + Console.WriteLine("Options:"); + Console.WriteLine(" --template: Generate a Visual Studio compatible project template."); + Console.WriteLine(); + return; + } + + + bool vsTemplate = args[0] == "--template"; + string projectName = args[vsTemplate ? 1 : 0]; + string sourceDirectory = Path.GetFullPath(args[vsTemplate ? 2 : 1]); + string destinationDirectory = Path.GetFullPath(args[vsTemplate ? 3 : 2]); + + if(!Directory.Exists(sourceDirectory)) + { + Console.WriteLine("ERROR: Source directory not found!"); + return; + } + + if(!File.Exists(Path.Combine(sourceDirectory, "FNATemplate.csproj"))) + { + Console.WriteLine("ERROR: Source directory is missing \"FNATemplate.csproj\""); + return; + } + + if(destinationDirectory.StartsWith(sourceDirectory)) // <- Probably not the most robust way to do this... + { + Console.WriteLine("ERROR: Destination directory is contained with the source directory!"); + return; + } + + + + // And off we go... + + string projectDirectory = Path.Combine(destinationDirectory, projectName); + Directory.CreateDirectory(projectDirectory); + StreamWriter templateFile = null; + + if(vsTemplate) + { + templateFile = new StreamWriter(Path.Combine(projectDirectory, projectName + ".vstemplate")); + templateFile.WriteLine(""); + templateFile.WriteLine(" "); + templateFile.WriteLine(" FNA Game Project"); + templateFile.WriteLine(" A cross-platform game project using FNA."); + templateFile.WriteLine(" CSharp"); + templateFile.WriteLine(" 1"); + templateFile.WriteLine(" "); + templateFile.WriteLine(" "); + templateFile.WriteLine(" 43900"); + templateFile.WriteLine(" true"); + templateFile.WriteLine(" true"); // <- Required because we have relative import paths in the project file! + templateFile.WriteLine(" MyFNAGameProject"); + templateFile.WriteLine(" true"); + templateFile.WriteLine(" Enabled"); + templateFile.WriteLine(" true"); + //templateFile.WriteLine(" __TemplateIcon.png"); + //templateFile.WriteLine(" __PreviewImage.png"); + templateFile.WriteLine(" "); + templateFile.WriteLine(" "); + templateFile.WriteLine(" "); + } + + string binDir = Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar; + string objDir = Path.DirectorySeparatorChar + "obj" + Path.DirectorySeparatorChar; + string binDirFirst = "bin" + Path.DirectorySeparatorChar; + string objDirFirst = "obj" + Path.DirectorySeparatorChar; + + foreach(var inputPath in Directory.EnumerateFiles(sourceDirectory, "*.*", SearchOption.AllDirectories)) + { + string localPath = inputPath.Substring(sourceDirectory.EndsWith(Path.DirectorySeparatorChar.ToString()) ? sourceDirectory.Length : sourceDirectory.Length + 1); + + if(localPath.Contains(binDir) || localPath.Contains(objDir) || localPath.StartsWith(binDirFirst) || localPath.StartsWith(objDirFirst)) + { + continue; + } + + string outputLocalPath = localPath.Replace("FNATemplate", projectName); + + // NOTE: "GetFileName" here is because VS bizarrely combines the path from the ProjectItem AND the TargetFileName + string templateTargetFileName = Path.GetFileName(localPath).Replace("FNATemplate", "$safeprojectname$"); + + string outputPath = Path.Combine(projectDirectory, outputLocalPath); + Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); + + // Quick'n'dirty text replacement: + bool replaceParameters; + if(outputLocalPath.EndsWith(".csproj")) + { + var lines = File.ReadAllLines(inputPath); + for(int i = 0; i < lines.Length; i++) + { + if(lines[i].Contains("")) + lines[i] = " " + (vsTemplate ? "$guid1$" : Guid.NewGuid().ToString()) + ""; + else if(lines[i].Contains("FNATemplate")) + lines[i] = lines[i].Replace("FNATemplate", vsTemplate ? "$safeprojectname$" : projectName); + } + File.WriteAllLines(outputPath, lines); + + replaceParameters = true; + } + else if(localPath.EndsWith(".cs")) + { + var lines = File.ReadAllLines(inputPath); + for(int i = 0; i < lines.Length; i++) + { + if(lines[i].Contains("[assembly: Guid(")) + lines[i] = "[assembly: Guid(\"" + (vsTemplate ? "$guid2$" : Guid.NewGuid().ToString()) + "\")]"; + else if(lines[i].Contains("FNATemplate")) + lines[i] = lines[i].Replace("FNATemplate", vsTemplate ? "$safeprojectname$" : projectName); + } + File.WriteAllLines(outputPath, lines); + + replaceParameters = true; + } + else // All other files + { + File.Copy(inputPath, outputPath, true); + replaceParameters = false; + } + + if(vsTemplate) + { + templateFile.Write(" "); + templateFile.Write(outputLocalPath); + templateFile.WriteLine(""); + } + } + + + if(vsTemplate) + { + templateFile.WriteLine(" "); + templateFile.WriteLine(" "); + templateFile.WriteLine(""); + templateFile.Close(); + } + + } + } +} diff --git a/CreateTemplate/Properties/AssemblyInfo.cs b/CreateTemplate/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5ba7067 --- /dev/null +++ b/CreateTemplate/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CreateTemplate")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CreateTemplate")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("eb5275ca-9920-41cf-aa32-442e77dbed09")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/FNATemplate.sln b/FNATemplate.sln new file mode 100644 index 0000000..8fec249 --- /dev/null +++ b/FNATemplate.sln @@ -0,0 +1,63 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FNATemplate", "FNATemplate\FNATemplate.csproj", "{D488C5AD-5192-4A08-88FD-22219586ED9F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FNA", "FNA\FNA.csproj", "{35253CE1-C864-4CD3-8249-4D1319748E8F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreateTemplate", "CreateTemplate\CreateTemplate.csproj", "{F6DF8289-8138-41C7-B747-E672AFEE44A4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D488C5AD-5192-4A08-88FD-22219586ED9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D488C5AD-5192-4A08-88FD-22219586ED9F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D488C5AD-5192-4A08-88FD-22219586ED9F}.Debug|x86.ActiveCfg = Debug|x86 + {D488C5AD-5192-4A08-88FD-22219586ED9F}.Debug|x86.Build.0 = Debug|x86 + {D488C5AD-5192-4A08-88FD-22219586ED9F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D488C5AD-5192-4A08-88FD-22219586ED9F}.Release|Any CPU.Build.0 = Release|Any CPU + {D488C5AD-5192-4A08-88FD-22219586ED9F}.Release|x86.ActiveCfg = Release|x86 + {D488C5AD-5192-4A08-88FD-22219586ED9F}.Release|x86.Build.0 = Release|x86 + {35253CE1-C864-4CD3-8249-4D1319748E8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {35253CE1-C864-4CD3-8249-4D1319748E8F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {35253CE1-C864-4CD3-8249-4D1319748E8F}.Debug|x86.ActiveCfg = Debug|Any CPU + {35253CE1-C864-4CD3-8249-4D1319748E8F}.Debug|x86.Build.0 = Debug|Any CPU + {35253CE1-C864-4CD3-8249-4D1319748E8F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {35253CE1-C864-4CD3-8249-4D1319748E8F}.Release|Any CPU.Build.0 = Release|Any CPU + {35253CE1-C864-4CD3-8249-4D1319748E8F}.Release|x86.ActiveCfg = Release|Any CPU + {35253CE1-C864-4CD3-8249-4D1319748E8F}.Release|x86.Build.0 = Release|Any CPU + {F6DF8289-8138-41C7-B747-E672AFEE44A4}.Debug|Any CPU.ActiveCfg = Debug|x86 + {F6DF8289-8138-41C7-B747-E672AFEE44A4}.Debug|Any CPU.Build.0 = Debug|x86 + {F6DF8289-8138-41C7-B747-E672AFEE44A4}.Debug|x86.ActiveCfg = Debug|x86 + {F6DF8289-8138-41C7-B747-E672AFEE44A4}.Debug|x86.Build.0 = Debug|x86 + {F6DF8289-8138-41C7-B747-E672AFEE44A4}.Release|Any CPU.ActiveCfg = Release|x86 + {F6DF8289-8138-41C7-B747-E672AFEE44A4}.Release|Any CPU.Build.0 = Release|x86 + {F6DF8289-8138-41C7-B747-E672AFEE44A4}.Release|x86.ActiveCfg = Release|x86 + {F6DF8289-8138-41C7-B747-E672AFEE44A4}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + Policies = $0 + $0.TextStylePolicy = $1 + $1.scope = text/x-csharp + $1.FileWidth = 80 + $1.TabsToSpaces = True + $1.inheritsSet = null + $0.CSharpFormattingPolicy = $2 + $2.scope = text/x-csharp + $2.SpaceAfterControlFlowStatementKeyword = False + $0.TextStylePolicy = $3 + $3.FileWidth = 80 + $3.TabsToSpaces = True + $3.EolMarker = Unix + $3.scope = text/plain + $0.StandardHeader = $4 + EndGlobalSection +EndGlobal diff --git a/FNATemplate/Content/Content.mgcb b/FNATemplate/Content/Content.mgcb new file mode 100644 index 0000000..43151b0 --- /dev/null +++ b/FNATemplate/Content/Content.mgcb @@ -0,0 +1,34 @@ + +#----------------------------- Global Properties ----------------------------# + +/outputDir:bin/Windows +/intermediateDir:obj/Windows +/platform:Windows +/config: +/profile:HiDef +/compress:False + +#-------------------------------- References --------------------------------# + + +#---------------------------------- Content ---------------------------------# + +#begin Font.spritefont +/importer:FontDescriptionImporter +/processor:FontDescriptionProcessor +/processorParam:PremultiplyAlpha=True +/processorParam:TextureFormat=Color +/build:Font.spritefont + +#begin Smile.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Smile.png + diff --git a/FNATemplate/Content/Font.spritefont b/FNATemplate/Content/Font.spritefont new file mode 100644 index 0000000..73a4451 --- /dev/null +++ b/FNATemplate/Content/Font.spritefont @@ -0,0 +1,60 @@ + + + + + + + Roboto/Roboto-Regular.ttf + + + 18 + + + 0 + + + true + + + + + + ? + + + + + + ~ + + + + diff --git a/FNATemplate/Content/Roboto/LICENSE.txt b/FNATemplate/Content/Roboto/LICENSE.txt new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/FNATemplate/Content/Roboto/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/FNATemplate/Content/Roboto/Roboto-Regular.ttf b/FNATemplate/Content/Roboto/Roboto-Regular.ttf new file mode 100644 index 0000000..2c97eea Binary files /dev/null and b/FNATemplate/Content/Roboto/Roboto-Regular.ttf differ diff --git a/FNATemplate/Content/Smile.png b/FNATemplate/Content/Smile.png new file mode 100644 index 0000000..5156870 Binary files /dev/null and b/FNATemplate/Content/Smile.png differ diff --git a/FNATemplate/Effects/ExampleEffect.fx b/FNATemplate/Effects/ExampleEffect.fx new file mode 100644 index 0000000..90c4bcb --- /dev/null +++ b/FNATemplate/Effects/ExampleEffect.fx @@ -0,0 +1,20 @@ + +// A simple example effect for FNA-Template. + + +sampler TextureSampler : register(s0); + +float4 PixelShaderFunction(float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0 +{ + float4 tex = tex2D(TextureSampler, texCoord); + + return tex * float4(texCoord.x, texCoord.y, 1, 1); +} + +technique Technique1 +{ + pass Pass1 + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} diff --git a/FNATemplate/FNATemplate.csproj b/FNATemplate/FNATemplate.csproj new file mode 100644 index 0000000..e4100dd --- /dev/null +++ b/FNATemplate/FNATemplate.csproj @@ -0,0 +1,96 @@ + + + + + Debug + x86 + 8.0.30703 + 2.0 + {D488C5AD-5192-4A08-88FD-22219586ED9F} + WinExe + Properties + FNATemplate + FNATemplate + v4.0 + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + true + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + true + + + + + + true + bin\Debug\ + DEBUG;TRACE + full + AnyCPU + prompt + true + + + bin\Release\ + TRACE + true + pdbonly + AnyCPU + prompt + true + + + + + + + + + + + + + + {35253CE1-C864-4CD3-8249-4D1319748E8F} + FNA + + + + + + + + + + + Windows + + + + + + + \ No newline at end of file diff --git a/FNATemplate/FNATemplateGame.cs b/FNATemplate/FNATemplateGame.cs new file mode 100644 index 0000000..f40ee3a --- /dev/null +++ b/FNATemplate/FNATemplateGame.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace FNATemplate +{ + class FNATemplateGame : Game + { + GraphicsDeviceManager graphics; + + public FNATemplateGame() + { + graphics = new GraphicsDeviceManager(this); + graphics.PreferredBackBufferWidth = 1280; + graphics.PreferredBackBufferHeight = 720; + graphics.PreferMultiSampling = true; + Content.RootDirectory = "Content"; + + Window.AllowUserResizing = true; + IsMouseVisible = true; + } + + + SpriteBatch spriteBatch; + SpriteFont font; + Texture2D smile; + Effect exampleEffect; + + protected override void LoadContent() + { + spriteBatch = new SpriteBatch(GraphicsDevice); + + // Most content can be loaded from MonoGame Content Builder projects. + // (Note how "Content.mgcb" has the Build Action "MonoGameContentReference".) + font = Content.Load("Font"); + smile = Content.Load("smile"); + + // Effects need to be loaded from files built by fxc.exe from the DirectX SDK (June 2010) + // (Note how each .fx file has the Build Action "CompileShader", which produces a .fxb file.) + exampleEffect = new Effect(GraphicsDevice, File.ReadAllBytes(@"Effects/ExampleEffect.fxb")); + + base.LoadContent(); + } + + + protected override void Update(GameTime gameTime) + { + // Insert your game update logic here. + + base.Update(gameTime); + } + + + protected override void Draw(GameTime gameTime) + { + // Replace this with your own drawing code. + + GraphicsDevice.Clear(Color.CornflowerBlue); + + spriteBatch.Begin(); + spriteBatch.DrawString(font, "Insert awesome game here!", new Vector2(20, 20), Color.White); + spriteBatch.End(); + + spriteBatch.Begin(0, null, null, null, null, exampleEffect); + spriteBatch.Draw(smile, new Vector2(20, 60), Color.White); + spriteBatch.End(); + + base.Draw(gameTime); + } + + } +} diff --git a/FNATemplate/Program.cs b/FNATemplate/Program.cs new file mode 100644 index 0000000..7e842ff --- /dev/null +++ b/FNATemplate/Program.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Diagnostics; +using System.IO; +using System.Runtime.InteropServices; + +namespace FNATemplate +{ + class Program + { + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool SetDllDirectory(string lpPathName); + + + static void Main(string[] args) + { + // https://github.com/FNA-XNA/FNA/wiki/4:-FNA-and-Windows-API#64-bit-support + if(Environment.OSVersion.Platform == PlatformID.Win32NT) + { + SetDllDirectory(Path.Combine( + AppDomain.CurrentDomain.BaseDirectory, + Environment.Is64BitProcess ? "x64" : "x86" + )); + } + + // https://github.com/FNA-XNA/FNA/wiki/7:-FNA-Environment-Variables#fna_graphics_enable_highdpi + // NOTE: from documentation: + // Lastly, when packaging for macOS, be sure this is in your app bundle's Info.plist: + // NSHighResolutionCapable + // True + Environment.SetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI", "1"); + + using(FNATemplateGame game = new FNATemplateGame()) + { + bool isHighDPI = Environment.GetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI") == "1"; + if(isHighDPI) + Debug.WriteLine("HiDPI Enabled"); + + game.Run(); + } + } + } +} diff --git a/FNATemplate/Properties/AssemblyInfo.cs b/FNATemplate/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0315d3e --- /dev/null +++ b/FNATemplate/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FNATemplate")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FNATemplate")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("68e63d4e-84c3-4440-a5dd-f6e0991142ca")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/README.md b/README.md index ce20b9a..7a6d976 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,121 @@ -# FNA-Template -A simple template for FNA game projects. +FNA Template +============ + +FNA Template is a quick, easy and robust way to start new projects using FNA (http://fna-xna.github.io/), Ethan Lee's excellent reimplementation of Microsoft XNA Game Studio. + +It has been tested with Visual Studio 2010 (on Windows) and Visual Studio Community 2017 (on OSX). But it should run on other versions of Visual Studio, or directly with MSBuild. + +It uses MonoGame's content pipeline for building assets (except shaders), but does not use MonoGame at runtime. It does NOT require XNA or XNA Game Studio. + +FNA Template is released under the Microsoft Public License. (Note that this is the same license as FNA). + + +Getting Started +=============== + +To use FNA Template you will need to install the following: + +- MonoGame (tested with MonoGame 3.6) from http://www.monogame.net/ for building content +- DirectX SDK (June 2010) from https://www.microsoft.com/en-us/download/details.aspx?id=6812 for building shaders + +Building shaders on OSX +----------------------- + +On OSX, the DirectX SDK is still required (and we need wine to help). Here is how to install it: + +- Install Homebrew from https://brew.sh/ +- Install wine with `brew install wine` +- Install winetricks with `brew install winetricks` +- (If you already have these installed, update with `brew update`, `brew upgrade wine` `brew upgrade winetricks`) +- Setup wine with `winecfg` +- Install the DirectSDK with `winetricks dxsdk_jun2010` + +NOTE: At time of writing there is a bug in winetricks that will cause the DirectX SDK to not install correctly. See https://github.com/Winetricks/winetricks/issues/841 + +You can either modify your winetricks to fix that bug (`which winetricks`, and then find and replace the broken hash value), or use `winetricks d3dcompiler_43` instead and put a copy of `fxc.exe` from the DirectX SDK in the `builds/tools` directory (see `BuildShaders.targets` for details). + +Required FNA components +----------------------- + +You need to add the following directories at the same level as the solution file: + +- "FNA" containing the FNA project from https://github.com/FNA-XNA/FNA +- "FNALibs" containing the FNA libraries from http://fna.flibitijibibo.com/archive/fnalibs.tar.bz2 + +At this point you should be able to open the solution file, and build and run the FNATemplate project. + +Debugging on OSX +---------------- + +In order to run in the debugger on Visual Studio on OSX, you will need to add an environment variable: + +- Right click the FNATemplate project +- Options +- Run -> Configurations -> Default +- Environment Variables -> Add +- "DYLD_LIBRARY_PATH" "./osx/" + +You will need to repeat these steps for any new projects you create from the template (because they are per-user debugging settings, not part of the project file). + +Using the CreateTemplate tool +----------------------------- + +Use the CreateTemplate tool to create new versions of the FNATemplate (NOTE: Including any local modifications). This is easier than copying the files and fixing up names and GUIDs by hand. + +The command line is: + +`CreateTemplate [--template] ` + +You can use it to directly create new projects: + +`CreateTemplate NewProject "X:\pathToThisSolution\FNATemplate" "X:\yourSolution\NewProject"` + +Or you can create a Visual Studio template file, which itself can be used to create projects. + +`CreateTemplate --template FNATemplate "X:\pathToThisSolution\FNATemplate" .` + +To install the generated template in Visual Studio: + +- Go to the output folder (containing the resulting .vstemplate file) +- Select all files in that folder (Ctrl + A) +- Add them to a zip (Right click -> Send To -> Compressed (zipped) folder) +- Move that zip file to the project templates directory for your platform (eg: "C:\Users\\Documents\Visual Studio 2010\Templates\ProjectTemplates\Visual C#") + +(NOTE: Ensure that the .vstemplate file is at the root of the resulting .zip file. Otherwise the template will not work.) + +Note that the template requires the "FNA" and "FNALibs" directories as specified above, as well as the "build" directory. You will also need to add the FNA project to your solution. + + +Building and loading shaders +============================ + +FNA Template uses fxc.exe (from the DirectX SDK) to build shaders, rather than using a content pipleine. This produces raw .fxb files rather than the usual .xnb content files. + +To add .fx (shader source) files to your project, add them and then set their Build Action to "Compile Shader" in the Properties window (typically the F4 key). (Set "Copy to Output Directory" to "Do not copy".) + +To load a shader, read it directly from the .fxb file. For example: + +`myEffect = new Effect(GraphicsDevice, File.ReadAllBytes(@"Effects/MyEffect.fxb"));` + +An example shader is included in FNATemplate. + +Note that if you are not creating your own shaders, you can safely delete the shader file and associated code from the template, and skip installing the DirectX SDK. + + +Building and loading other content +================================== + +Other content is built using the MonoGame Content Pipeline. The .mgcb file in the template can be opened with the MonoGame Content Pipeline Tool. + +Unlike MonoGame, simply create the content for the Windows platform. + +Load content the same as you would with XNA or MonoGame. For example: + +`font = Content.Load("Font");` + + +Distributing your game +====================== + +Please refer to https://github.com/FNA-XNA/FNA/wiki/3:-Distributing-FNA-Games + diff --git a/build/BuildShaders.targets b/build/BuildShaders.targets new file mode 100644 index 0000000..2a0186b --- /dev/null +++ b/build/BuildShaders.targets @@ -0,0 +1,78 @@ + + + + + + + + + + + + "$(MSBuildThisFileDirectory)tools\fxc.exe" + + + "$(DXSDK_DIR)\Utilities\bin\x86\fxc.exe" + + + + + + wine "$(MSBuildThisFileDirectory)tools/fxc.exe" + + + wine "$(WINEPREFIX)/drive_c/Program Files/Microsoft DirectX SDK (June 2010)/Utilities/bin/x86/fxc.exe" + wine "$(WINEPREFIX)/drive_c/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Utilities/bin/x86/fxc.exe" + wine "$(HOME)/.wine/drive_c/Program Files/Microsoft DirectX SDK (June 2010)/Utilities/bin/x86/fxc.exe" + wine "$(HOME)/.wine/drive_c/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Utilities/bin/x86/fxc.exe" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PreserveNewest + %(RelativeDir)%(FileName).fxb + + + + + + + diff --git a/build/CopyFNALibs.targets b/build/CopyFNALibs.targets new file mode 100644 index 0000000..4673994 --- /dev/null +++ b/build/CopyFNALibs.targets @@ -0,0 +1,20 @@ + + + + + + x86\%(RecursiveDir)%(Filename)%(Extension) + PreserveNewest + + + x64\%(RecursiveDir)%(Filename)%(Extension) + PreserveNewest + + + osx\%(RecursiveDir)%(Filename)%(Extension) + PreserveNewest + + + + +