diff options
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 224 |
1 files changed, 158 insertions, 66 deletions
@@ -1,90 +1,158 @@ -# libgraffik +# libgraffik - Cross-Platform Graphics Library A simple cross-platform graphics abstraction layer with support for multiple backends (SDL2, Win32, X11). -## Current Implementation +## Implemented Backends -Currently implemented backends: -- **SDL2** (Windows) - Fully implemented - -Planned backends: -- **Win32** (Windows native) - Placeholder -- **X11** (Linux) - Placeholder +- ✅ **SDL2** (Windows, Linux, macOS) - Fully implemented +- ✅ **Win32** (Windows native) - Fully implemented +- ✅ **X11** (Linux native) - Fully implemented ## Features - Window creation and management +- Double buffering for smooth rendering - Basic drawing primitives: - Lines - Rectangles (filled and outlined) - Circles (filled and outlined) - Pixels -- Color support with alpha channel -- Simple event handling +- Color support with alpha channel (SDL only) +- Simple event handling (ESC key, window close) - Cross-platform delay function -## Building +## Building on Windows + +### Option 1: Batch File (Easiest for Windows) + +```cmd +REM Build with SDL2 +build.bat sdl sample1 + +REM Build with Win32 +build.bat win32 sample1 + +REM Clean +build.bat clean + +REM Show help +build.bat help +``` + +### Option 2: PowerShell Script (Recommended for Windows) + +```powershell +# Build with SDL2 +.\build.ps1 -Backend sdl -Example sample1 -### Windows (with SDL2) +# Build with Win32 +.\build.ps1 -Backend win32 -Example sample2 -#### Prerequisites -1. **C++ compiler**: MinGW or MSVC -2. **SDL2 development libraries**: Download from [libsdl.org](https://www.libsdl.org/download-2.0.php) - - For MinGW: Download `SDL2-devel-2.x.x-mingw.tar.gz` - - For MSVC: Download `SDL2-devel-2.x.x-VC.zip` +# Build and run +.\build.ps1 -Backend sdl -Example sample1 -Run -#### Installing SDL2 +# Build all examples +.\build.ps1 -Backend sdl -All -1. **Download SDL2** development libraries for your compiler -2. **Extract** the archive -3. **Place SDL2** in one of these locations: - - `C:/SDL2` - - `D:/SDL2` - - Or in your project directory: `<project>/SDL2` +# Clean +.\build.ps1 -Clean -#### Option 1: Using Makefile (MinGW - Easiest) +# Show help +.\build.ps1 -Help +``` + +### Option 3: Makefile (MinGW Make) ```bash -# If SDL2 is in C:/SDL2 +# Show help make -# If SDL2 is elsewhere -make SDL2_PATH=D:/path/to/SDL2 +# Build specific example +make build BACKEND=sdl EXAMPLE=sample1 +make build BACKEND=win32 EXAMPLE=sample2 + +# Build all examples +make build-all BACKEND=sdl -# Run the demo -make run +# Build and run +make run BACKEND=sdl EXAMPLE=sample1 + +# Clean +make clean ``` -**Note**: Make sure `SDL2.dll` from `SDL2/bin` is in the same directory as the executable or in your PATH. +### Prerequisites for Windows + +1. **MinGW** with g++ compiler +2. **SDL2** (only for SDL backend): + - Download from [libsdl.org](https://www.libsdl.org/download-2.0.php) + - Get `SDL2-devel-2.x.x-mingw.tar.gz` + - Extract to `C:\SDL2` or set `SDL2_PATH` environment variable + +**Note**: Win32 backend has no external dependencies! -#### Option 2: Manual compilation with g++/MinGW +## Building on Linux + +### Using Makefile ```bash -# Adjust paths to match your SDL2 installation -g++ -std=c++11 -DUSE_SDL -o GraphicsDemo.exe main.cpp graphics.cpp ^ - -IC:/SDL2/include ^ - -LC:/SDL2/lib ^ - -lmingw32 -lSDL2main -lSDL2 -mwindows +# Build with SDL2 +make build BACKEND=sdl EXAMPLE=sample1 + +# Build with X11 (native Linux) +make build BACKEND=x11 EXAMPLE=sample1 -# Copy SDL2.dll to the same directory -copy C:\SDL2\bin\SDL2.dll . +# Build all examples +make build-all BACKEND=x11 + +# Clean +make clean ``` -#### Option 3: Manual compilation with MSVC +### Prerequisites for Linux +For SDL2 backend: ```bash -cl /EHsc /DUSE_SDL main.cpp graphics.cpp ^ - /I"C:\SDL2\include" ^ - /link "C:\SDL2\lib\x64\SDL2.lib" "C:\SDL2\lib\x64\SDL2main.lib" ^ - /SUBSYSTEM:CONSOLE +sudo apt-get install libsdl2-dev # Debian/Ubuntu +sudo dnf install SDL2-devel # Fedora +``` + +For X11 backend: +```bash +sudo apt-get install libx11-dev # Debian/Ubuntu +sudo dnf install libX11-devel # Fedora +``` -# Copy SDL2.dll -copy C:\SDL2\lib\x64\SDL2.dll . +## Manual Compilation + +### Windows with SDL2 +```cmd +g++ -std=c++11 -DUSE_SDL -o build\sample1.exe ^ + examples\sample1.cpp lib\graphics.cpp ^ + -IC:\SDL2\include ^ + -LC:\SDL2\lib ^ + -lmingw32 -lSDL2main -lSDL2 -mwindows +``` + +### Windows with Win32 +```cmd +g++ -std=c++11 -DUSE_WIN32 -o build\sample1.exe ^ + examples\sample1.cpp lib\graphics.cpp ^ + -lgdi32 -luser32 +``` + +### Linux with SDL2 +```bash +g++ -std=c++11 -DUSE_SDL -o build/sample1 \ + examples/sample1.cpp lib/graphics.cpp \ + $(sdl2-config --cflags --libs) ``` -### Linux (X11 - Not yet implemented) +### Linux with X11 ```bash -g++ -o demo main.cpp graphics.cpp -lX11 -DUSE_X11 +g++ -std=c++11 -DUSE_X11 -o build/sample1 \ + examples/sample1.cpp lib/graphics.cpp \ + -lX11 ``` ## Usage Example @@ -120,23 +188,6 @@ int main() { } ``` -## Architecture - -The library uses a simple abstraction pattern: - -1. **graphics.h** - Platform-independent API declarations -2. **graphics.cpp** - Platform-specific implementations (selected at compile time) -3. **Compile-time selection** - Backend is chosen via preprocessor defines - -### Adding a New Backend - -To add a new backend (e.g., Vulkan, DirectX): - -1. Add a new `#ifdef USE_BACKEND` section in `graphics.cpp` -2. Implement all functions declared in `graphics.h` -3. Update the platform detection logic in `graphics.h` if needed -4. Add compilation instructions to this README - ## API Reference ### Window Management @@ -167,6 +218,47 @@ struct Color { }; ``` +## Backend Comparison + +| Feature | SDL2 | Win32 | X11 | +|---------|------|-------|-----| +| Platform | Cross-platform | Windows only | Linux only | +| Dependencies | SDL2 library | None (native) | X11 library | +| Performance | Good | Excellent | Good | +| Complexity | Easy | Medium | Medium | +| Alpha blending | Yes | Limited | Limited | + +## Project Structure + +``` +libgraffik/ +├── lib/ +│ ├── graphics.h # Header file with API declarations +│ ├── graphics.cpp # Implementation for all backends +│ └── SDL2.dll # SDL2 DLL (Windows only) +├── examples/ +│ ├── sample1.cpp # Basic shapes demo +│ ├── sample2.cpp # Animation demo +│ └── sample3.cpp # Interactive demo +├── build/ # Output directory (created automatically) +├── Makefile # Unix-style Makefile +├── build.ps1 # PowerShell build script +├── build.bat # Batch build script +└── README.md # This file +``` + +## Native options + +- **Windows native**: Use `build.bat` for CMD or `build.ps1` for PowerShell. +- **Linux users**: Use the universal Makefile, also most recommended for all OSes. +- **Win32 backend**: Windows-native, uses CPU for rendering, may cause lack of performance, although may use less resources. +- **SDL2 backend**: Best for cross-platform development, works natively on both Linux and Windows, uses GPU for rendering. May be more resource heavy than these simplier backends like X11 or Win32. +- **X11 backend**: Native Linux performance, uses CPU for rendering. Will work for desktops using Xorg server. + ## License -MIT License. See [LICENSE](LICENSE) file.
\ No newline at end of file +MIT License. See [LICENSE](LICENSE) file for details. + +# Important notice + +AI had a hand in this. I try to review and improve everything it generates. |
