SubC.AllegroDotNet
0.9.2
See the version list below for details.
dotnet add package SubC.AllegroDotNet --version 0.9.2
NuGet\Install-Package SubC.AllegroDotNet -Version 0.9.2
<PackageReference Include="SubC.AllegroDotNet" Version="0.9.2" />
paket add SubC.AllegroDotNet --version 0.9.2
#r "nuget: SubC.AllegroDotNet, 0.9.2"
// Install SubC.AllegroDotNet as a Cake Addin #addin nuget:?package=SubC.AllegroDotNet&version=0.9.2 // Install SubC.AllegroDotNet as a Cake Tool #tool nuget:?package=SubC.AllegroDotNet&version=0.9.2
AllegroDotNet
❓ What is it?
The AllegroDotNet project aims to make the Allegro 5 game programming library available in C# and feel .NET-like. Using AllegroDotNet will allow you to create game and multimedia applications in C#.
⭐ Requirements
- Target x64 architecture (at least, for now)
- Native Allegro library available (example
allegro-5.2.dll
/allegro_monolith-5.2.dll
, see Quick Start)
💥 Quick Start (Windows)
Add NuGet package references to SubC.AllegroDotNet and SubC.AllegroDotNet.Win64.
Add the following test code to your source code:
using SubC.AllegroDotNet;
// ...
Al.Init();
var display = Al.CreateDisplay(1280, 720) ?? throw new Exception();
Al.Rest(3);
Al.DestroyDisplay(display);
Al.UninstallSystem();
- Compile and run.
For more example code, see the Source/Ex.<whatever>
projects such as Source/Ex.Camera/
.
🔥 Slow Start
AllegroDotNet is a wrapper for the native Allegro 5 library. Care was taken to make Allegro feel more like .NET and not a wrapper library generated by a tool that requires you to pass around IntPtr
everywhere.
You must provide the native Allegro 5 library, but the NuGet package SubC.AllegroDotNet.Win64
can do that for you if you add it to your project (if targeting Windows).
All the existing documentation for Allegro 5 is still valid with AllegroDotNet; for example, you still have to first call al_init()
(in AllegroDotNet: Al.Init()
), then you can make your display with al_create_display()
(in AllegroDotNet: Al.CreateDisplay()
), etc.
Things like the concept of the thread that created the display is the thread that owns it is still correct (just like when using Allegro in C); there is not too much of a difference between using C# with AllegroDotNet to run Allegro or C/C++ code.
See below for more differences between Allegro and AllegroDotNet.
💾 Native Allegro 5 Library
AllegroDotNet is only an interop wrapper for the native Allegro 5 library; you still need to provide the native Allegro 5 binary library. For convience, you can use the SubC.AllegroDotNet.Win64
NuGet package if you are targeting Windows to automatically add the monolith .DLL to your project's output.
The Allegro 5 library filenames should not be modified from the defaults, such as allegro_monolith-5.2.dll
(Windows).
The native Allegro library may require a runtime for your target platform, such as the Visual C++ Redistributable vc_redist.x64.exe
on Windows. Your development machine may already have this installed, but other machines may not.
This is a requirement you can forget about when testing on other machines.
The method Al.Init()
tries to initialize Allegro with any known versions in the LibraryVersion
enumeration. If you want/need to specify the version, you need to call Al.InstallSystem()
instead.
When specifying the version of Allegro 5 with Al.InstallSystem()
, you can provide either an integer of the version as per usual from C, or use the enumeration LibraryVersion
to specify some well-known versions such as 5.2.8 (LibraryVersion.V528
).
📰 Differences Between Allegro and AllegroDotNet
All Allegro functions are provided in the
Al
static class (example:Al.InstallKeyboard()
).Most Allegro 5 opaque types (example:
ALLEGRO_BITMAP*
) are turned into classes (example:AllegroBitmap
). They are located in theSubC.AllegroDotNet.Models
namespace.The remaining Allegro 5 types (example:
ALLEGRO_COLOR
) are turned into structures (example:AllegroColor
). You will often need to pass them with theref
keyword to facilitate marshalling them to the native C library correctly and quickly.Allegro 5 constant values (example:
ALLEGRO_NO_PRESERVE_TEXTURE
) are grouped into enumerations (example:BitmapFlags.NoPreserveTexture
). These enumerations are in theSubC.AllegroDotNet.Enums
namespace.Allegro 5 macros (example:
ALLEGRO_BPS_TO_SECS(x)
) are turned into static methods (example:Al.BpsToSecs(x)
).The method
Al.Init()
only is aware of versions in theLibraryVersion
enumeration. If you need to initialize a version of Allegro not in this enumeration, you need to callAl.InstallSystem()
with the correct integer parameter (same as from C code).When calling
Al.InitUserEventSource()
, native memory is allocated for the event source. When you are done with the event source, callAl.DestroyUserEventSource()
. This is different than native Allegro 5 where theALLEGRO_EVENT_SOURCE
is allocated by the user, instead of the API methods.If the Allegro function takes or returns a string, that involves extra marshalling from managed/unmanaged code. While this isn't "slow", it isn't as fast as passing pointers and numbers around.
📝 Custom Interop Providers
AllegroDotNet has built in interop providers for Windows, OS X, and Linux. These providers define 3 things:
- The well-known filenames of the Allegro 5 library.
- A method that will load a library and return the native pointer to it.
- A method that will return the native pointer to a function in the Allegro 5 library.
You can make your own custom interop provider if you want to have custom Allegro 5 library filenames or add support for a platform not already present. To use your own interop provider:
- Make a class that implements the
SubC.AllegroDotNet.Native.IInteropProvider
interface (see the existing interop providers for examples). - Call
Al.SetupInteropProvider()
before you call any Allegro function. - Call Allegro functions (ex:
Al.InstallSystem()
) like usual.
⚠️ Troubleshooting
If you get "unbalanced stack" errors, ensure your application is targeting
x64
architecture.AnyCPU
orx86
will not work.If calling
Al.InstallSystem()
is failing, ensure the version of Allegro 5 you are trying to load is available. You cannot load Allegro 5.2.8 if you passLibraryVersion.V529
(5.2.9) toAl.InstallSystem()
. Also ensure the library files (ie, .DLL files on Windows) are available to your executable.If you get "missing function" errors, you may be using a native version of Allegro 5 that does not have functions available that are expected by AllegroDotNet. For example, if you did not include audio or acodec support in your Allegro 5 library, but you try to use any of those functions, you will get an error.
You may get errors if your native library files do not have their dependencies available or are not statically linked. You can solve this by providing the needed libraries (flac.dll, zlib.dll, etc) or by using a statically-linked native Allegro library.
❌ Unimplemented Routines
- Any function marked as "Unstable API" - I will add these functions if they become non-unstable.
- Haptic functions - These are marked as unstable in Allegro 5.2.9.
- PhysFS addon - This would also require wrapping the PhysFS library.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
0.10.0 | 106 | 9/2/2024 | |
0.9.4 | 103 | 8/27/2024 | |
0.9.3 | 128 | 8/24/2024 | |
0.9.2 | 117 | 8/11/2024 | |
0.9.1 | 146 | 5/4/2024 | |
0.9.0 | 299 | 2/17/2024 | |
0.8.2 | 597 | 10/3/2023 | |
0.8.1-pre | 656 | 7/22/2023 | |
0.7.10 | 579 | 10/2/2023 | |
0.7.9 | 810 | 4/8/2023 | |
0.7.2 | 949 | 1/15/2023 | |
0.7.1 | 963 | 12/10/2022 | |
0.6.42 | 1,116 | 9/10/2022 | |
0.6.39 | 1,165 | 8/21/2022 | |
0.6.38 | 1,143 | 8/14/2022 | |
0.6.33 | 903 | 8/13/2022 | |
0.6.28 | 928 | 6/25/2022 | |
0.6.22 | 926 | 6/18/2022 | |
0.6.6 | 893 | 6/13/2022 | |
0.6.6-debug | 612 | 6/13/2022 | |
0.6.5 | 908 | 6/12/2022 | |
0.6.5-debug | 677 | 6/12/2022 | |
0.6.1 | 914 | 6/10/2022 | |
0.6.1-debug | 632 | 6/10/2022 | |
0.5.42 | 863 | 5/30/2022 | |
0.5.42-debug | 675 | 5/30/2022 | |
0.5.41 | 928 | 5/14/2022 | |
0.5.41-debug | 662 | 5/14/2022 | |
0.5.39 | 913 | 5/13/2022 | |
0.5.39-debug | 623 | 5/13/2022 | |
0.5.38 | 907 | 5/12/2022 | |
0.5.38-debug | 646 | 5/12/2022 | |
0.5.37 | 933 | 5/10/2022 | |
0.5.37-debug | 641 | 5/10/2022 | |
0.5.36 | 890 | 5/8/2022 | |
0.5.36-debug | 625 | 5/8/2022 | |
0.5.28 | 901 | 4/30/2022 | |
0.5.28-debug | 664 | 4/30/2022 |
Add .NET8 target. Small bug fixes.