Skip to content

Instantly share code, notes, and snippets.

@thatcosmonaut
Created March 11, 2020 22:04
Show Gist options
  • Save thatcosmonaut/2ce0de2fd659ee702ce23bbf3f0790be to your computer and use it in GitHub Desktop.
Save thatcosmonaut/2ce0de2fd659ee702ce23bbf3f0790be to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace SamuraiGunn2
{
/// <summary>
/// The main class.
/// </summary>
public static class Program
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetDefaultDllDirectories(int directoryFlags);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern void AddDllDirectory(string lpPathName);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetDllDirectory(string lpPathName);
const int LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000;
static void Main(string[] args)
{
#if NETCOREAPP
DllMap.Initialise(false);
#endif
// https://github.com/FNA-XNA/FNA/wiki/4:-FNA-and-Windows-API#64-bit-support
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
try
{
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
AddDllDirectory(Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
Environment.Is64BitProcess ? "x64" : "x86"
));
}
catch
{
// Pre-Windows 7, KB2533623
SetDllDirectory(Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
Environment.Is64BitProcess ? "x64" : "x86"
));
}
}
// TODO: figure out why metal rendering causes a black screen
var OSVersion = SDL2.SDL.SDL_GetPlatform();
if (OSVersion.Equals("Mac OS X"))
{
// 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:
// <key>NSHighResolutionCapable</key>
// <string>True</string>
Environment.SetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI", "1");
Environment.SetEnvironmentVariable("FNA_GRAPHICS_FORCE_GLDEVICE", "MetalDevice");
Environment.SetEnvironmentVariable("METAL_DEVICE_WRAPPER_TYPE", "1");
}
bool isHighDPI = Environment.GetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI") == "1";
if (isHighDPI)
System.Console.WriteLine("HiDPI Enabled");
using var game = new SamuraiGunnGame();
game.Run();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment