{"id":29279346,"url":"https://github.com/krisfur/raylib-template","last_synced_at":"2026-04-29T21:05:55.896Z","repository":{"id":302319013,"uuid":"1009656411","full_name":"krisfur/raylib-template","owner":"krisfur","description":"Simple template for Raylib in C++ for making a 2D game with menus, controller support with SDL2, automatic scaling on resizing, windowed and fullscreen mode, and saving game states.","archived":false,"fork":false,"pushed_at":"2025-07-01T17:36:34.000Z","size":1433,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-01T18:34:09.279Z","etag":null,"topics":["cmake","cpp","cpp17","game-development","linux","macos","raylib","sdl2","template-project","windows"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krisfur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-27T13:43:55.000Z","updated_at":"2025-07-01T17:36:37.000Z","dependencies_parsed_at":"2025-07-01T18:48:55.121Z","dependency_job_id":null,"html_url":"https://github.com/krisfur/raylib-template","commit_stats":null,"previous_names":["krisfur/raylib-template"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/krisfur/raylib-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisfur%2Fraylib-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisfur%2Fraylib-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisfur%2Fraylib-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisfur%2Fraylib-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krisfur","download_url":"https://codeload.github.com/krisfur/raylib-template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisfur%2Fraylib-template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32443599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T20:22:27.477Z","status":"ssl_error","status_checked_at":"2026-04-29T20:22:26.507Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmake","cpp","cpp17","game-development","linux","macos","raylib","sdl2","template-project","windows"],"created_at":"2025-07-05T14:00:45.747Z","updated_at":"2026-04-29T21:05:55.890Z","avatar_url":"https://github.com/krisfur.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 2D Game Template with SDL2 Controller Support\n\n![C++](https://img.shields.io/badge/C++-00599C?style=flat\u0026logo=cplusplus\u0026logoColor=white) [![C++](https://img.shields.io/badge/C++-17-blueviolet)](https://isocpp.org/) ![Raylib](https://img.shields.io/badge/Raylib-5.5.0-green) ![SDL2](https://img.shields.io/badge/SDL2-2.32.56-orange) ![Platform](https://img.shields.io/badge/Platform-Linux%20%7C%20macOS%20%7C%20Windows-blue)\n\nA basic 2D game template built with raylib and SDL2 for reliable controller support. Features fullscreen scaling, a main menu, game states, and automatic save/load functionality.\n\n![screencast](screencast.gif)\n\n## Features\n\n- **Fullscreen Scaling**: Automatically scales UI and player movement to any resolution\n- **Game States**: Menu, Playing, Settings, and Paused states\n- **SDL2 Controller Support**: Reliable controller input using SDL2 (works with Xbox, DualSense, and other controllers)\n- **Save/Load System**: Automatically saves player position, fullscreen state, FPS, and input mode\n- **Cross-Platform**: Works on Linux, macOS, and Windows\n- **Smart Input Switching**: Seamlessly switches between mouse, keyboard, and controller input\n\n## Controller Support\n\nThe game uses SDL2 for controller input, which provides excellent compatibility with:\n- Xbox controllers (Xbox One, Xbox Series X/S)\n- PlayStation controllers (DualSense, DualShock)\n- Generic gamepads\n- And many other controllers\n\n### Controller Controls\n\n- **Left Stick**: Move player\n- **D-pad**: Navigate menus (one press at a time)\n- **A Button**: Select menu items\n- **B Button**: Go back / Resume game\n- **Start Button**: Pause/resume game\n- **Back Button**: Return to main menu from pause\n- **F1**: Toggle controller debug overlay\n\n## Building and Running\n\n### Prerequisites\n\n#### Linux (Arch Linux)\n```bash\nsudo pacman -S raylib sdl2 gcc cmake\n```\n\n#### Linux (Ubuntu/Debian)\n```bash\nsudo apt install libraylib-dev libsdl2-dev g++ cmake\n```\n\n#### macOS\n```bash\nbrew install raylib sdl2 gcc cmake pkg-config\n```\n\nIf you encounter errors about missing libraries when running the game, try:\n\n```bash\nexport DYLD_LIBRARY_PATH=/opt/homebrew/lib:$DYLD_LIBRARY_PATH\n./game\n```\n\nAll dependencies are installed via Homebrew. If you have issues with CMake not finding raylib or SDL2, ensure that pkg-config is installed and up to date.\n\n#### Windows\n1. Install [Visual Studio](https://visualstudio.microsoft.com/) or [MinGW](https://www.mingw-w64.org/)\n2. Install [raylib](https://www.raylib.com/) development libraries\n3. Install [SDL2](https://www.libsdl.org/) development libraries\n4. Install [CMake](https://cmake.org/)\n\n### Quick Start\n\n```bash\n# Clone the repository\ngit clone \u003crepository-url\u003e\ncd raylib-template\n\n# Build and run\n./run.sh\n```\n\n### Manual Build\n\n#### Using CMake (Recommended)\n```bash\nmkdir build\ncd build\ncmake ..\nmake\n./game\n```\n\n#### Direct Compilation (Linux/macOS)\n```bash\n# Linux\ng++ -o game main.cpp -lraylib -lSDL2 -lGL -lm -lpthread -ldl -lrt -lX11\n\n# macOS\ng++ -o game main.cpp -lraylib -lSDL2 -framework OpenGL -framework Cocoa -framework IOKit -framework CoreAudio -framework CoreVideo\n\n# Run the game\n./game\n```\n\n## Game Controls\n\n### Keyboard/Mouse\n- **WASD/Arrow Keys**: Move player\n- **ESC**: Pause game / Go back from settings to main menu\n- **Mouse**: Navigate menus\n- **F1**: Toggle debug overlay\n\n### Controller\n- **Left Stick**: Move player\n- **D-pad**: Navigate menus\n- **A Button**: Select\n- **B Button**: Go back / Resume game\n- **Start Button**: Pause/resume\n- **Back Button**: Return to main menu / Go back from settings to main menu\n\n## File Structure\n\n- `main.cpp` - Main game code with SDL2 controller support\n- `run.sh` - Build and run script (Linux/macOS)\n- `CMakeLists.txt` - Cross-platform CMake configuration\n- `game_save.dat` - Save file (created automatically)\n- `resources/` - Folder for all game assets (sounds, images, etc.)\n\n## Assets/Resources\n\n- All game assets (sounds, images, etc.) should be placed in the `resources` folder in the project root.\n- The build system (CMake) automatically copies the `resources` folder next to the game executable after each build.\n- When distributing or packaging your game, make sure to include the `resources` folder alongside your executable.\n\n## Technical Details\n\n### Input System\n- Uses **raylib** for graphics, window management, and keyboard/mouse input\n- Uses **SDL2** specifically for controller input\n- Automatic input mode switching based on detected input\n- Button press tracking prevents rapid-fire menu navigation\n- Smart menu highlighting that switches between mouse hover and keyboard/controller selection\n\n### Save System\n- Player position stored as relative coordinates (0.0-1.0)\n- Automatically recalculates position when window size changes\n- Saves fullscreen state, target FPS, and input mode\n- Save file located next to executable\n\n### Scaling System\n- UI elements scale with window size\n- Player movement speed adapts to screen dimensions\n- Consistent feel across different resolutions\n\n## Troubleshooting\n\n### Controller Not Detected\n1. Ensure SDL2 is installed: `pacman -Q sdl2` (Arch) or `dpkg -l | grep sdl2` (Ubuntu)\n2. Check controller permissions: `ls -la /dev/input/js*`\n3. Add user to input group: `sudo usermod -a -G input $USER`\n4. Reboot or log out/in\n\n### Build Issues\n- Ensure raylib and SDL2 development libraries are installed\n- On Linux, you may need additional packages: `sudo pacman -S mesa glu` (Arch) or `sudo apt install libgl1-mesa-dev` (Ubuntu)\n- Check that g++ supports C++17 or later\n- On Windows, ensure all dependencies are in your PATH\n\n### Performance Issues\n- The game targets 120 FPS by default\n- Adjust `targetFPS` in the code if needed\n- Fullscreen mode may provide better performance\n\n## Cross-Platform Compatibility\n\nThis template has been designed to work across all major platforms:\n\n- **Linux**: Tested on Arch Linux with X11\n- **macOS**: Compatible with macOS 10.14+ \n- **Windows**: Compatible with Windows 10/11\n\nThe CMake configuration automatically detects the platform and links the appropriate libraries.\n\n### Linux Display Server Compatibility\n\n#### X11 (Traditional)\n- ✅ **Fully supported** - All features work perfectly\n- ✅ **Controller support** - Reliable input detection\n- ✅ **Fullscreen mode** - Works as expected\n\n#### Wayland (Modern)\n- ⚠️ **Limited support** - May encounter issues\n- ⚠️ **Controller input** - Some controllers may not work properly\n- ⚠️ **Fullscreen behavior** - May behave differently\n\n**If you experience issues on Wayland:**\n\n1. **Force X11 mode** (recommended):\n   ```bash\n   GDK_BACKEND=x11 ./game\n   ```\n\n2. **Force SDL2 X11 driver**:\n   ```bash\n   SDL_VIDEODRIVER=x11 ./game\n   ```\n\n3. **Use XWayland** (if available):\n   ```bash\n   # Run your desktop environment with XWayland enabled\n   # Then run the game normally\n   ```\n\n**Why Wayland issues occur:**\n- raylib/GLFW has limited Wayland support\n- Controller input handling differs between X11 and Wayland\n- Fullscreen and window management work differently\n\n**Future improvements:**\n- The template includes Wayland detection and will show helpful messages\n- CMake configuration includes optional Wayland library linking\n- Environment variable handling for better compatibility\n\n## License\n\nThis template is provided as-is for educational and development purposes.\n\n### Missing Assets?\n\nIf you see errors about missing files (e.g., `resources/click.wav`), make sure the `resources` folder exists next to your executable.  \nCMake will copy it automatically when you build, but if you move the executable, copy the `resources` folder as well. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrisfur%2Fraylib-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrisfur%2Fraylib-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrisfur%2Fraylib-template/lists"}