From b13ad306d88d7af65c68589c6a3a3784bb0e5b38 Mon Sep 17 00:00:00 2001 From: moonpower Date: Mon, 3 Feb 2025 21:06:41 +0000 Subject: [PATCH] Add README.md --- README.md | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..5570f1a --- /dev/null +++ b/README.md @@ -0,0 +1,89 @@ +Below is a sample **README.md** that explains how to install the necessary **MinGW** dependencies via **MSYS2**’s `pacman` and then build both the DLL and an EXE that depends on it. + +```md +# Snake Ported - SDL2 + OpenGL Test Game (UWP/Windows) + +This project builds a DLL (`snake_ported.dll`) that exposes `external_entry()` and `update_controller_input()` for use in a host application. It relies on **SDL2** and **OpenGL** under MinGW-w64 on Windows. + +## Prerequisites + +Install [MSYS2](https://www.msys2.org/) and update it: +``` + +```bash +pacman -Syu +``` + +Close the shell, reopen MSYS2 MinGW 64-bit shell, and update again if prompted: + +```bash +pacman -Syu +``` + +Then install the needed packages: + +```bash +pacman -S --needed base-devel \ + mingw-w64-x86_64-toolchain \ + mingw-w64-x86_64-SDL2 +``` + +These packages provide: +- **GCC/G++** (MinGW toolchain) +- **SDL2** headers and libraries for 64-bit Windows +- Basic build tools like `make` + +## Building the DLL + +Inside the **MinGW64** shell, run: + +```bash +g++ -shared snake_ported.cpp -o snake_ported.dll \ + -lmingw32 -lSDL2main -lSDL2 -lopengl32 -mwindows +``` + +This produces **`snake_ported.dll`** which exports: +- `external_entry()` to launch the Snake game loop using the host’s OpenGL context. +- `update_controller_input(...)` to feed controller/keyboard input into the game. + +## Building a Standalone EXE (Optional) + +If you also have a version of the same code (like the original Snake game) that creates its own window, you can build it as an EXE. For instance: + +```bash +g++ snake.cpp -o snake_exe \ + -lmingw32 -lSDL2main -lSDL2 -lopengl32 -mwindows +``` + + + +This will produce a standalone EXE (**`snake_exe`**) that creates an SDL window and runs the game. + +## Usage + +1. **DLL scenario**: Load `snake_ported.dll` from a host application (C#, Rust, C++, etc.). +2. **EXE scenario**: Simply run `snake_exe.exe`. + +In the DLL scenario, the host is responsible for: +- Creating an SDL window and OpenGL context. +- Calling `external_entry()` once everything is set up. +- Calling `update_controller_input(...)` with user/controller input data every frame/tick. + +## After compilation + +once compiled you should see what your DLL depends on. A good tool for this is [Dependencies](https://github.com/lucasg/Dependencies/releases/download/v1.11.1/Dependencies_x64_Release.zip). + +Since unlike traditional C++ devs i don't want to burden you and force you to basically decrypt what it needs i'll tell you what you need to grab from mingw: +- libstdc++-6.dll +- libwinpthread-1.dll +- libgcc_s_seh-1.dll + +!!! it might say SDL2.dll is not found that's okay since the host itself will provide a UWP compatible SDL build so you can ignore that. + +all these can be found in the following folder: + +``` +C:\msys64\mingw64\bin +``` + +A host compatible with the DLL can be found [here](https://git.nanodata.cloud/moonpower/sdl-cs-uwp). Simply replace the existing DLL by snake_ported.dll, insert the 3 mingw extra DLLS and see your game boot up!