SubC.AllegroDotNet
0.8.2
See the version list below for details.
dotnet add package SubC.AllegroDotNet --version 0.8.2
NuGet\Install-Package SubC.AllegroDotNet -Version 0.8.2
<PackageReference Include="SubC.AllegroDotNet" Version="0.8.2" />
paket add SubC.AllegroDotNet --version 0.8.2
#r "nuget: SubC.AllegroDotNet, 0.8.2"
// Install SubC.AllegroDotNet as a Cake Addin #addin nuget:?package=SubC.AllegroDotNet&version=0.8.2 // Install SubC.AllegroDotNet as a Cake Tool #tool nuget:?package=SubC.AllegroDotNet&version=0.8.2
AllegroDotNet
The AllegroDotNet project aims to make the Allegro 5 game programming library to be useable from C# and feel .NET-like. Native C functions, pointers, and structs are wrapped by C# methods and classes and avoid exposing pointers whenever possible.
Using AllegroDotNet will allow you to create game and multimedia applications in C#.
Requirements
- Target x64 architecture (AnyCPU or x86 will not work)
- Native Allegro 5 (v5.2.8) library available (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.InstallSystem(Al.ALLEGRO_VERSION_INT, null);
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 projects in the Source/Examples/
folder.
Differences between Allegro 5 and AllegroDotNet
AllegroDotNet tries to mimic Allegro 5 as closely as possible while also translating the original C library to modern .NET. You can use documentation and tutorials for Allegro 5 with AllegroDotNet, as long as you note the differences between the two:
AllegroDotNet uses .NET-style naming conventions, so Allegro 5's snake casing is turned into pascal casing.
Allegro 5 prefixed all functions with
al_
. AllegroDotNet instead puts all functions into the static classAl
. For example,al_init()
becomesAl.Init()
.Allegro 5 functions are all placed in the static
SubC.AllegroDotNet.Al
class.Allegro 5 pointers (ex:
ALLEGRO_BITMAP*
) are turned into classes (ex:AllegroBitmap
). These classes are all in theSubC.AllegroDotNet.Models
namespace.Allegro 5 constants (ex:
ALLEGRO_NO_PRESERVE_TEXTURE
) are grouped and turned into enumerations (ex:BitmapFlags.NoPreserveTexture
). These enumerations are all in theSubC.AllegroDotNet.Enums
namespace.Allegro 5 macros (ex:
ALLEGRO_BPS_TO_SECS(x)
) are turned into static methods (ex:Al.BpmToSecs(x)
). These static methods are part of theSubC.AllegroDotNet.Al
static class.
Notes about using AllegroDotNet:
Currently AllegroDotNet uses Allegro version 5.2.8.
Older versions of AllegroDotNet loaded the native Allegro functions into delegates via static initialization. This caused issues if you want to handle the case where the native Allegro library is unavailable. In newer versions, the first time
Al.Init()
orAl.InstallSystem()
is called the library is loaded. If you try to invoke any other Allegro methods before this, you will get a null reference exception thrown. If you want to load the library without initializing, callAl.SetupAllegroInterop()
.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.
Not every Allegro 5 function is available (ex: no shader, color addon, or video streaming addon routines). More functions will be added in the future.
No testing has been done on OSX, and minimal testing was done on Linux. Would you want to test it on those platforms?
Troubleshooting
If you get "unbalanced stack" errors, ensure your application is targeting x64 architecture. AnyCPU will not work.
If calling
Al.Init()
is failing, ensure you have the correct version of the Allegro 5 library. Currently, AllegroDotNet requires v5.2.8. See NuGet packages SubC.AllegroDotNet.Win64 or SubC.AllegroDotNet.Linux64 for known working native Allegro libraries to use.AllegroDotNet requires a monolith version of Allegro to be available (ex:
allegro_monolith-5.2.dll
).If you'd rather use the offical Allegro 5 binaries instead of
SubC.AllegroDotNet.Win64
, that is also an option. However, you will need to do the work to make sure the monolith .DLL file is available to your executable (the NuGet package automatically adds the .DLL to your project's output).You will get "missing function" errors if the native Allegro 5 library you are using is missing functions for addons it expects to be available (ex: you compiled your own .DLL and did not include native dialog functions, acodec functions, etc).
You may get additional errors if your .DLL did not have dependencies statically linked. You can solve this by using a static-linked Allegro 5 .DLL (such as from
SubC.AllegroDotNet.Win64
), or place the needed .DLLs with your program output (flac.dll, zlib.dll, etc).
AllegroDotNet.Extensions
This extension project adds object-oriented extension methods to (some of) the AllegroDotNet classes. Example:
Al.RegisterEventSource(myEventSource, Al.GetDisplayEventSource(myDisplay))
becomes
myEventSource.RegisterEventSource(myDisplay.GetDisplayEventSource());
Closing
Thanks to the Allegro team, it's an awesome library that I've been using since the DOS / DJGPP days.
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 was computed. 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.
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 | 103 | 9/2/2024 | |
0.9.4 | 101 | 8/27/2024 | |
0.9.3 | 126 | 8/24/2024 | |
0.9.2 | 115 | 8/11/2024 | |
0.9.1 | 144 | 5/4/2024 | |
0.9.0 | 297 | 2/17/2024 | |
0.8.2 | 579 | 10/3/2023 | |
0.8.1-pre | 654 | 7/22/2023 | |
0.7.10 | 577 | 10/2/2023 | |
0.7.9 | 808 | 4/8/2023 | |
0.7.2 | 947 | 1/15/2023 | |
0.7.1 | 961 | 12/10/2022 | |
0.6.42 | 1,114 | 9/10/2022 | |
0.6.39 | 1,163 | 8/21/2022 | |
0.6.38 | 1,141 | 8/14/2022 | |
0.6.33 | 901 | 8/13/2022 | |
0.6.28 | 926 | 6/25/2022 | |
0.6.22 | 924 | 6/18/2022 | |
0.6.6 | 874 | 6/13/2022 | |
0.6.6-debug | 595 | 6/13/2022 | |
0.6.5 | 906 | 6/12/2022 | |
0.6.5-debug | 657 | 6/12/2022 | |
0.6.1 | 912 | 6/10/2022 | |
0.6.1-debug | 630 | 6/10/2022 | |
0.5.42 | 861 | 5/30/2022 | |
0.5.42-debug | 662 | 5/30/2022 | |
0.5.41 | 926 | 5/14/2022 | |
0.5.41-debug | 660 | 5/14/2022 | |
0.5.39 | 911 | 5/13/2022 | |
0.5.39-debug | 621 | 5/13/2022 | |
0.5.38 | 905 | 5/12/2022 | |
0.5.38-debug | 642 | 5/12/2022 | |
0.5.37 | 931 | 5/10/2022 | |
0.5.37-debug | 639 | 5/10/2022 | |
0.5.36 | 888 | 5/8/2022 | |
0.5.36-debug | 623 | 5/8/2022 | |
0.5.28 | 899 | 4/30/2022 | |
0.5.28-debug | 662 | 4/30/2022 |
This release adds the Allegro File I/O routines.