sbyte*
, delegate* < ... >
and pass-thought.dotnet add package DeafMan1983.Interop.SDL2
dotnet add package DeafMan1983.Conversion
And open code ( Visual Studio Code )<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PublishAOT>true</PublishAOT>
<StripSymbols>true</StripSymbols>
Open your Program.cs
namespace YourGame;
using static DeafMan1983.Conversion;
using DeafMan1983.Interop.SDL2;
using static DeafMan1983.Interop.SDL2.SDL;
unsafe class Program
{
private SDL_Window* window;
private SDL_Renderer* renderer;
private SDL_Event evt;
// Add init main(int, sbyte**)
}
And why do I add manual function like in C/C++ because somebody understands better.
public int main(int argc, sbyte** argv)
{
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
{
Console.WriteLine("Error: SDL initializing. {0}.\n", StringFromSBytePointer(SDL_GetError()));
return -1;
}
Console.WriteLine("Woohoo! SDL2 initializes.\n");
window = SDL_CreateWindow(SBytePointerFromString("Hello SDL2"), (int)SDL_WINDOWPOS_CENTERED, (int)SDL_WINDOWPOS_CENTERED, 600, 400, (uint)SDL_WindowFlags.SDL_WINDOW_SHOWN | (uint)SDL_WindowFlags.SDL_WINDOW_OPENGL);
if (window == null)
{
Console.WriteLine("Error: Creating SDL_Window {0}.\n", StringFromSBytePointer(SDL_GetError()));
return -1;
}
renderer = SDL_CreateRenderer(window, -1, (uint)SDL_RendererFlags.SDL_RENDERER_SOFTWARE);
if (renderer == null)
{
Console.WriteLine("Error: Creating SDL_Renderer {0}.\n", StringFromSBytePointer(SDL_GetError()));
return -1;
}
while (true)
{
/*
WARNING: You need add fixed statement = It works fine :D
*/
fixed (SDL_Event* evtptrs = &evt)
{
if (SDL_PollEvent(evtptrs) > 0)
{
if (evt.type == (uint)SDL_EventType.SDL_QUIT)
{
Console.WriteLine("Click with frame window!\n");
break;
}
if (evt.type == (uint)SDL_EventType.SDL_KEYDOWN)
{
if (evt.key.keysym.sym == SDL_KeyCode.SDLK_ESCAPE)
{
Console.WriteLine("Press key Escape!\n");
break;
}
}
}
}
SDL_SetRenderDrawColor(renderer, 255, 255 /3, 0, 255);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
}
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
// static int Main(string[] args)
We add end of static Main function for C#.
static int Main(string[] args)
{
// Reforce with default main function into static int Main() for C#
Program game = new();
return game.main(args.Length, SByteDoublePointersFromStringArray(args));
}
Compile and check:
And try to use native executable:dotnet publish -c Release -r <rid> --self-contained=true
DeafMan1983.Interop.GLFW3
, DeafMan1983.Interop.SDL2
and X11'S GL ( glx ) and other desktop environmentsYou must log in to post a comment. You can login or register a new account.